aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-04 12:37:03 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commit9b714166cf0ebbbb098a52b97d7c9b4e3ec13a2e (patch)
treeaffc639dbbb39a7fb07d06bd12fc97d332339c1d /tests/unit
parent270ff08a94f29f1552baaafe19e8b31a272e9f8c (diff)
downloadgenenetwork3-9b714166cf0ebbbb098a52b97d7c9b4e3ec13a2e.tar.gz
Add test cases for inserting and deleting data
* tests/unit/db/test_sample_data.py (test_insert_sample_data): Test inserting data. (test_delete_sample_data): Test deleting data.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/db/test_sample_data.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py
new file mode 100644
index 0000000..4c03dbd
--- /dev/null
+++ b/tests/unit/db/test_sample_data.py
@@ -0,0 +1,75 @@
+import pytest
+
+from gn3.db.sample_data import insert_sample_data
+from gn3.db.sample_data import delete_sample_data
+
+
+@pytest.mark.unit_test
+def test_insert_sample_data(mocker):
+ mock_conn = mocker.MagicMock()
+ strain_id, data_id, inbredset_id = 1, 17373, 20
+ with mock_conn.cursor() as cursor:
+ cursor.fetchone.side_effect = (0, [19, ], 0)
+ mocker.patch('gn3.db.sample_data.get_sample_data_ids',
+ return_value=(strain_id, data_id, inbredset_id))
+ insert_sample_data(conn=mock_conn,
+ trait_name=35,
+ data="BXD1,18,3,0,M",
+ csv_header="Strain Name,Value,SE,Count,Sex",
+ phenotype_id=10007)
+ calls = [mocker.call("SELECT Id FROM PublishData where Id = %s "
+ "AND StrainId = %s",
+ (data_id, strain_id)),
+ mocker.call("INSERT INTO PublishData "
+ "(StrainId, Id, value) VALUES (%s, %s, %s)",
+ (strain_id, data_id, '18')),
+ mocker.call("INSERT INTO PublishSE "
+ "(StrainId, DataId, error) VALUES (%s, %s, %s)",
+ (strain_id, data_id, '3')),
+ mocker.call("INSERT INTO NStrain "
+ "(StrainId, DataId, count) VALUES (%s, %s, %s)",
+ (strain_id, data_id, '0')),
+ mocker.call("SELECT Id FROM CaseAttribute WHERE Name = %s",
+ ("Sex",)),
+ mocker.call("SELECT StrainId FROM CaseAttributeXRefNew "
+ "WHERE StrainId = %s AND "
+ "CaseAttributeId = %s AND InbredSetId = %s",
+ (strain_id, 19, inbredset_id)),
+ mocker.call("INSERT INTO CaseAttributeXRefNew "
+ "(StrainId, CaseAttributeId, Value, "
+ "InbredSetId) VALUES (%s, %s, %s, %s)",
+ (strain_id, 19, 'M', inbredset_id))
+ ]
+ cursor.execute.assert_has_calls(calls, any_order=False)
+
+
+@pytest.mark.unit_test
+def test_delete_sample_data(mocker):
+ mock_conn = mocker.MagicMock()
+ strain_id, data_id, inbredset_id = 1, 17373, 20
+ with mock_conn.cursor() as cursor:
+ cursor.fetchone.side_effect = (0, [19, ], 0)
+ mocker.patch('gn3.db.sample_data.get_sample_data_ids',
+ return_value=(strain_id, data_id, inbredset_id))
+ delete_sample_data(conn=mock_conn,
+ trait_name=35,
+ data="BXD1,18,3,0,M",
+ csv_header="Strain Name,Value,SE,Count,Sex",
+ phenotype_id=10007)
+ calls = [mocker.call("DELETE FROM PublishData WHERE "
+ "StrainId = %s AND Id = %s",
+ (strain_id, data_id)),
+ mocker.call("DELETE FROM PublishSE WHERE "
+ "StrainId = %s AND DataId = %s",
+ (strain_id, data_id)),
+ mocker.call("DELETE FROM NStrain WHERE "
+ "StrainId = %s AND DataId = %s",
+ (strain_id, data_id)),
+ mocker.call("DELETE FROM CaseAttributeXRefNew WHERE "
+ "StrainId = %s AND CaseAttributeId = "
+ "(SELECT CaseAttributeId FROM "
+ "CaseAttribute WHERE Name = %s) "
+ "AND InbredSetId = %s",
+ (strain_id, "Sex", inbredset_id)),
+ ]
+ cursor.execute.assert_has_calls(calls, any_order=False)