aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py11
-rw-r--r--tests/uploader/phenotypes/test_misc.py303
-rw-r--r--tests/uploader/publications/test_misc.py67
3 files changed, 378 insertions, 3 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 9012221..a716c52 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,6 +2,8 @@
import io
import os
import uuid
+import shutil
+from pathlib import Path
from hashlib import sha256
import redis
@@ -46,17 +48,20 @@ def cleanup_redis(redisuri: str, prefix: str):
@pytest.fixture(scope="module")
def client():
"Fixture for test client"
- app = create_app()
test_prefix = sha256(f"test:{uuid.uuid4()}".encode("utf8")).hexdigest()
- app.config.update({
+ tests_work_dir = Path("/tmp/{test_prefix}")
+ tests_work_dir.mkdir(exist_ok=True)
+ app = create_app({
"TESTING": True,
"GNQC_REDIS_PREFIX": f"{test_prefix}:GNQC",
- "JOBS_TTL_SECONDS": 2 * 60 * 60# 2 hours
+ "JOBS_TTL_SECONDS": 2 * 60 * 60,# 2 hours
+ "ASYNCHRONOUS_JOBS_SQLITE_DB": f"{tests_work_dir}/jobs.db"
})
with app.app_context():
yield app.test_client()
cleanup_redis(app.config["REDIS_URL"], test_prefix)
+ shutil.rmtree(tests_work_dir, ignore_errors=True)
@pytest.fixture(scope="module")
def db_url(client):#pylint: disable=[redefined-outer-name]
diff --git a/tests/uploader/phenotypes/test_misc.py b/tests/uploader/phenotypes/test_misc.py
new file mode 100644
index 0000000..c0261aa
--- /dev/null
+++ b/tests/uploader/phenotypes/test_misc.py
@@ -0,0 +1,303 @@
+"""Test miscellaneous phenotypes functions."""
+
+import pytest
+
+from uploader.phenotypes.misc import phenotypes_data_differences
+
+__sample_db_phenotypes_data__ = (
+ {
+ "PhenotypeId": 4,
+ "xref_id": 10001,
+ "DataId": 8967043,
+ "data": {
+ "B6D2F1": {"StrainId": 1, "value": None},
+ "C57BL/6J": {"StrainId": 2, "value": None},
+ "DBA/2J": {"StrainId": 3, "value": None},
+ "BXD1": {"StrainId": 4, "value": 61.4},
+ "BXD2": {"StrainId": 5, "value": 49},
+ "BXD5": {"StrainId": 6, "value": 62.5},
+ "BXD6": {"StrainId": 7, "value": 53.1}
+ }
+ },
+ {
+ "PhenotypeId": 10,
+ "xref_id": 10002,
+ "DataId": 8967044,
+ "data": {
+ "B6D2F1": {"StrainId": 1, "value": None},
+ "C57BL/6J": {"StrainId": 2, "value": None},
+ "DBA/2J": {"StrainId": 3, "value": None},
+ "BXD1": {"StrainId": 4, "value": 54.1},
+ "BXD2": {"StrainId": 5, "value": 50.1},
+ "BXD5": {"StrainId": 6, "value": 53.3},
+ "BXD6": {"StrainId": 7, "value": 55.1}
+ }
+ },
+ {
+ "PhenotypeId": 15,
+ "xref_id": 10003,
+ "DataId": 8967045,
+ "data": {
+ "B6D2F1": {"StrainId": 1, "value": None},
+ "C57BL/6J": {"StrainId": 2, "value": None},
+ "DBA/2J": {"StrainId": 3, "value": None},
+ "BXD1": {"StrainId": 4, "value": 483},
+ "BXD2": {"StrainId": 5, "value": 403},
+ "BXD5": {"StrainId": 6, "value": 501},
+ "BXD6": {"StrainId": 7, "value": 403}
+ }
+ },
+ {
+ "PhenotypeId": 20,
+ "xref_id": 10004,
+ "DataId": 8967046,
+ "data": {
+ "B6D2F1": {"StrainId": 1, "value": None},
+ "C57BL/6J": {"StrainId": 2, "value": None},
+ "DBA/2J": {"StrainId": 3, "value": None},
+ "BXD1": {"StrainId": 4, "value": 49.8},
+ "BXD2": {"StrainId": 5, "value": 45.5},
+ "BXD5": {"StrainId": 6, "value": 62.9},
+ "BXD6": {"StrainId": 7, "value": None}
+ }
+ },
+ {
+ "PhenotypeId": 25,
+ "xref_id": 10005,
+ "DataId": 8967047,
+ "data": {
+ "B6D2F1": {"StrainId": 1, "value": None},
+ "C57BL/6J": {"StrainId": 2, "value": None},
+ "DBA/2J": {"StrainId": 3, "value": None},
+ "BXD1": {"StrainId": 4, "value": 46},
+ "BXD2": {"StrainId": 5, "value": 44.9},
+ "BXD5": {"StrainId": 6, "value": 52.5},
+ "BXD6": {"StrainId": 7, "value": None}
+ }
+ })
+
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+ "filedata,dbdata,expected",
+ ((tuple(), tuple(), tuple()), # No data
+
+ # No data difference
+ (({
+ "phenotype_id": 4,
+ "xref_id": 10001,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 61.4,
+ "BXD2": 49,
+ "BXD5":62.5,
+ "BXD6": 53.1
+ }
+ },
+ {
+ "phenotype_id": 10,
+ "xref_id": 10002,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 54.1,
+ "BXD2": 50.1,
+ "BXD5": 53.3,
+ "BXD6": 55.1
+ }
+ },
+ {
+ "phenotype_id": 15,
+ "xref_id": 10003,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 483,
+ "BXD2": 403,
+ "BXD5": 501,
+ "BXD6": 403
+ }
+ },
+ {
+ "phenotype_id": 20,
+ "xref_id": 10004,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 49.8,
+ "BXD2": 45.5,
+ "BXD5": 62.9,
+ "BXD6": None
+ }
+ },
+ {
+ "phenotype_id": 25,
+ "xref_id": 10005,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 46,
+ "BXD2": 44.9,
+ "BXD5": 52.5,
+ "BXD6": None
+ }
+ }),
+ __sample_db_phenotypes_data__,
+ tuple()),
+
+ # Change values: No deletions
+ (({
+ "phenotype_id": 4,
+ "xref_id": 10001,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 77.2,
+ "BXD2": 49,
+ "BXD5":62.5,
+ "BXD6": 53.1
+ }
+ },
+ {
+ "phenotype_id": 10,
+ "xref_id": 10002,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 54.1,
+ "BXD2": 50.1,
+ "BXD5": 53.3,
+ "BXD6": 55.1
+ }
+ },
+ {
+ "phenotype_id": 15,
+ "xref_id": 10003,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 483,
+ "BXD2": 403,
+ "BXD5": 503,
+ "BXD6": 903
+ }
+ },
+ {
+ "phenotype_id": 20,
+ "xref_id": 10004,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": 1,
+ "BXD1": 8,
+ "BXD2": 9,
+ "BXD5": 62.9,
+ "BXD6": None
+ }
+ },
+ {
+ "phenotype_id": 25,
+ "xref_id": 10005,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 46,
+ "BXD2": 44.9,
+ "BXD5": 52.5,
+ "BXD6": None
+ }
+ }),
+ __sample_db_phenotypes_data__,
+ ({"PhenotypeId": 4, "xref_id": 10001, "DataId": 8967043, "StrainId": 4, "StrainName": "BXD1", "value": 77.2},
+ {"PhenotypeId": 15, "xref_id": 10003, "DataId": 8967045, "StrainId": 6, "StrainName": "BXD5", "value": 503},
+ {"PhenotypeId": 15, "xref_id": 10003, "DataId": 8967045, "StrainId": 7, "StrainName": "BXD6", "value": 903},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 3, "StrainName": "DBA/2J", "value": 1},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 4, "StrainName": "BXD1", "value": 8},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 5, "StrainName": "BXD2", "value": 9})),
+
+ # Changes — with deletions
+ (({
+ "phenotype_id": 4,
+ "xref_id": 10001,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": None,
+ "BXD2": 49,
+ "BXD5":62.5,
+ "BXD6": 53.1
+ }
+ },
+ {
+ "phenotype_id": 10,
+ "xref_id": 10002,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 54.1,
+ "BXD2": 50.1,
+ "BXD5": 53.3,
+ "BXD6": 55.1
+ }
+ },
+ {
+ "phenotype_id": 15,
+ "xref_id": 10003,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 483,
+ "BXD2": 403,
+ "BXD5": None,
+ "BXD6": None
+ }
+ },
+ {
+ "phenotype_id": 20,
+ "xref_id": 10004,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": 15,
+ "BXD1": None,
+ "BXD2": 24,
+ "BXD5": 62.9,
+ "BXD6": None
+ }
+ },
+ {
+ "phenotype_id": 25,
+ "xref_id": 10005,
+ "data": {
+ "B6D2F1": None,
+ "C57BL/6J": None,
+ "DBA/2J": None,
+ "BXD1": 46,
+ "BXD2": 44.9,
+ "BXD5": 52.5,
+ "BXD6": None
+ }
+ }),
+ __sample_db_phenotypes_data__,
+ ({"PhenotypeId": 4, "xref_id": 10001, "DataId": 8967043, "StrainId": 4, "StrainName": "BXD1", "value": None},
+ {"PhenotypeId": 15, "xref_id": 10003, "DataId": 8967045, "StrainId": 6, "StrainName": "BXD5", "value": None},
+ {"PhenotypeId": 15, "xref_id": 10003, "DataId": 8967045, "StrainId": 7, "StrainName": "BXD6", "value": None},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 3, "StrainName": "DBA/2J", "value": 15},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 4, "StrainName": "BXD1", "value": None},
+ {"PhenotypeId": 20, "xref_id": 10004, "DataId": 8967046, "StrainId": 5, "StrainName": "BXD2", "value": 24}))))
+def test_phenotypes_data_differences(filedata, dbdata, expected):
+ """Test differences are computed correctly."""
+ assert phenotypes_data_differences(filedata, dbdata) == expected
diff --git a/tests/uploader/publications/test_misc.py b/tests/uploader/publications/test_misc.py
new file mode 100644
index 0000000..7a52941
--- /dev/null
+++ b/tests/uploader/publications/test_misc.py
@@ -0,0 +1,67 @@
+"""Tests for functions used for bulk editing."""
+import pytest
+
+from uploader.publications.misc import publications_differences
+
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+ "filedata,dbdata,pubmed2pubidmap,expected",
+ (((), (), {}, tuple()), # no data
+
+ # Same Data
+ (({"phenotype_id": 1, "xref_id": 10001, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10002, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10003, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10005, "PubMed_ID": 9999999999999}),
+ ({"PhenotypeId": 1, "xref_id": 10001, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10002, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10003, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10004, "PublicationId": 15,
+ "PubMed_ID": 9999999999999}),
+ {9999999999999: 15},
+ tuple()),
+
+ # Differences: no new pubmeds (all pubmeds in db)
+ (({"phenotype_id": 1, "xref_id": 10001, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10002, "PubMed_ID": 9999999999998},
+ {"phenotype_id": 1, "xref_id": 10003, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10004, "PubMed_ID": 9999999999997}),
+ ({"PhenotypeId": 1, "xref_id": 10001, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10002, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10003, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10004, "PublicationId": 15,
+ "PubMed_ID": None}),
+ {9999999999999: 15, 9999999999998: 18, 9999999999997: 12},
+ ({"PhenotypeId": 1, "xref_id": 10002, "PublicationId": 18,
+ "PubMed_ID": 9999999999998},
+ {"PhenotypeId": 1, "xref_id": 10004, "PublicationId": 12,
+ "PubMed_ID": 9999999999997})),
+
+ # Differences: Deletions of pubmeds
+ (({"phenotype_id": 1, "xref_id": 10001, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10002, "PubMed_ID": None},
+ {"phenotype_id": 1, "xref_id": 10003, "PubMed_ID": 9999999999999},
+ {"phenotype_id": 1, "xref_id": 10004, "PubMed_ID": None}),
+ ({"PhenotypeId": 1, "xref_id": 10001, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10002, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10003, "PublicationId": 15,
+ "PubMed_ID": 9999999999999},
+ {"PhenotypeId": 1, "xref_id": 10004, "PublicationId": 15,
+ "PubMed_ID": 9999999999999}),
+ {9999999999999: 15, 9999999999998: 18, 9999999999997: 12},
+ ({"PhenotypeId": 1, "xref_id": 10002, "PublicationId": None,
+ "PubMed_ID": None},
+ {"PhenotypeId": 1, "xref_id": 10004, "PublicationId": None,
+ "PubMed_ID": None}))))
+def test_publications_differences(filedata, dbdata, pubmed2pubidmap, expected):
+ assert publications_differences(
+ filedata, dbdata, pubmed2pubidmap) == expected