about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/uploader/test_genotype_collector_config.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/uploader/test_genotype_collector_config.py b/tests/uploader/test_genotype_collector_config.py
new file mode 100644
index 0000000..d0ab99e
--- /dev/null
+++ b/tests/uploader/test_genotype_collector_config.py
@@ -0,0 +1,79 @@
+"""Tests for building the genotype collector config from the upload form."""
+import pytest
+
+from uploader.genotypes.collector_config import from_form
+
+
+@pytest.mark.unit_test
+def test_from_form_maps_every_upload_field():
+    """
+    GIVEN: a fully specified upload form
+    WHEN: the collector config is built
+    THEN: each form field is mapped to the collector's config key
+    """
+    form = {
+        "markers_field": "Marker",
+        "chromosomes_field": "Chrom",
+        "centimorgans_field": "Centimorgan",
+        "megabases_field": "Megabase",
+        "file-separator": "\t",
+        "file-comment-char": ";",
+        "file-na": "- NA",
+        "transposed": "on",
+    }
+    assert from_form(form) == {
+        "markers": "Marker",
+        "chromosome": "Chrom",
+        "cm": "Centimorgan",
+        "mb": "Megabase",
+        "separator": "\t",
+        "comment.char": ";",
+        "na_strings": ["-", "NA"],
+        "transposed": True,
+    }
+
+
+@pytest.mark.unit_test
+def test_from_form_uses_collector_defaults_for_missing_fields():
+    """
+    GIVEN: an upload form without the metadata fields
+    WHEN: the collector config is built
+    THEN: the collector's own defaults are used
+    """
+    assert from_form({}) == {
+        "markers": "Locus",
+        "chromosome": "Chr",
+        "cm": "cM",
+        "mb": "Mb",
+        "separator": ",",
+        "comment.char": "#",
+        "na_strings": ["-", "NA", "N/A"],
+        "transposed": False,
+    }
+
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+    "form,expected",
+    (({"transposed": "on"}, True),
+     ({"transposed": ""}, False),
+     ({"transposed": "off"}, False),
+     ({}, False)))
+def test_from_form_parses_the_transposed_checkbox(form, expected):
+    """
+    GIVEN: an upload form with various transposed checkbox values
+    WHEN: the collector config is built
+    THEN: the transposed flag is True only when the checkbox is checked
+    """
+    assert from_form(form)["transposed"] is expected
+
+
+@pytest.mark.unit_test
+def test_from_form_normalises_na_string_whitespace():
+    """
+    GIVEN: a space- and tab-separated list of missing-value strings
+    WHEN: the collector config is built
+    THEN: the list is split into non-empty strings
+    """
+    assert from_form({"file-na": "  -   NA\tN/A  "})["na_strings"] == [
+        "-", "NA", "N/A"]