From a35859a45c9eebc567e3dbfb8b8b296ae9aa9c72 Mon Sep 17 00:00:00 2001 From: mayabrandi Date: Mon, 16 Nov 2020 09:02:04 +0100 Subject: [PATCH] tests fixed --- tests/build/test_build_batch.py | 74 ------------------------ tests/build/test_build_document.py | 31 ++++++++++ tests/build/test_build_sample.py | 91 ------------------------------ 3 files changed, 31 insertions(+), 165 deletions(-) delete mode 100644 tests/build/test_build_batch.py create mode 100644 tests/build/test_build_document.py delete mode 100644 tests/build/test_build_sample.py diff --git a/tests/build/test_build_batch.py b/tests/build/test_build_batch.py deleted file mode 100644 index 3ac41a06..00000000 --- a/tests/build/test_build_batch.py +++ /dev/null @@ -1,74 +0,0 @@ -from NIPTool.build.document import build_batch -from NIPTool.models.constants import BATCH_KEYS -import pytest - - -def test_build_batch(): - # GIVEN a batch_data with requiered key 'SampleProject' - batch_data = { - "Median_18": 1.01950547134618, - "SampleProject": 201862, - "Stdev_13": 0.009517510060085, - } - - # WHEN building a mongo batch - mongo_batch = build_batch(batch_data=batch_data) - - # THEN the mongo_batch has a key "_id" with the value of "SampleProject" - assert mongo_batch == { - "_id": "201862", - "Median_18": 1.01950547134618, - "Stdev_13": 0.009517510060085, - } - - -def test_build_batch_wrong_keys(): - # GIVEN a batch_data with not accepted keys: key1 key2 key3 - batch_data = { - "SampleProject": 201862, - "key1": " ", - "key2": 201862, - "key3": -10.1836097044367, - } - - # WHEN building a mongo batch - mongo_batch = build_batch(batch_data=batch_data) - - # THEN the unaccepted keys will not be part of the mongo_batch" - assert mongo_batch == {"_id": "201862"} - - -@pytest.mark.parametrize("batch_key", BATCH_KEYS) -def test_build_batch_str_values(batch_key): - # GIVEN a batch_data dict with requiered key 'SampleProject' and a batch_key with some str value - batch_data = {"SampleProject": 201862, batch_key: "Value"} - - # WHEN building a mongo batch - mongo_batch = build_batch(batch_data=batch_data) - - # THEN the the batch_key will be loaded into the mongo_batch dict - assert mongo_batch == {"_id": "201862", batch_key: "Value"} - - -@pytest.mark.parametrize("batch_key", BATCH_KEYS) -def test_build_batch_zero_values(batch_key): - # GIVEN a batch_data dict with requiered key 'SampleProject' and a batch_key with value 0 - batch_data = {"SampleProject": 201862, batch_key: 0} - - # WHEN building a mongo batch - mongo_batch = build_batch(batch_data=batch_data) - - # THEN the the batch_key will be loaded into the mongo_batch dict - assert mongo_batch == {"_id": "201862", batch_key: 0} - - -@pytest.mark.parametrize("batch_key", BATCH_KEYS) -def test_build_batch_empty_strings(batch_key): - # GIVEN a batch_data dict with requiered key 'SampleProject' and a batch_key with empty string as value - batch_data = {"SampleProject": 201862, batch_key: " "} - - # WHEN building a mongo batch - mongo_batch = build_batch(batch_data=batch_data) - - # THEN the the batch_key will not be loaded into the mongo_batch dict - assert mongo_batch == {"_id": "201862"} \ No newline at end of file diff --git a/tests/build/test_build_document.py b/tests/build/test_build_document.py new file mode 100644 index 00000000..b8d0d17d --- /dev/null +++ b/tests/build/test_build_document.py @@ -0,0 +1,31 @@ +from NIPTool.build.document import build_batch, build_sample +from NIPTool.models.constants import BATCH_KEYS, SAMPLE_KEYS +import pytest + + +@pytest.mark.parametrize("sample_key", SAMPLE_KEYS) +@pytest.mark.parametrize("value", [124, 2.08, "randomstring"]) +def test_build_sample(sample_key, value): + # GIVEN a sample_data dict with requiered key 'SampleID' and a sample_key with some value and a non sample_key + + sample_data = {"SampleID": "someid", sample_key: value, "other_key": 8983} + + # WHEN building a mongo sample + mongo_sample = build_sample(sample_data=sample_data) + + # THEN the SampleID will be _id and the non sample key will be removed + assert mongo_sample == {"_id": "someid", sample_key: value} + + +@pytest.mark.parametrize("batch_key", BATCH_KEYS) +@pytest.mark.parametrize("value", [124, 2.08, "randomstring"]) +def test_build_batch(batch_key, value): + # GIVEN a batch_data dict a batch_key with some value and a non batch_key + + batch_data = {batch_key: value, "other_key": 8983} + + # WHEN building a mongo batch + mongo_batch = build_batch(batch_data=batch_data) + + # THEN the non batch_key will be removed + assert mongo_batch == {batch_key: value} \ No newline at end of file diff --git a/tests/build/test_build_sample.py b/tests/build/test_build_sample.py deleted file mode 100644 index 4eda2bc0..00000000 --- a/tests/build/test_build_sample.py +++ /dev/null @@ -1,91 +0,0 @@ -from NIPTool.build.document import build_sample -from NIPTool.models.constants import SAMPLE_KEYS -import pytest - - -def test_build_sample(): - # GIVEN a sample_data with requiered key 'SampleID' - sample_data = { - "SampleID": "2020-07452-02", - "Description": " ", - "Zscore_13": -10.1836097044367, - } - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the mongo_sample has a key "_id" with the value of "SampleID" - assert mongo_sample == { - "_id": "2020-07452-02", - "Zscore_13": -10.1836097044367, - } - - -def test_build_sample_SampleProject_key(): - # GIVEN a sample_data with requiered key 'SampleID' and 'SampleProject' in int format - sample_data = { - "SampleID": "2020-07452-02", - "SampleProject": 201862, - } - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the value of "SampleProject" is in str format - assert mongo_sample == { - "_id": "2020-07452-02", - "SampleProject": "201862", - } - - -def test_build_sample_wrong_keys(): - # GIVEN a sample_data with not accepted keys: key1 key2 key3 - sample_data = { - "SampleID": "2020-07452-02", - "key1": " ", - "key2": 201862, - "key3": -10.1836097044367, - } - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the unaccepted keys will not be part of the mongo_sample" - assert mongo_sample == {"_id": "2020-07452-02"} - - -@pytest.mark.parametrize("sample_key", SAMPLE_KEYS) -def test_build_sample_str_values(sample_key): - # GIVEN a sample_data dict with requiered key 'SampleID' and a sample_key with some str value - sample_data = {"SampleID": "2020-07452-02", sample_key: "Value"} - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the the sample_key will be loaded into the mongo_sample dict - if sample_key == "SampleID": - assert mongo_sample == {"_id": "2020-07452-02", sample_key: "Value"} - - -@pytest.mark.parametrize("sample_key", SAMPLE_KEYS) -def test_build_sample_empty_strings(sample_key): - # GIVEN a sample_data dict with requiered key 'SampleID' and a sample_key with empty string as value - sample_data = {"SampleID": "2020-07452-02", sample_key: " "} - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the the sample_key will not be loaded into the mongo_sample dict - assert mongo_sample == {"_id": "2020-07452-02"} - - -@pytest.mark.parametrize("sample_key", SAMPLE_KEYS) -def test_build_sample_zero_values(sample_key): - # GIVEN a sample_data dict with requiered key 'SampleID' and a sample_key with value 0 - sample_data = {"SampleID": "2020-07452-02", sample_key: 0} - - # WHEN building a mongo sample - mongo_sample = build_sample(sample_data=sample_data) - - # THEN the the sample_key will be loaded into the mongo_sample dict - assert mongo_sample == {"_id": "2020-07452-02", sample_key: 0}