Skip to content

Commit

Permalink
[backend] Set default category if none is provided
Browse files Browse the repository at this point in the history
The default category is now set to the first category listed in the backend's
`CATEGORIES` list. This change is necessary to accommodate the removal of
backend-specific `fetch` methods, which previously handled category assignment.

Updated the tests to validate the default and specific category assignments,
and removed the obsolete `test_fetch_archive_needs_category`.

Signed-off-by: Venu Vardhan Reddy Tekula <[email protected]>
  • Loading branch information
vchrombie committed Sep 3, 2024
1 parent 13fc18c commit f9e99f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
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 <[email protected]>
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

0 comments on commit f9e99f1

Please sign in to comment.