aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py11
-rw-r--r--tests/r_qtl/test_r_qtl2_control_file.py1
-rw-r--r--tests/uploader/__init__.py (renamed from tests/qc_app/__init__.py)0
-rw-r--r--tests/uploader/phenotypes/__init__.py1
-rw-r--r--tests/uploader/phenotypes/test_misc.py387
-rw-r--r--tests/uploader/publications/__init__.py1
-rw-r--r--tests/uploader/publications/test_misc.py68
-rw-r--r--tests/uploader/test_entry.py (renamed from tests/qc_app/test_entry.py)0
-rw-r--r--tests/uploader/test_expression_data_pages.py (renamed from tests/qc_app/test_expression_data_pages.py)0
-rw-r--r--tests/uploader/test_files.py17
-rw-r--r--tests/uploader/test_parse.py (renamed from tests/qc_app/test_parse.py)3
-rw-r--r--tests/uploader/test_progress_indication.py (renamed from tests/qc_app/test_progress_indication.py)0
-rw-r--r--tests/uploader/test_results_page.py (renamed from tests/qc_app/test_results_page.py)0
-rw-r--r--tests/uploader/test_uploads_with_zip_files.py (renamed from tests/qc_app/test_uploads_with_zip_files.py)0
14 files changed, 485 insertions, 4 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/r_qtl/test_r_qtl2_control_file.py b/tests/r_qtl/test_r_qtl2_control_file.py
index 316307d..5b9fef6 100644
--- a/tests/r_qtl/test_r_qtl2_control_file.py
+++ b/tests/r_qtl/test_r_qtl2_control_file.py
@@ -16,6 +16,7 @@ __DEFAULTS__ = {
"pheno_transposed": False,
"covar_transposed": False,
"phenocovar_transposed": False,
+ "phenonum_transposed": False,
"gmap_transposed": False,
"pmap_transposed": False,
"phenose_transposed": False
diff --git a/tests/qc_app/__init__.py b/tests/uploader/__init__.py
index e69de29..e69de29 100644
--- a/tests/qc_app/__init__.py
+++ b/tests/uploader/__init__.py
diff --git a/tests/uploader/phenotypes/__init__.py b/tests/uploader/phenotypes/__init__.py
new file mode 100644
index 0000000..1e0a932
--- /dev/null
+++ b/tests/uploader/phenotypes/__init__.py
@@ -0,0 +1 @@
+"""phenotypes tests"""
diff --git a/tests/uploader/phenotypes/test_misc.py b/tests/uploader/phenotypes/test_misc.py
new file mode 100644
index 0000000..cf475ad
--- /dev/null
+++ b/tests/uploader/phenotypes/test_misc.py
@@ -0,0 +1,387 @@
+"""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/__init__.py b/tests/uploader/publications/__init__.py
new file mode 100644
index 0000000..de15e08
--- /dev/null
+++ b/tests/uploader/publications/__init__.py
@@ -0,0 +1 @@
+"""publications tests"""
diff --git a/tests/uploader/publications/test_misc.py b/tests/uploader/publications/test_misc.py
new file mode 100644
index 0000000..8c7e567
--- /dev/null
+++ b/tests/uploader/publications/test_misc.py
@@ -0,0 +1,68 @@
+"""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):
+ """Test publication differences — flesh out description…"""
+ assert publications_differences(
+ filedata, dbdata, pubmed2pubidmap) == expected
diff --git a/tests/qc_app/test_entry.py b/tests/uploader/test_entry.py
index 0c614a5..0c614a5 100644
--- a/tests/qc_app/test_entry.py
+++ b/tests/uploader/test_entry.py
diff --git a/tests/qc_app/test_expression_data_pages.py b/tests/uploader/test_expression_data_pages.py
index c2f7de1..c2f7de1 100644
--- a/tests/qc_app/test_expression_data_pages.py
+++ b/tests/uploader/test_expression_data_pages.py
diff --git a/tests/uploader/test_files.py b/tests/uploader/test_files.py
new file mode 100644
index 0000000..cb22fff
--- /dev/null
+++ b/tests/uploader/test_files.py
@@ -0,0 +1,17 @@
+"""Tests functions in the `uploader.files` module."""
+from pathlib import Path
+
+import pytest
+
+from uploader.files import sha256_digest_over_file
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+ "filepath,expectedhash",
+ ((Path("tests/test_data/average.tsv.zip"),
+ "a371c654c095c030edad468e1c3d6b176ea8adfbcd91a322afd37779044478d9"),
+ (Path("tests/test_data/standarderror.tsv"),
+ "a08332e0b06391d50eecb722f69d85fbdf374a2d77713ee879d3fd6c60419d55")))
+def test_sha256_digest_over_file(filepath: Path, expectedhash: str):
+ """Test the `sha256_digest_over_file` function."""
+ assert sha256_digest_over_file(filepath) == expectedhash
diff --git a/tests/qc_app/test_parse.py b/tests/uploader/test_parse.py
index 076c47c..20c75b7 100644
--- a/tests/qc_app/test_parse.py
+++ b/tests/uploader/test_parse.py
@@ -8,7 +8,8 @@ from uploader.jobs import job, jobsnamespace
from tests.conftest import uploadable_file_object
-def test_parse_with_existing_uploaded_file(#pylint: disable=[too-many-arguments]
+def test_parse_with_existing_uploaded_file(
+ #pylint: disable=[too-many-arguments,too-many-positional-arguments]
client,
db_url,
redis_url,
diff --git a/tests/qc_app/test_progress_indication.py b/tests/uploader/test_progress_indication.py
index 14a1050..14a1050 100644
--- a/tests/qc_app/test_progress_indication.py
+++ b/tests/uploader/test_progress_indication.py
diff --git a/tests/qc_app/test_results_page.py b/tests/uploader/test_results_page.py
index 8c8379f..8c8379f 100644
--- a/tests/qc_app/test_results_page.py
+++ b/tests/uploader/test_results_page.py
diff --git a/tests/qc_app/test_uploads_with_zip_files.py b/tests/uploader/test_uploads_with_zip_files.py
index 1506cfa..1506cfa 100644
--- a/tests/qc_app/test_uploads_with_zip_files.py
+++ b/tests/uploader/test_uploads_with_zip_files.py