Skip to content

Commit ea9b7d9

Browse files
sdelliotmitchnegus
andauthored
fix: Ensuring users know when a duplicate repository is trying to be added (#81)
This PR further enhances #65 by ensuring the user gets feedback on if duplicate repositories are installed. Additionally, it performs more test clean up. --------- Signed-off-by: Steven Elliott <[email protected]> Co-authored-by: Mitch Negus <[email protected]>
1 parent b8d1b3f commit ea9b7d9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/firewheel/cli/helpers/repository/install

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ def install_repo(repo):
9393
repo (dict): A dictionary object which can be added as a new FIREWHEEL repository.
9494
"""
9595
repo_db = RepositoryDb()
96-
repo_db.add_repository(repo)
97-
Console().print("[green]Repository successfully installed!")
96+
ret = repo_db.add_repository(repo)
97+
if ret:
98+
Console().print("[green]Repository successfully installed!")
99+
else:
100+
Console().print("[yellow]Duplicate repositories cannot be installed!")
98101

99102

100103
def run_install_script(repo, insecure):

src/firewheel/control/repository_db.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def add_repository(self, repository):
7878
7979
Args:
8080
repository (dict): A repository dictionary to add. See format for the database.
81+
82+
Returns:
83+
int: Number of entries added, 0 for duplicate repository or 1 for a single repository.
8184
"""
8285
self._validate_repository(repository)
8386

@@ -95,13 +98,14 @@ def add_repository(self, repository):
9598

9699
if any(entry["path"] == repository["path"] for entry in entries):
97100
self.log.debug("Ignoring duplicate repository: %s", repository)
98-
return
101+
return 0
99102

100103
entries.append(repository)
101104
with self.db_file.open("w") as db:
102105
json.dump(entries, db)
103106

104107
self.log.debug("Added repository: %s", repository)
108+
return 1
105109

106110
def delete_repository(self, repository):
107111
"""

src/firewheel/tests/unit/control/test_repository_db.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def repository_db():
4141
db_filename="test_repositories.json",
4242
)
4343
yield repository_db
44+
# Ensure all repositories are removed during teardown
45+
for repo in repository_db.list_repositories():
46+
repository_db.delete_repository(repo)
4447

4548

4649
@pytest.fixture
@@ -92,7 +95,7 @@ def test_corrupt_repository_add(self, repository_db_test_path, repo_entry):
9295
assert location.exists() is False
9396

9497
def test_add_repository(self, repository_db, repo_entry):
95-
repository_db.add_repository(repo_entry)
98+
assert repository_db.add_repository(repo_entry) == 1
9699
repo_list = list(repository_db.list_repositories())
97100
assert self._entry_in_repo_list(repo_entry, repo_list)
98101

@@ -120,8 +123,8 @@ def test_add_repository_invalid(
120123

121124
def test_duplicate_repository(self, repository_db, repo_entry):
122125
orig_entry_count = len(list(repository_db.list_repositories()))
123-
repository_db.add_repository(repo_entry)
124-
repository_db.add_repository(repo_entry)
126+
assert repository_db.add_repository(repo_entry) == 1
127+
assert repository_db.add_repository(repo_entry) == 0
125128
repo_list = list(repository_db.list_repositories())
126129
assert self._entry_in_repo_list(repo_entry, repo_list)
127130
# The entry should only be added once

0 commit comments

Comments
 (0)