From 69f63f04eb4af3b706e3705c1565bb9b3c8f287a Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 14 Apr 2023 10:32:14 +0000 Subject: [PATCH] refactor(backups): make a dedicated get_folders() function --- selfprivacy_api/backup/__init__.py | 4 ++-- selfprivacy_api/services/service.py | 5 +++++ selfprivacy_api/services/test_service/__init__.py | 7 ++++++- tests/test_graphql/test_backup.py | 6 +++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index 72d6168..708d4a5 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -194,7 +194,7 @@ class Backups: @staticmethod def back_up(service: Service): """The top-level function to back up a service""" - folder = service.get_drive() + folder = service.get_folders() repo_name = service.get_id() service.pre_backup() @@ -238,7 +238,7 @@ class Backups: @staticmethod def restore_service_from_snapshot(service: Service, snapshot_id: str): repo_name = service.get_id() - folder = service.get_drive() + folder = service.get_folders() Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder) diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index 3f1f4af..9a7663a 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -135,6 +135,11 @@ class Service(ABC): def get_drive() -> str: pass + # @staticmethod + # @abstractmethod + # def get_folders() -> str: + # pass + @abstractmethod def move_to_volume(self, volume: BlockDevice) -> Job: pass diff --git a/selfprivacy_api/services/test_service/__init__.py b/selfprivacy_api/services/test_service/__init__.py index 822348c..2906244 100644 --- a/selfprivacy_api/services/test_service/__init__.py +++ b/selfprivacy_api/services/test_service/__init__.py @@ -106,8 +106,13 @@ class DummyService(Service): storage_usage = 0 return storage_usage - @classmethod + @staticmethod def get_drive(cls) -> str: + return "sda1" + + @classmethod + def get_folders(cls) -> str: + # for now only a single folder return cls.location @staticmethod diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index d33cde1..9c8af3f 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -44,7 +44,7 @@ def raw_dummy_service(tmpdir, backups): with open(testfile_path, "w") as file: file.write(TESTFILE_BODY) - # we need this to not change get_drive() much + # we need this to not change get_folders() much class TestDummyService(DummyService, location=service_dir): pass @@ -143,7 +143,7 @@ def test_one_snapshot(backups, dummy_service): def test_backup_returns_snapshot(backups, dummy_service): - service_folder = dummy_service.get_drive() + service_folder = dummy_service.get_folders() provider = Backups.provider() name = dummy_service.get_id() snapshot = provider.backuper.start_backup(service_folder, name) @@ -154,7 +154,7 @@ def test_backup_returns_snapshot(backups, dummy_service): def test_restore(backups, dummy_service): - service_folder = dummy_service.get_drive() + service_folder = dummy_service.get_folders() file_to_nuke = listdir(service_folder)[0] assert file_to_nuke is not None path_to_nuke = path.join(service_folder, file_to_nuke)