aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/db/test_traits.py195
1 files changed, 0 insertions, 195 deletions
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index a1c1136..434f758 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -5,9 +5,7 @@ from gn3.db.traits import (
build_trait_name,
export_trait_data,
export_informative,
- get_trait_csv_sample_data,
set_haveinfo_field,
- update_sample_data,
retrieve_trait_info,
set_confidential_field,
set_homologene_id_field,
@@ -203,56 +201,6 @@ class TestTraitsDBFunctions(TestCase):
expected)
@pytest.mark.unit_test
- def test_update_sample_data(self):
- """Test that the SQL queries when calling update_sample_data are called with
- the right calls.
-
- """
- # pylint: disable=C0103
- db_mock = mock.MagicMock()
- PUBLISH_DATA_SQL: str = (
- "UPDATE PublishData SET value = %s "
- "WHERE StrainId = %s AND Id = %s")
- PUBLISH_SE_SQL: str = (
- "UPDATE PublishSE SET error = %s "
- "WHERE StrainId = %s AND DataId = %s")
- N_STRAIN_SQL: str = (
- "UPDATE NStrain SET count = %s "
- "WHERE StrainId = %s AND DataId = %s")
-
- with db_mock.cursor() as cursor:
- type(cursor).rowcount = 1
- mock_fetchone = mock.MagicMock()
- mock_fetchone.return_value = (1, 1)
- type(cursor).fetchone = mock_fetchone
- self.assertEqual(update_sample_data(
- conn=db_mock, strain_name="BXD11",
- trait_name="1",
- phenotype_id=10, value=18.7,
- error=2.3, count=2),
- (1, 1, 1))
- cursor.execute.assert_has_calls(
- [mock.call(('SELECT Strain.Id, PublishData.Id FROM'
- ' (PublishData, Strain, PublishXRef, '
- 'PublishFreeze) LEFT JOIN PublishSE ON '
- '(PublishSE.DataId = PublishData.Id '
- 'AND PublishSE.StrainId = '
- 'PublishData.StrainId) LEFT JOIN NStrain ON '
- '(NStrain.DataId = PublishData.Id AND '
- 'NStrain.StrainId = PublishData.StrainId) WHERE '
- 'PublishXRef.InbredSetId = '
- 'PublishFreeze.InbredSetId AND PublishData.Id = '
- 'PublishXRef.DataId AND PublishXRef.Id = %s AND '
- 'PublishXRef.PhenotypeId = %s AND '
- 'PublishData.StrainId = Strain.Id AND '
- 'Strain.Name = %s'),
- ("1", 10, "BXD11")),
- mock.call(PUBLISH_DATA_SQL, (18.7, 1, 1)),
- mock.call(PUBLISH_SE_SQL, (2.3, 1, 1)),
- mock.call(N_STRAIN_SQL, (2, 1, 1))]
- )
-
- @pytest.mark.unit_test
def test_set_haveinfo_field(self):
"""Test that the `haveinfo` field is set up correctly"""
for trait_info, expected in [
@@ -432,146 +380,3 @@ class TestTraitsDBFunctions(TestCase):
with self.subTest(trait_data=trait_data):
self.assertEqual(
export_informative(trait_data, inc_var), expected)
-
-
-class TestRetrieveCsvData(TestCase):
- "Test cases for retrieving csv data"
- def test_get_trait_csv_sample_data_with_case_attributes(self):
- """Test that correct csv is returned when all samples have case attribute
-values"""
- mock_conn = mock.MagicMock()
- with mock_conn.cursor() as cursor:
- cursor.fetchall.return_value = [
- ['H1044,25.900000,x,1', 'Strain', 'BXD29'],
- ['H1044,25.900000,x,1', 'Condition', 'CD'],
- ['H1044,25.900000,x,1', 'EarTag', 1044],
- ['H1044,25.900000,x,1', 'Age', 724],
- ['H1096,23.700001,x,1', 'EarTag', 1096],
- ['H1096,23.700001,x,1', 'Age', 732],
- ['H1096,23.700001,x,1', 'Strain', 'BXD90'],
- ['H1096,23.700001,x,1', 'Condition', 'CD'],
- ['H1163,95.000000,x,1', 'Strain', 'D2B6F1'],
- ['H1163,95.000000,x,1', 'Condition', 'HF'],
- ['H1163,95.000000,x,1', 'EarTag', 1163],
- ['H1163,95.000000,x,1', 'Age', 1114],
- ['H1230,88.099998,x,1', 'EarTag', 1230],
- ['H1230,88.099998,x,1', 'Age', 726],
- ['H1230,88.099998,x,1', 'Strain', 'B6D2F1'],
- ['H1230,88.099998,x,1', 'Condition', 'HF'],
- ['H1251,24.100000,x,1', 'EarTag', 1251],
- ['H1251,24.100000,x,1', 'Age', 711],
- ['H1251,24.100000,x,1', 'Strain', 'C57BL/6J'],
- ['H1251,24.100000,x,1', 'Condition', 'CD'],
- ['H1292,24.900000,x,1', 'Strain', 'C57BL/6J'],
- ['H1292,24.900000,x,1', 'Condition', 'CD'],
- ['H1292,24.900000,x,1', 'EarTag', 1292],
- ['H1292,24.900000,x,1', 'Age', 705],
- ]
- csv = get_trait_csv_sample_data(conn=mock_conn,
- trait_name=10006,
- phenotype_id=28409)
- self.assertEqual(csv, """Strain Name,Value,SE,Count,Age,Condition,EarTag,Strain
-H1044,25.900000,x,1,724,CD,1044,BXD29
-H1096,23.700001,x,1,732,CD,1096,BXD90
-H1163,95.000000,x,1,1114,HF,1163,D2B6F1
-H1230,88.099998,x,1,726,HF,1230,B6D2F1
-H1251,24.100000,x,1,711,CD,1251,C57BL/6J
-H1292,24.900000,x,1,705,CD,1292,C57BL/6J
-""")
-
- def test_get_trait_csv_sample_data_with_missing_case_attributes(self):
- """Test that the correct csv is returned when some case attributes are not
-present from some samples"""
- mock_conn = mock.MagicMock()
- with mock_conn.cursor() as cursor:
- cursor.fetchall.return_value = [
- ['H1044,25.900000,x,1', 'Strain', 'BXD29'],
- ['H1044,25.900000,x,1', 'Condition', 'CD'],
- ['H1044,25.900000,x,1', 'Age', 724],
- ['H1096,23.700001,x,1', 'Age', 732],
- ['H1096,23.700001,x,1', 'Strain', 'BXD90'],
- ['H1096,23.700001,x,1', 'Condition', 'CD'],
- ['H1163,95.000000,x,1', 'Condition', 'HF'],
- ['H1163,95.000000,x,1', 'EarTag', 1163],
- ['H1163,95.000000,x,1', 'Age', 1114],
- ['H1230,88.099998,x,1', 'EarTag', 1230],
- ['H1230,88.099998,x,1', 'Age', 726],
- ['H1230,88.099998,x,1', 'Strain', 'B6D2F1'],
- ['H1230,88.099998,x,1', 'Condition', 'HF'],
- ['H1251,24.100000,x,1', 'EarTag', 1251],
- ['H1251,24.100000,x,1', 'Age', 711],
- ['H1251,24.100000,x,1', 'Strain', 'C57BL/6J'],
- ['H1251,24.100000,x,1', 'Condition', 'CD'],
- ['H1292,24.900000,x,1', 'Strain', 'C57BL/6J'],
- ['H1292,24.900000,x,1', 'Condition', 'CD'],
- ['H1292,24.900000,x,1', 'EarTag', 1292],
- ]
- csv = get_trait_csv_sample_data(conn=mock_conn,
- trait_name=10006,
- phenotype_id=28409)
- self.assertEqual(csv, """Strain Name,Value,SE,Count,Age,Condition,EarTag,Strain
-H1044,25.900000,x,1,724,CD,x,BXD29
-H1096,23.700001,x,1,732,CD,x,BXD90
-H1163,95.000000,x,1,1114,HF,1163,x
-H1230,88.099998,x,1,726,HF,1230,B6D2F1
-H1251,24.100000,x,1,711,CD,1251,C57BL/6J
-H1292,24.900000,x,1,x,CD,1292,C57BL/6J
-""")
-
- def test_get_trait_csv_sample_data_with_varying_case_attributes(self):
- """Test that the correct csv is returned when case attributes are entirely
-missing from same samples, and only one sample has a case attribute that is
-not present in all other samples"""
- mock_conn = mock.MagicMock()
- with mock_conn.cursor() as cursor:
- cursor.fetchall.return_value = [
- ['H1044,25.900000,x,1', 'x', 'x'],
- ['H1096,23.700001,x,1', 'x', 'x'],
- ['H1163,95.000000,x,1', 'x', 'x'],
- ['H1230,88.099998,x,1', 'x', 'x'],
- ['H1251,24.100000,x,1', 'x', 'x'],
- ['H1292,24.900000,x,1', 'x', 'x'],
- ]
- csv = get_trait_csv_sample_data(conn=mock_conn,
- trait_name=10006,
- phenotype_id=28409)
- self.assertEqual(csv, """Strain Name,Value,SE,Count
-H1044,25.900000,x,1
-H1096,23.700001,x,1
-H1163,95.000000,x,1
-H1230,88.099998,x,1
-H1251,24.100000,x,1
-H1292,24.900000,x,1""")
-
- def test_get_trait_csv_sample_data_with_empty_case_attributes(self):
- mock_conn = mock.MagicMock()
- with mock_conn.cursor() as cursor:
- cursor.fetchall.return_value = [
- ['H1044,25.900000,x,1', 'x', 'x'],
- ['H1096,23.700001,x,1', 'Age', 732],
- ['H1096,23.700001,x,1', 'Sex', "M"],
- ['H1096,23.700001,x,1', 'Strain', 'BXD90'],
- ['H1096,23.700001,x,1', 'Condition', 'CD'],
- ['H1163,95.000000,x,1', 'Condition', 'HF'],
- ['H1163,95.000000,x,1', 'EarTag', 1163],
- ['H1163,95.000000,x,1', 'Age', 1114],
- ['H1230,88.099998,x,1', 'EarTag', 1230],
- ['H1230,88.099998,x,1', 'Age', 726],
- ['H1230,88.099998,x,1', 'Strain', 'B6D2F1'],
- ['H1230,88.099998,x,1', 'Condition', 'HF'],
- ['H1251,24.100000,x,1', 'x', 'x'],
- ['H1292,24.900000,x,1', 'Strain', 'C57BL/6J'],
- ['H1292,24.900000,x,1', 'Condition', 'CD'],
- ['H1292,24.900000,x,1', 'EarTag', 1292],
- ]
- csv = get_trait_csv_sample_data(conn=mock_conn,
- trait_name=10006,
- phenotype_id=28409)
- self.assertEqual(csv, """Strain Name,Value,SE,Count,Age,Condition,EarTag,Sex,Strain
-H1044,25.900000,x,1,x,x,x,x,x
-H1096,23.700001,x,1,732,CD,x,M,BXD90
-H1163,95.000000,x,1,1114,HF,1163,x,x
-H1230,88.099998,x,1,726,HF,1230,x,B6D2F1
-H1251,24.100000,x,1,x,x,x,x,x
-H1292,24.900000,x,1,x,CD,1292,x,C57BL/6J
-""")