diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-11-11 19:04:07 +0000 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-11-11 14:06:44 -0600 |
| commit | 98f2e739ef4724bdd3043fad8277c4444986326b (patch) | |
| tree | 03717920a3f17d010846971cadbbbde4e0e235ba /tests | |
| parent | 9a30e5112f252d7aa5a09fd718733a35c7869b4e (diff) | |
| download | gn-libs-main.tar.gz | |
Change `initialise_job` to accept metadata as keyword arguments, with
`expiry_seconds` as a keyword-only reserved argument. Document the
`external_id` value, and the `workflow_claim` metadata convention for
idempotent stage transitions.
Call sites that pass `extra_meta={...}` must unpack the dict instead.
Co-authored-by: pi coding agent <pi@pi.dev>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_jobs.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/unit/test_jobs.py b/tests/unit/test_jobs.py index f513764..a026870 100644 --- a/tests/unit/test_jobs.py +++ b/tests/unit/test_jobs.py @@ -20,7 +20,7 @@ def jobsdb(tmp_path): def _job(conn, job_type, **metadata): """Create a job with the given type and metadata.""" return jobs.initialise_job( - conn, str(uuid.uuid4()), ["true"], job_type, extra_meta=metadata) + conn, str(uuid.uuid4()), ["true"], job_type, **metadata) @pytest.mark.unit_test @@ -82,3 +82,23 @@ def test_jobs_by_metadata_returns_empty_when_no_match(jobsdb): _job(conn, "qc", genotype_collector_job_id="c1") assert jobs.jobs_by_metadata( conn, {"genotype_collector_job_id": "nope"}) == () + + +@pytest.mark.unit_test +def test_initialise_job_treats_metadata_kwargs_as_metadata(jobsdb): + """ + GIVEN: metadata and reserved operational arguments + WHEN: a job is initialised + THEN: the metadata is stored, while expiry_seconds is not metadata + """ + with sqlite3.connection(str(jobsdb)) as conn: + job = jobs.initialise_job( + conn, str(uuid.uuid4()), ["true"], "qc", + genotype_collector_job_id="c1", + external_id="user-1", expiry_seconds=60) + stored = jobs.job(conn, job["job_id"]) + assert stored["metadata"]["genotype_collector_job_id"] == "c1" + assert stored["metadata"]["external_id"] == "user-1" + assert "expiry_seconds" not in stored["metadata"] + assert jobs.jobs_by_external_id(conn, "user-1")[0]["job_id"] == ( + job["job_id"]) |
