mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
test(backups): test that the job has run
This commit is contained in:
parent
2a87eb80f9
commit
ebff2b308a
|
@ -133,9 +133,26 @@ class Jobs:
|
|||
key = _redis_log_key_from_uuid(job.uid)
|
||||
if redis.exists(key):
|
||||
assert redis.type(key) == "list"
|
||||
redis.lpush(key, str(status))
|
||||
redis.lpush(key, status.value)
|
||||
redis.expire(key, 10)
|
||||
|
||||
@staticmethod
|
||||
def status_updates(job: Job) -> typing.List[JobStatus]:
|
||||
result = []
|
||||
|
||||
redis = RedisPool().get_connection()
|
||||
key = _redis_log_key_from_uuid(job.uid)
|
||||
if not redis.exists(key):
|
||||
return []
|
||||
|
||||
status_strings = redis.lrange(key, 0, -1)
|
||||
for status in status_strings:
|
||||
try:
|
||||
result.append(JobStatus[status])
|
||||
except KeyError as e:
|
||||
raise ValueError("impossible job status: " + status) from e
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def update(
|
||||
job: Job,
|
||||
|
|
|
@ -227,6 +227,12 @@ def assert_job_finished(job_type, count):
|
|||
assert finished_types.count(job_type) == count
|
||||
|
||||
|
||||
def assert_job_has_run(job_type):
|
||||
finished_jobs = [job for job in Jobs.get_jobs() if job.status is JobStatus.FINISHED]
|
||||
job = [job for job in finished_jobs if job.type_id == job_type][0]
|
||||
assert JobStatus.RUNNING in Jobs.status_updates(job)
|
||||
|
||||
|
||||
def test_backup_service_task(backups, dummy_service):
|
||||
handle = start_backup(dummy_service)
|
||||
handle(blocking=True)
|
||||
|
@ -235,7 +241,9 @@ def test_backup_service_task(backups, dummy_service):
|
|||
assert len(snaps) == 1
|
||||
|
||||
id = dummy_service.get_id()
|
||||
assert_job_finished(f"services.{id}.backup", count=1)
|
||||
job_type_id = f"services.{id}.backup"
|
||||
assert_job_finished(job_type_id, count=1)
|
||||
assert_job_has_run(job_type_id)
|
||||
|
||||
|
||||
def test_restore_snapshot_task(backups, dummy_service):
|
||||
|
|
Loading…
Reference in a new issue