From f9e99f1f4e00d675144324ce19005a53e6517f2e Mon Sep 17 00:00:00 2001 From: Venu Vardhan Reddy Tekula Date: Tue, 3 Sep 2024 14:11:03 -0400 Subject: [PATCH] [backend] Set default category if none is provided 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 --- perceval/backend.py | 4 ++-- .../refactor-backend-fetch-logic.yml | 13 ++++++++++++ tests/test_backend.py | 21 +++++++------------ 3 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 releases/unreleased/refactor-backend-fetch-logic.yml diff --git a/perceval/backend.py b/perceval/backend.py index 47db68543..6fa89ee3d 100644 --- a/perceval/backend.py +++ b/perceval/backend.py @@ -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) diff --git a/releases/unreleased/refactor-backend-fetch-logic.yml b/releases/unreleased/refactor-backend-fetch-logic.yml new file mode 100644 index 000000000..3b97e0398 --- /dev/null +++ b/releases/unreleased/refactor-backend-fetch-logic.yml @@ -0,0 +1,13 @@ +--- +title: Refactor Backend Fetch Logic +category: other +author: Venu Vardhan Reddy Tekula +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. diff --git a/tests/test_backend.py b/tests/test_backend.py index 01803789b..ad5068c73 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -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', '']