diff --git a/selfprivacy_api/jobs/__init__.py b/selfprivacy_api/jobs/__init__.py index 4267819..1547b84 100644 --- a/selfprivacy_api/jobs/__init__.py +++ b/selfprivacy_api/jobs/__init__.py @@ -115,7 +115,9 @@ class Jobs: """ r = RedisPool().get_connection() key = _redis_key_from_uuid(job_uuid) - r.delete(key) + if (r.exists(key)): + r.delete(key) + return True return False @staticmethod diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 3474fc3..d0f506c 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -20,6 +20,15 @@ def test_minimal_update(jobs_with_one_job): assert jobs.get_jobs() == [test_job] +def test_remove_by_uid(jobs_with_one_job): + test_job = jobs_with_one_job.get_jobs()[0] + uid_str = str(test_job.uid) + + assert jobs_with_one_job.remove_by_uid(uid_str) + assert jobs_with_one_job.get_jobs() == [] + assert not jobs_with_one_job.remove_by_uid(uid_str) + + def test_remove_update_nonexistent(jobs_with_one_job): test_job = jobs_with_one_job.get_jobs()[0]