From bade1fd7222e6aeab7f9f90ff1bf0be24643d0e2 Mon Sep 17 00:00:00 2001 From: Jon Massey Date: Wed, 17 Jul 2024 18:40:10 +0100 Subject: [PATCH] Test all Django Job Scheduling Jobs are monitored Check that all jobs in jobserver.jobs have their `execute` methods annotated correctly (e.g. `@monitor` but not `@monitor()`) --- tests/unit/jobserver/jobs/__init__.py | 0 tests/unit/jobserver/jobs/test_jobs.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/unit/jobserver/jobs/__init__.py create mode 100644 tests/unit/jobserver/jobs/test_jobs.py diff --git a/tests/unit/jobserver/jobs/__init__.py b/tests/unit/jobserver/jobs/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/jobserver/jobs/test_jobs.py b/tests/unit/jobserver/jobs/test_jobs.py new file mode 100644 index 0000000000..8b2889ced3 --- /dev/null +++ b/tests/unit/jobserver/jobs/test_jobs.py @@ -0,0 +1,20 @@ +import pkgutil + +import jobserver.jobs + + +def test_jobs_annotated(): + for moduleinfo in pkgutil.walk_packages(jobserver.jobs.__path__, "jobserver.jobs."): + if len(moduleinfo.name.split(".")) <= 3: + continue + + module = pkgutil.resolve_name(moduleinfo.name) + job = module.Job + execute = job.execute + + # check the monitor decorator is imported + assert "monitor" in module.__dict__ + # check the execute function has been decorated by something using functools.wraps + assert "__wrapped__" in execute.__dict__ + # check the thing that decorated it came from services.sentry + assert execute.__globals__["__name__"] == "services.sentry"