about summary refs log tree commit diff
path: root/wqflask/tests/api
diff options
context:
space:
mode:
authorBonfaceKilz2020-07-29 22:28:38 +0300
committerBonfaceKilz2020-07-29 23:03:35 +0300
commitd50f72869b8d0a7078f0481aad2b04346cd56e3f (patch)
tree21bf38cd291e46ec151f6e3e47368446f48f6142 /wqflask/tests/api
parent3425e7a5dbf5a6983424659c05c258e7a132edf3 (diff)
downloadgenenetwork2-d50f72869b8d0a7078f0481aad2b04346cd56e3f.tar.gz
Add tests for "phenotypes_exist" and "genotypes_exist"
* wqflask/tests/api/test_gen_menu.py: Add new tests
Diffstat (limited to 'wqflask/tests/api')
-rw-r--r--wqflask/tests/api/test_gen_menu.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/wqflask/tests/api/test_gen_menu.py b/wqflask/tests/api/test_gen_menu.py
index a2a93da7..be66a4c6 100644
--- a/wqflask/tests/api/test_gen_menu.py
+++ b/wqflask/tests/api/test_gen_menu.py
@@ -4,6 +4,8 @@ import mock
 
 from wqflask.api.gen_menu import get_species
 from wqflask.api.gen_menu import get_groups
+from wqflask.api.gen_menu import phenotypes_exist
+from wqflask.api.gen_menu import genotypes_exist
 
 
 class TestGenMenu(unittest.TestCase):
@@ -62,3 +64,50 @@ class TestGenMenu(unittest.TestCase):
                  "InbredSet.FullName) ASC, InbredSet.FullName ASC, " +
                  "InbredSet.MenuOrderId ASC").format(name)
             )
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_phenotypes_exist_called_with_correct_query(self, db_mock):
+        """Test that phenotypes_exist is called with the correct query"""
+        db_mock.db.execute.return_value.fetchone.return_value = None
+        phenotypes_exist("test")
+        db_mock.db.execute.assert_called_with(
+            "SELECT Name FROM PublishFreeze WHERE PublishFreeze.Name = 'testPublish'"
+        )
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_phenotypes_exist_with_falsy_values(self, db_mock):
+        """Test that phenotype check returns correctly when given a None value"""
+        for x in [None, False, (), [], ""]:
+            db_mock.db.execute.return_value.fetchone.return_value = x
+            self.assertFalse(phenotypes_exist("test"))
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_phenotypes_exist_with_truthy_value(self, db_mock):
+        """Test that phenotype check returns correctly when given Truthy """
+        for x in ["x", ("result"), ["result"], [1]]:
+            db_mock.db.execute.return_value.fetchone.return_value = (x)
+            self.assertTrue(phenotypes_exist("test"))
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_genotypes_exist_called_with_correct_query(self, db_mock):
+        """Test that genotypes_exist is called with the correct query"""
+        db_mock.db.execute.return_value.fetchone.return_value = None
+        genotypes_exist("test")
+        db_mock.db.execute.assert_called_with(
+            "SELECT Name FROM GenoFreeze WHERE GenoFreeze.Name = 'testGeno'"
+        )
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_genotypes_exist_with_falsy_values(self, db_mock):
+        """Test that genotype check returns correctly when given a None value"""
+        for x in [None, False, (), [], ""]:
+            db_mock.db.execute.return_value.fetchone.return_value = x
+            self.assertFalse(genotypes_exist("test"))
+
+    @mock.patch('wqflask.api.gen_menu.g')
+    def test_genotypes_exist_with_truthy_value(self, db_mock):
+        """Test that genotype check returns correctly when given Truthy """
+        for x in ["x", ("result"), ["result"], [1]]:
+            db_mock.db.execute.return_value.fetchone.return_value = (x)
+            self.assertTrue(phenotypes_exist("test"))
+