Skip to content

Commit 529c9ab

Browse files
committed
[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 <vt2182@nyu.edu>
1 parent 13fc18c commit 529c9ab

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

AUTHORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Valerio Cosentino <valcos@bitergia.com>
77
Jose Javier Merchante <jjmerchante@bitergia.com>
88
Chris Burgess <chris.burgess@catalyst.net.nz>
99
devpod.cn <support@devpod.cn>
10-
Venu Vardhan Reddy Tekula <venu@chaoss.community>
10+
Venu Vardhan Reddy Tekula <vt2182@nyu.edu>
1111
Matt Gaughan <mgaughan@proton.me>
1212

perceval/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,9 @@ def parse(self, *args):
688688
"""
689689
parsed_args = self.parser.parse_args(args)
690690

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

695695
if self._from_date:
696696
parsed_args.from_date = str_to_datetime(parsed_args.from_date)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Refactor Backend Fetch Logic
3+
category: other
4+
author: Venu Vardhan Reddy Tekula <vt2182@nyu.edu>
5+
issue: 527
6+
notes: >
7+
Refactored the `Backend` class to simplify and improve maintainability.
8+
The `fetch` method is no longer overridden in subclasses. Instead,
9+
subclasses are only required to implement the `fetch_items` method, where
10+
the specific data retrieval logic is defined. This change ensures that any
11+
updates to the `fetch` method in the `Backend` class are automatically
12+
inherited by all subclasses, reducing the need to propagate changes across
13+
multiple classes.

tests/test_backend.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,26 +1093,19 @@ def test_incompatible_fetch_archive_and_no_archive(self):
10931093
with self.assertRaises(AttributeError):
10941094
_ = parser.parse(*args)
10951095

1096-
def test_fetch_archive_needs_category(self):
1097-
"""Test if fetch-archive needs a category"""
1098-
1099-
args = ['--fetch-archive']
1100-
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
1101-
archive=True)
1102-
1103-
with self.assertRaises(AttributeError):
1104-
_ = parser.parse(*args)
1105-
1106-
def test_remove_empty_category(self):
1107-
"""Test whether category argument is removed when no value is given"""
1096+
def test_default_category(self):
1097+
"""Test whether a default category is set if none is provided"""
11081098

1099+
# No category is provided
11091100
args = []
11101101
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
11111102
archive=True)
11121103
parsed_args = parser.parse(*args)
11131104

1114-
with self.assertRaises(AttributeError):
1115-
_ = parsed_args.category
1105+
self.assertEqual(parsed_args.category, MockedBackendCommand.BACKEND.DEFAULT_CATEGORY)
1106+
1107+
def test_specific_category(self):
1108+
"""Test whether a specific category is set when provided"""
11161109

11171110
# An empty string is parsed
11181111
args = ['--category', '']

0 commit comments

Comments
 (0)