aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2022-05-10 17:05:28 +0300
committerBonfaceKilz2022-05-27 15:02:25 +0300
commitbc99eed7438e087650125ceab04797db7c726f31 (patch)
treeac65f20dbd1d1824c04cf98efd9557e24f552115
parent236d9236c794d7870258eab9e087f990c557462a (diff)
downloadgenenetwork3-bc99eed7438e087650125ceab04797db7c726f31.tar.gz
Return all the results from CaseAttributes column as is
* gn3/db/sample_data.py: Remove "collections" import. Add "Optional" import. (get_case_attributes): Return the results of "fetchall" from the case attributes. * tests/unit/db/test_sample_data.py (test_get_case_attributes): Update failing test.
-rw-r--r--gn3/db/sample_data.py27
-rw-r--r--tests/unit/db/test_sample_data.py64
2 files changed, 10 insertions, 81 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index 3f7e2da..f79ce97 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -1,5 +1,5 @@
"""Module containing functions that work with sample data"""
-from typing import Any, Tuple, Dict, Callable
+from typing import Any, Tuple, Dict, Callable, Optional
import re
import collections
@@ -425,27 +425,8 @@ def insert_sample_data(
raise MySQLdb.Error(_e) from _e
-def get_case_attributes(conn) -> dict:
- """Get all the case attributes as a dictionary from the database. Should there
- exist more than one case attribute with the same name, put the id in
- brackets."""
- results = {}
+def get_case_attributes(conn) -> Optional[Tuple]:
+ """Get all the case attributes from the database."""
with conn.cursor() as cursor:
cursor.execute("SELECT Id, Name, Description FROM CaseAttribute")
- _r = cursor.fetchall()
- _dups = [
- item
- for item, count in collections.Counter(
- [name for _, name, _ in _r]
- ).items()
- if count > 1
- ]
- for _id, _name, _desc in _r:
- _name = _name.strip()
- _desc = _desc if _desc else ""
- if _name in _dups:
- results[f"{_name} ({_id})"] = _desc
- else:
- results[f"{_name}"] = _desc
-
- return results
+ return cursor.fetchall()
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py
index 0fc20f4..8af4d3b 100644
--- a/tests/unit/db/test_sample_data.py
+++ b/tests/unit/db/test_sample_data.py
@@ -239,62 +239,10 @@ def test_get_case_attributes(mocker):
cursor.execute.assert_called_once_with(
"SELECT Id, Name, Description FROM CaseAttribute"
)
- assert results == {
- "Condition (1)": "",
- "Tissue": "",
- "Age": "Cum sociis natoque penatibus et magnis dis",
- "Condition (4)": "Description A",
- "Condition (5)": "Description B",
- }
-
-
-@pytest.mark.unit_test
-def test_get_trait_csv_sample_data(mocker):
- """Test fetching trait sample data"""
- mock_conn = mocker.MagicMock()
- with mock_conn.cursor() as cursor:
- cursor.fetchall.return_value = [
- ["JL00005,896.000000,x,x", "Age", "896"],
- ["JL00005,896.000000,x,x", "DOB", "4/22/04"],
- ["JL00005,896.000000,x,x", "Date Geno", "x"],
- ["JL00005,896.000000,x,x", "Drug/Site", "4OHPBN_J"],
- ["JL00005,896.000000,x,x", "MOD", "Oct"],
- ["JL00005,896.000000,x,x", "Platform", "x"],
- [
- "JL00005,896.000000,x,x",
- "SNP",
- """0
-""",
- ],
- ["JL00005,896.000000,x,x", "Sex", "M"],
- ["JL00005,896.000000,x,x", "Site", "JL"],
- ["JL00005,896.000000,x,x", "Tx", "1"],
- ["JL00005,896.000000,x,x", "Year", "2004"],
- ["JL00058,686.000000,x,x", "Age", "686"],
- ["JL00058,686.000000,x,x", "DOB", "4/22/04"],
- ["JL00058,686.000000,x,x", "Date Geno", "2017.06"],
- ["JL00058,686.000000,x,x", "Drug/Site", "Cont_04_J"],
- ["JL00058,686.000000,x,x", "MOD", "Mar"],
- ["JL00058,686.000000,x,x", "Platform", "M"],
- [
- "JL00058,686.000000,x,x",
- "SNP",
- """2
-""",
- ],
- ["JL00058,686.000000,x,x", "Sex", "M"],
- ["JL00058,686.000000,x,x", "Site", "JL"],
- ["JL00058,686.000000,x,x", "Tx", "0"],
- ["JL00058,686.000000,x,x", "Year", "2004"],
- ]
- assert get_trait_csv_sample_data(
- conn=mock_conn, trait_name=10007, phenotype_id=35
- ) == (
- "Strain Name,Value,SE,Count,Age,DOB,"
- "Date Geno,Drug/Site,MOD,"
- "Platform,SNP,Sex,Site,Tx,Year\n"
- "JL00005,896.000000,x,x,"
- "896,4/22/04,x,4OHPBN_J,Oct,x,0,M,JL,1,2004\n"
- "JL00058,686.000000,x,x,"
- "686,4/22/04,2017.06,Cont_04_J,Mar,M,2,M,JL,0,2004\n"
+ assert results == (
+ (1, "Condition", None),
+ (2, "Tissue", None),
+ (3, "Age", "Cum sociis natoque penatibus et magnis dis"),
+ (4, "Condition", "Description A"),
+ (5, "Condition", "Description B"),
)