about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpi coding agent <pi@localhost>2026-11-04 19:59:58 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-04 14:19:50 -0600
commitb9ab013e1b3cfedc5d241faedf13840b51ae0f8a (patch)
tree3d5861555dd1833e4e0260218dc9f12ac17f0445
parent539f8baf47c428884aeb68fb5fe34830d5bf5435 (diff)
downloadgn-uploader-b9ab013e1b3cfedc5d241faedf13840b51ae0f8a.tar.gz
Test: cover reading genotype collector jobs
Add tests for validating a collector job (type, completion, dataset
ownership) and parsing the FileStats from its recorded stdout.
-rw-r--r--tests/uploader/test_genotype_collector_job.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/uploader/test_genotype_collector_job.py b/tests/uploader/test_genotype_collector_job.py
new file mode 100644
index 0000000..52eeee9
--- /dev/null
+++ b/tests/uploader/test_genotype_collector_job.py
@@ -0,0 +1,98 @@
+"""Tests for reading genotype collector jobs."""
+import json
+
+import pytest
+
+from uploader.genotypes.collector_job import InvalidCollectorJob, file_stats
+
+STATS = {
+    "total_lines": 3,
+    "description": "a comment",
+    "geno_symbols": ["A", "T"],
+}
+
+
+def _job(
+        job_type="genotype-file-stats",
+        status="completed",
+        species_id=1,
+        population_id=2,
+        dataset_id=3,
+        stdout=None):
+    """Build a collector job dict for the tests."""
+    return {
+        "job_id": "fafc2d21-ed00-4a52-986e-3d0fe2250d5e",
+        "metadata": {
+            "job-type": job_type,
+            "status": status,
+            "species_id": species_id,
+            "population_id": population_id,
+            "dataset_id": dataset_id,
+        },
+        "stdout": json.dumps(STATS) if stdout is None else stdout,
+    }
+
+
+@pytest.mark.unit_test
+def test_file_stats_parses_a_valid_completed_job():
+    """
+    GIVEN: a completed genotype-stats job for the requested dataset
+    WHEN: its file statistics are read
+    THEN: the parsed statistics are returned
+    """
+    assert file_stats(_job(), 1, 2, 3) == STATS
+
+
+@pytest.mark.unit_test
+def test_file_stats_rejects_the_wrong_job_type():
+    """
+    GIVEN: a job of a different type
+    WHEN: its file statistics are read
+    THEN: InvalidCollectorJob is raised
+    """
+    with pytest.raises(InvalidCollectorJob):
+        file_stats(_job(job_type="something-else"), 1, 2, 3)
+
+
+@pytest.mark.unit_test
+def test_file_stats_rejects_incomplete_jobs():
+    """
+    GIVEN: a job that has not completed
+    WHEN: its file statistics are read
+    THEN: InvalidCollectorJob is raised
+    """
+    with pytest.raises(InvalidCollectorJob):
+        file_stats(_job(status="running"), 1, 2, 3)
+
+
+@pytest.mark.unit_test
+def test_file_stats_rejects_jobs_for_another_dataset():
+    """
+    GIVEN: a collector job for a different dataset
+    WHEN: its file statistics are read for the requested dataset
+    THEN: InvalidCollectorJob is raised
+    """
+    with pytest.raises(InvalidCollectorJob):
+        file_stats(_job(), 1, 2, 999)
+
+
+@pytest.mark.unit_test
+def test_file_stats_rejects_missing_output():
+    """
+    GIVEN: a job with no recorded output
+    WHEN: its file statistics are read
+    THEN: InvalidCollectorJob is raised
+    """
+    with pytest.raises(InvalidCollectorJob):
+        file_stats(_job(stdout=""), 1, 2, 3)
+
+
+@pytest.mark.unit_test
+def test_file_stats_rejects_invalid_output():
+    """
+    GIVEN: a job whose output is not valid JSON
+    WHEN: its file statistics are read
+    THEN: InvalidCollectorJob is raised
+    """
+    with pytest.raises(InvalidCollectorJob):
+        file_stats(_job(stdout="not-json"), 1, 2, 3)