Merge pull request 'fix(backup):force backup function to return same length ids as when getting snapshots' (#43) from fix-forget into master

Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/43
This commit is contained in:
houkime 2023-07-21 14:20:42 +03:00
commit e8c59f5068
2 changed files with 7 additions and 1 deletions

View file

@ -19,6 +19,8 @@ from selfprivacy_api.jobs import Jobs, JobStatus
from selfprivacy_api.backup.local_secret import LocalBackupSecret from selfprivacy_api.backup.local_secret import LocalBackupSecret
SHORT_ID_LEN = 8
class ResticBackupper(AbstractBackupper): class ResticBackupper(AbstractBackupper):
def __init__(self, login_flag: str, key_flag: str, storage_type: str) -> None: def __init__(self, login_flag: str, key_flag: str, storage_type: str) -> None:
@ -177,7 +179,9 @@ class ResticBackupper(AbstractBackupper):
@staticmethod @staticmethod
def _snapshot_from_fresh_summary(message: dict, repo_name) -> Snapshot: def _snapshot_from_fresh_summary(message: dict, repo_name) -> Snapshot:
return Snapshot( return Snapshot(
id=message["snapshot_id"], # There is a discrepancy between versions of restic/rclone
# Some report short_id in this field and some full
id=message["snapshot_id"][0:SHORT_ID_LEN],
created_at=datetime.datetime.now(datetime.timezone.utc), created_at=datetime.datetime.now(datetime.timezone.utc),
service_name=repo_name, service_name=repo_name,
) )

View file

@ -205,6 +205,8 @@ def test_backup_returns_snapshot(backups, dummy_service):
snapshot = provider.backupper.start_backup(service_folders, name) snapshot = provider.backupper.start_backup(service_folders, name)
assert snapshot.id is not None assert snapshot.id is not None
assert len(snapshot.id) == len(Backups.get_all_snapshots()[0].id)
assert Backups.get_snapshot_by_id(snapshot.id) is not None
assert snapshot.service_name == name assert snapshot.service_name == name
assert snapshot.created_at is not None assert snapshot.created_at is not None