Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasmcnulty committed Jan 29, 2024
1 parent 4ac5e24 commit 7a1d641
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dbbackup/management/commands/dbbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ def handle(self, **options):
self.storage = get_storage()

self.database = options.get("database") or ""
database_keys = (
self.database.split(",") if self.database else settings.DATABASES
)

for database_key in database_keys:
for database_key in self._get_database_keys():
self.connector = get_connector(database_key)
if self.connector and self.exclude_tables:
self.connector.exclude.extend(
Expand All @@ -98,6 +95,9 @@ def handle(self, **options):
except StorageError as err:
raise CommandError(err) from err

def _get_database_keys(self):
return self.database.split(",") if self.database else settings.DATABASES

def _save_new_backup(self, database):
"""
Save a new backup file.
Expand Down
10 changes: 10 additions & 0 deletions dbbackup/tests/commands/test_dbbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_path(self):
# tearDown
os.remove(self.command.path)

@patch("dbbackup.settings.DATABASES", ["db-from-settings"])
def test_get_database_keys(self):
with self.subTest("use --database from CLI"):
self.command.database = "db-from-cli"
self.assertEqual(self.command._get_database_keys(), ["db-from-cli"])

with self.subTest("fallback to DBBACKUP_DATABASES"):
self.command.database = ""
self.assertEqual(self.command._get_database_keys(), ["db-from-settings"])


@patch("dbbackup.settings.GPG_RECIPIENT", "test@test")
@patch("sys.stdout", DEV_NULL)
Expand Down

0 comments on commit 7a1d641

Please sign in to comment.