aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/db/test_sample_data.py
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-10 17:18:57 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commitdfa6a6106718f0c88f1b09aedae42eb31aafbb6c (patch)
treea15b5f73c674670f4d1562f6e6f2e1d02ece7b2c /tests/unit/db/test_sample_data.py
parent7641343e90f9a7f03cf0baf30818675efac6d7f3 (diff)
downloadgenenetwork3-dfa6a6106718f0c88f1b09aedae42eb31aafbb6c.tar.gz
Update how data is updated by re-using existing functions
* gn3/db/sample_data.py (get_sample_data_ids): Re-use "delete_sample_data" and "insert_sample_data" when updating data; and also add logic for updating modified data. * tests/unit/db/test_sample_data.py: Add tests for the above.
Diffstat (limited to 'tests/unit/db/test_sample_data.py')
-rw-r--r--tests/unit/db/test_sample_data.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py
index 4015ba5..80166fc 100644
--- a/tests/unit/db/test_sample_data.py
+++ b/tests/unit/db/test_sample_data.py
@@ -1,8 +1,10 @@
import pytest
+import gn3
-from gn3.db.sample_data import insert_sample_data
-from gn3.db.sample_data import delete_sample_data
from gn3.db.sample_data import __extract_actions
+from gn3.db.sample_data import delete_sample_data
+from gn3.db.sample_data import insert_sample_data
+from gn3.db.sample_data import update_sample_data
@pytest.mark.unit_test
@@ -94,3 +96,40 @@ def test_extract_actions():
"insert": {"data": "2,F", "csv_header": "SE,Sex"},
"update": {"data": "19,1", "csv_header": "Value,Count"},
})
+
+
+@pytest.mark.unit_test
+def test_update_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))
+ mocker.patch('gn3.db.sample_data.insert_sample_data',
+ return_value=1)
+ mocker.patch('gn3.db.sample_data.delete_sample_data',
+ return_value=1)
+ update_sample_data(conn=mock_conn,
+ trait_name=35,
+ original_data="BXD1,18,x,0,x",
+ updated_data="BXD1,x,2,1,F",
+ csv_header="Strain Name,Value,SE,Count,Sex",
+ phenotype_id=10007)
+ gn3.db.sample_data.insert_sample_data.assert_called_once_with(
+ conn=mock_conn,
+ trait_name=35,
+ data="2,F",
+ csv_header="SE,Sex",
+ phenotype_id=10007)
+ gn3.db.sample_data.delete_sample_data.assert_called_once_with(
+ conn=mock_conn,
+ trait_name=35,
+ data="18",
+ csv_header="Value",
+ phenotype_id=10007)
+ cursor.execute.assert_has_calls(
+ [mocker.call("UPDATE NStrain SET count = %s "
+ "WHERE StrainId = %s AND DataId = %s",
+ ('1', strain_id, data_id))],
+ any_order=False)