Skip to content

Commit

Permalink
test(test_autoarchive_service): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
maugde committed Oct 7, 2024
1 parent 3cc07eb commit 6465c41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
9 changes: 4 additions & 5 deletions antarest/study/storage/auto_archive_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def _try_archive_studies(self) -> None:
study_ids_to_archive = [
(study.id, isinstance(study, RawStudy))
for study in studies
if ((study.last_access or study.updated_at) < old_date)
and isinstance(study, VariantStudy)
or not study.archived
if (study.last_access or study.updated_at) < old_date
and (isinstance(study, VariantStudy) or not study.archived)
]
for study_id, is_raw_study in study_ids_to_archive[0 : self.max_parallel]:
try:
Expand Down Expand Up @@ -87,10 +86,10 @@ def _try_archive_studies(self) -> None:

def _try_clear_snapshot(self) -> None:
# convert days in hours
hours_of_lifespan = hours=self.config.storage.variant_snapshot_lifespan_days * 24
hours_of_lifespan = self.config.storage.variant_snapshot_lifespan_days * 24

self.study_service.storage_service.variant_study_service.clear_all_snapshots(
hours_of_lifespan
datetime.timedelta(hours=hours_of_lifespan)
)

def _loop(self) -> None:
Expand Down
19 changes: 4 additions & 15 deletions tests/storage/business/test_autoarchive_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,6 @@ def test_auto_archival(tmp_path: Path):
id="e",
updated_at=now - datetime.timedelta(days=61),
),
VariantStudy(
id="f",
updated_at=now - datetime.timedelta(days=0),
),
VariantStudy(
id="g",
updated_at=now - datetime.timedelta(days=1),
),
VariantStudy(
id="h",
last_access=now - datetime.timedelta(days=2)
)
]
)
db_session.commit()
Expand Down Expand Up @@ -109,7 +97,8 @@ def test_auto_archival(tmp_path: Path):
# Check that the variant outputs are deleted for the variant study "e"
study_service.archive_outputs.assert_called_once_with("e", params=RequestParameters(DEFAULT_ADMIN_USER))

# Test auto snapshot clearing
# Check if the `clear_all_snapshots` method was called with default values
auto_archive_service._try_clear_snapshot()

# Check if variant snapshots with date older than variant_snapshot_lifespan_days argument are cleared
study_service.storage_service.variant_study_service.clear_all_snapshots.assert_called_once_with(
datetime.timedelta(hours=24),
)

0 comments on commit 6465c41

Please sign in to comment.