about summary refs log tree commit diff
path: root/tests/unit/db
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-30 06:11:57 +0300
committerMuriithi Frederick Muriuki2021-07-30 06:11:57 +0300
commit75ba10b9f7e8c5c7fabbd0f4134a1475cc180ae1 (patch)
treef6ff2fd64cd288d75af4900cb7b2cd984f598ce0 /tests/unit/db
parent77312535e643e4c8fecd7c20b3381996808dea11 (diff)
parent00278bc237c90b4ac276171a32bbe57e056644b6 (diff)
downloadgenenetwork3-75ba10b9f7e8c5c7fabbd0f4134a1475cc180ae1.tar.gz
Merge branch 'main' of github.com:genenetwork/genenetwork3 into heatmap_decompose_db_retrieval
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi

Fix merge conflicts in:

* gn3/db/traits.py
* tests/unit/db/test_traits.py
Diffstat (limited to 'tests/unit/db')
-rw-r--r--tests/unit/db/test_traits.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index e3c5c28..c8f28b5 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -11,7 +11,9 @@ from gn3.db.traits import (
     retrieve_temp_trait_info,
     retrieve_trait_dataset_name,
     retrieve_publish_trait_info,
-    retrieve_probeset_trait_info)
+    retrieve_probeset_trait_info,
+    update_sample_data)
+
 
 class TestTraitsDBFunctions(TestCase):
     "Test cases for traits functions"
@@ -112,3 +114,32 @@ class TestTraitsDBFunctions(TestCase):
                             trait_type, trait_name, trait_dataset_id,
                             trait_dataset_name, db_mock),
                         tuple())
+
+    def test_update_sample_data(self):
+        """Test that the SQL queries when calling update_sample_data are called with
+        the right calls.
+
+        """
+        db_mock = mock.MagicMock()
+
+        STRAIN_ID_SQL: str = "UPDATE Strain SET Name = %s WHERE Id = %s"
+        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
+            self.assertEqual(update_sample_data(
+                conn=db_mock, strain_name="BXD11",
+                strain_id=10, publish_data_id=8967049,
+                value=18.7, error=2.3, count=2),
+                             (1, 1, 1, 1))
+            cursor.execute.assert_has_calls(
+                [mock.call(STRAIN_ID_SQL, ('BXD11', 10)),
+                 mock.call(PUBLISH_DATA_SQL, (18.7, 10, 8967049)),
+                 mock.call(PUBLISH_SE_SQL, (2.3, 10, 8967049)),
+                 mock.call(N_STRAIN_SQL, (2, 10, 8967049))]
+            )