Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fetch() and fetch_items() in the backends #848

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Valerio Cosentino <valcos@bitergia.com>
Jose Javier Merchante <jjmerchante@bitergia.com>
Chris Burgess <chris.burgess@catalyst.net.nz>
devpod.cn <support@devpod.cn>
Venu Vardhan Reddy Tekula <venu@chaoss.community>
Venu Vardhan Reddy Tekula <vt2182@nyu.edu>
Matt Gaughan <mgaughan@proton.me>

4 changes: 2 additions & 2 deletions perceval/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ def parse(self, *args):
"""
parsed_args = self.parser.parse_args(args)

# Category was not set, remove it
# Ensure category is set
if parsed_args.category is None:
delattr(parsed_args, 'category')
parsed_args.category = self._backend.CATEGORIES[0]

if self._from_date:
parsed_args.from_date = str_to_datetime(parsed_args.from_date)
Expand Down
13 changes: 13 additions & 0 deletions releases/unreleased/refactor-backend-fetch-logic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Refactor Backend Fetch Logic
category: other
author: Venu Vardhan Reddy Tekula <vt2182@nyu.edu>
issue: 527
notes: >
Refactored the `Backend` class to simplify and improve maintainability.
The `fetch` method is no longer overridden in subclasses. Instead,
subclasses are only required to implement the `fetch_items` method, where
the specific data retrieval logic is defined. This change ensures that any
updates to the `fetch` method in the `Backend` class are automatically
inherited by all subclasses, reducing the need to propagate changes across
multiple classes.
21 changes: 7 additions & 14 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,26 +1093,19 @@ def test_incompatible_fetch_archive_and_no_archive(self):
with self.assertRaises(AttributeError):
_ = parser.parse(*args)

def test_fetch_archive_needs_category(self):
"""Test if fetch-archive needs a category"""

args = ['--fetch-archive']
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
archive=True)

with self.assertRaises(AttributeError):
_ = parser.parse(*args)

def test_remove_empty_category(self):
"""Test whether category argument is removed when no value is given"""
def test_default_category(self):
"""Test whether a default category is set if none is provided"""

# No category is provided
args = []
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
archive=True)
parsed_args = parser.parse(*args)

with self.assertRaises(AttributeError):
_ = parsed_args.category
self.assertEqual(parsed_args.category, MockedBackendCommand.BACKEND.DEFAULT_CATEGORY)

def test_specific_category(self):
"""Test whether a specific category is set when provided"""

# An empty string is parsed
args = ['--category', '']
Expand Down