From 063dfafc196ad094765fe70f4a9ee34affa68026 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 30 Nov 2022 17:06:43 +0000 Subject: [PATCH] Jobs: fix return value of remove_by_uid And add a test for said return value. --- selfprivacy_api/jobs/__init__.py | 4 +++- tests/test_jobs.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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]