about summary refs log tree commit diff
path: root/tests/unit
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-17 14:34:25 +0300
committerBonfaceKilz2021-05-20 23:25:59 +0300
commit76418ebdbd9f89f04960646298c55098e20afefb (patch)
tree177ac3a95eb2672d9088fcdd1741bc7a31566636 /tests/unit
parent14a3cf0874bb8fc5c5b2817f8d2a9ab1cff17eca (diff)
downloadgenenetwork3-76418ebdbd9f89f04960646298c55098e20afefb.tar.gz
tests: test_phenotypes: New test cases for loading phenotypes
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/db/test_phenotypes.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit/db/test_phenotypes.py b/tests/unit/db/test_phenotypes.py
new file mode 100644
index 0000000..8b810fe
--- /dev/null
+++ b/tests/unit/db/test_phenotypes.py
@@ -0,0 +1,41 @@
+"""Tests for db/phenotypes.py"""
+from unittest import TestCase
+from unittest import mock
+
+from gn3.db.phenotypes import Phenotype
+from gn3.db.phenotypes import update_phenotype
+
+
+class TestPhenotypes(TestCase):
+    """Test cases for fetching chromosomes"""
+    def test_update_phenotype_with_no_data(self):
+        """
+        Test that a phenotype is updated correctly if an empty Phenotype dataclass
+        is provided
+        """
+        db_mock = mock.MagicMock()
+        self.assertEqual(update_phenotype(
+            db_mock, data=Phenotype(), where=Phenotype()), None)
+
+    def test_update_phenotype_with_data(self):
+        """
+        Test that a phenotype is updated correctly if some
+        data is provided
+        """
+        db_mock = mock.MagicMock()
+        with db_mock.cursor() as cursor:
+            type(cursor).rowcount = 1
+            self.assertEqual(update_phenotype(
+                db_mock, data=Phenotype(
+                    pre_pub_description="Test Pre Pub",
+                    submitter="Rob",
+                    post_pub_description="Test Post Pub"),
+                where=Phenotype(id_=1)), 1)
+            cursor.execute.assert_called_once_with(
+                "UPDATE Phenotype SET "
+                "Pre_publication_description = "
+                "'Test Pre Pub', "
+                "Post_publication_description = "
+                "'Test Post Pub', Submitter = 'Rob' "
+                "WHERE id = '1'"
+            )