aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorBonfaceKilz2020-07-29 22:19:13 +0300
committerBonfaceKilz2020-07-29 23:03:17 +0300
commit3425e7a5dbf5a6983424659c05c258e7a132edf3 (patch)
treef03d98bfd7cc0b7032e37fc3eae2c94b46be9f25 /wqflask/tests
parentb55792f2daf648affe52d78c7f3a480f6550dfc8 (diff)
downloadgenenetwork2-3425e7a5dbf5a6983424659c05c258e7a132edf3.tar.gz
Add test for "get_groups"
* wqflask/tests/api/test_gen_menu.py: test that "get_groups" uses the correct sql query and returns the correct group data structure.
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/api/test_gen_menu.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/wqflask/tests/api/test_gen_menu.py b/wqflask/tests/api/test_gen_menu.py
index 81908129..a2a93da7 100644
--- a/wqflask/tests/api/test_gen_menu.py
+++ b/wqflask/tests/api/test_gen_menu.py
@@ -3,10 +3,28 @@ import unittest
import mock
from wqflask.api.gen_menu import get_species
+from wqflask.api.gen_menu import get_groups
+
class TestGenMenu(unittest.TestCase):
"""Tests for the gen_menu module"""
+ def setUp(self):
+ self.test_group = {
+ 'mouse': [
+ ['H_T1',
+ 'H_T',
+ 'Family:DescriptionA'
+ ],
+ ['H_T2', "H_T'", 'Family:None']
+ ],
+ 'human': [
+ ['BXD', 'BXD', 'Family:None'],
+ ['HLC', 'Liver: Normal Gene Expression with Genotypes (Merck)',
+ 'Family:Test']
+ ]
+ }
+
@mock.patch('wqflask.api.gen_menu.g')
def test_get_species(self, db_mock):
"""Test that assertion is raised when dataset and dataset_name are defined"""
@@ -17,3 +35,30 @@ class TestGenMenu(unittest.TestCase):
db_mock.db.execute.assert_called_once_with(
"SELECT Name, MenuName FROM Species ORDER BY OrderId"
)
+
+ @mock.patch('wqflask.api.gen_menu.g')
+ def test_get_groups(self, db_mock):
+ """Test that species groups are grouped correctly"""
+ db_mock.db.execute.return_value.fetchall.side_effect = [
+ # Mouse
+ (('BXD', 'BXD', None),
+ ('HLC', 'Liver: Normal Gene Expression with Genotypes (Merck)', 'Test')),
+ # Human
+ (('H_T1', "H_T", "DescriptionA"),
+ ('H_T2', "H_T'", None))
+ ]
+
+ self.assertEqual(get_groups([["human", "Human"], ["mouse", "Mouse"]]),
+ self.test_group)
+
+ for name in ["mouse", "human"]:
+ db_mock.db.execute.assert_any_call(
+ ("SELECT InbredSet.Name, InbredSet.FullName, " +
+ "IFNULL(InbredSet.Family, 'None') " +
+ "FROM InbredSet, Species WHERE Species.Name " +
+ "= '{}' AND InbredSet.SpeciesId = Species.Id GROUP by " +
+ "InbredSet.Name ORDER BY IFNULL(InbredSet.FamilyOrder, " +
+ "InbredSet.FullName) ASC, IFNULL(InbredSet.Family, " +
+ "InbredSet.FullName) ASC, InbredSet.FullName ASC, " +
+ "InbredSet.MenuOrderId ASC").format(name)
+ )