From 37b747f87f23f35efa3c67610faad7a8aa22e285 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 13 Feb 2023 11:16:35 +0000 Subject: [PATCH] test(backup): no snapshots --- selfprivacy_api/backup/backuper.py | 8 ++++++++ selfprivacy_api/backup/restic_backuper.py | 8 ++++++-- selfprivacy_api/models/backup/snapshot.py | 2 ++ tests/test_graphql/test_backup.py | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/backup/backuper.py b/selfprivacy_api/backup/backuper.py index f428145..c2353ad 100644 --- a/selfprivacy_api/backup/backuper.py +++ b/selfprivacy_api/backup/backuper.py @@ -1,4 +1,7 @@ from abc import ABC, abstractmethod +from typing import List + +from selfprivacy_api.models.backup.snapshot import Snapshot class AbstractBackuper(ABC): @@ -8,3 +11,8 @@ class AbstractBackuper(ABC): @abstractmethod def start_backup(self, folder: str, repo_name: str): raise NotImplementedError + + @abstractmethod + def get_snapshots(self, repo_name) -> List[Snapshot]: + """Get all snapshots from the repo""" + raise NotImplementedError diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index fdecf1b..2c120f1 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -1,7 +1,10 @@ import subprocess import json +from typing import List + from selfprivacy_api.backup.backuper import AbstractBackuper +from selfprivacy_api.models.backup.snapshot import Snapshot class ResticBackuper(AbstractBackuper): @@ -107,10 +110,11 @@ class ResticBackuper(AbstractBackuper): self.error_message = output return [] - def get_snapshots(self): + def get_snapshots(self, repo_name) -> List[Snapshot]: + """Get all snapshots from the repo""" # No transformation for now snapshots = [] - for snapshot in self._load_snapshots(): + for snapshot in self._load_snapshots(repo_name): snapshots.append(snapshot) return snapshots diff --git a/selfprivacy_api/models/backup/snapshot.py b/selfprivacy_api/models/backup/snapshot.py index b9c9e6e..9893f03 100644 --- a/selfprivacy_api/models/backup/snapshot.py +++ b/selfprivacy_api/models/backup/snapshot.py @@ -1,5 +1,7 @@ +import datetime from pydantic import BaseModel + class Snapshot(BaseModel): id: str service_name: str diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 64efe05..ee8ee0e 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -57,3 +57,7 @@ def test_backup_simple(test_service, memory_backup): def test_backup_service(test_service, backups): backups.back_up(test_service) + + +def test_no_snapshots(memory_backup): + assert memory_backup.backuper.get_snapshots("") == []