diff options
Diffstat (limited to 'wqflask/tests/base')
-rw-r--r-- | wqflask/tests/base/test_data_set.py | 69 | ||||
-rw-r--r-- | wqflask/tests/base/test_general_object.py | 9 | ||||
-rw-r--r-- | wqflask/tests/base/test_trait.py | 9 |
3 files changed, 63 insertions, 24 deletions
diff --git a/wqflask/tests/base/test_data_set.py b/wqflask/tests/base/test_data_set.py index dd7f5051..b1de4932 100644 --- a/wqflask/tests/base/test_data_set.py +++ b/wqflask/tests/base/test_data_set.py @@ -4,7 +4,7 @@ import unittest import mock from wqflask import app -from data import gen_menu_json +from .data import gen_menu_json from base.data_set import DatasetType @@ -59,9 +59,14 @@ class TestDataSetTypes(unittest.TestCase): self.assertEqual(data_set("BXDGeno"), "Geno") self.assertEqual(data_set("BXDPublish"), "Publish") self.assertEqual(data_set("HLC_0311"), "ProbeSet") + redis_mock.set.assert_called_once_with( "dataset_structure", - '{"BXDGeno": "Geno", "BXDPublish": "Publish", "HLCPublish": "Publish", "HLC_0311": "ProbeSet", "HC_M2_0606_P": "ProbeSet"}') + ('{"HLC_0311": "ProbeSet", ' + '"HLCPublish": "Publish", ' + '"BXDGeno": "Geno", ' + '"HC_M2_0606_P": "ProbeSet", ' + '"BXDPublish": "Publish"}')) @mock.patch('base.data_set.g') def test_set_dataset_key_mrna(self, db_mock): @@ -74,8 +79,17 @@ class TestDataSetTypes(unittest.TestCase): self.assertEqual(data_set("Test"), "ProbeSet") redis_mock.set.assert_called_once_with( "dataset_structure", - '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "ProbeSet", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}') - expected_db_call = """""" + ('{"AD-cases-controls-MyersGeno": "Geno", ' + '"AD-cases-controls-MyersPublish": "Publish", ' + '"AKXDGeno": "Geno", ' + '"AXBXAGeno": "Geno", ' + '"AXBXAPublish": "Publish", ' + '"Aging-Brain-UCIPublish": "Publish", ' + '"All Phenotypes": "Publish", ' + '"B139_K_1206_M": "ProbeSet", ' + '"B139_K_1206_R": "ProbeSet", ' + '"Test": "ProbeSet"}')) + db_mock.db.execute.assert_called_with( ("SELECT ProbeSetFreeze.Id FROM ProbeSetFreeze " + "WHERE ProbeSetFreeze.Name = \"Test\" ") @@ -92,12 +106,21 @@ class TestDataSetTypes(unittest.TestCase): self.assertEqual(data_set("Test"), "Publish") redis_mock.set.assert_called_once_with( "dataset_structure", - '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Publish", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}') + ('{"AD-cases-controls-MyersGeno": "Geno", ' + '"AD-cases-controls-MyersPublish": "Publish", ' + '"AKXDGeno": "Geno", ' + '"AXBXAGeno": "Geno", ' + '"AXBXAPublish": "Publish", ' + '"Aging-Brain-UCIPublish": "Publish", ' + '"All Phenotypes": "Publish", ' + '"B139_K_1206_M": "ProbeSet", ' + '"B139_K_1206_R": "ProbeSet", ' + '"Test": "Publish"}')) db_mock.db.execute.assert_called_with( - ("SELECT InfoFiles.GN_AccesionId " + - "FROM InfoFiles, PublishFreeze, InbredSet " + + ("SELECT InfoFiles.GN_AccesionId " + "FROM InfoFiles, PublishFreeze, InbredSet " "WHERE InbredSet.Name = 'Test' AND " - "PublishFreeze.InbredSetId = InbredSet.Id AND " + + "PublishFreeze.InbredSetId = InbredSet.Id AND " "InfoFiles.InfoPageName = PublishFreeze.Name") ) @@ -110,9 +133,20 @@ class TestDataSetTypes(unittest.TestCase): data_set = DatasetType(redis_mock) data_set.set_dataset_key("other_pheno", "Test") self.assertEqual(data_set("Test"), "Publish") + redis_mock.set.assert_called_once_with( "dataset_structure", - '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Publish", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}') + ('{"AD-cases-controls-MyersGeno": "Geno", ' + '"AD-cases-controls-MyersPublish": "Publish", ' + '"AKXDGeno": "Geno", ' + '"AXBXAGeno": "Geno", ' + '"AXBXAPublish": "Publish", ' + '"Aging-Brain-UCIPublish": "Publish", ' + '"All Phenotypes": "Publish", ' + '"B139_K_1206_M": "ProbeSet", ' + '"B139_K_1206_R": "ProbeSet", ' + '"Test": "Publish"}')) + db_mock.db.execute.assert_called_with( ("SELECT PublishFreeze.Name " + "FROM PublishFreeze, InbredSet " + @@ -131,8 +165,17 @@ class TestDataSetTypes(unittest.TestCase): self.assertEqual(data_set("Test"), "Geno") redis_mock.set.assert_called_once_with( "dataset_structure", - '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Geno", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}') - expected_db_call = """""" + ('{"AD-cases-controls-MyersGeno": "Geno", ' + '"AD-cases-controls-MyersPublish": "Publish", ' + '"AKXDGeno": "Geno", ' + '"AXBXAGeno": "Geno", ' + '"AXBXAPublish": "Publish", ' + '"Aging-Brain-UCIPublish": "Publish", ' + '"All Phenotypes": "Publish", ' + '"B139_K_1206_M": "ProbeSet", ' + '"B139_K_1206_R": "ProbeSet", ' + '"Test": "Geno"}')) + db_mock.db.execute.assert_called_with( - ("SELECT GenoFreeze.Id FROM GenoFreeze WHERE GenoFreeze.Name = \"Test\" ") - ) + ("SELECT GenoFreeze.Id FROM " + "GenoFreeze WHERE GenoFreeze.Name = \"Test\" ")) diff --git a/wqflask/tests/base/test_general_object.py b/wqflask/tests/base/test_general_object.py index c7701021..00fd3c72 100644 --- a/wqflask/tests/base/test_general_object.py +++ b/wqflask/tests/base/test_general_object.py @@ -17,9 +17,9 @@ class TestGeneralObjectTests(unittest.TestCase): def test_object_dict(self): """Test whether the base class is printed properly""" test_obj = GeneralObject("a", name="test", value=1) - self.assertEqual(str(test_obj), "value = 1\nname = test\n") + self.assertEqual(str(test_obj), "name = test\nvalue = 1\n") self.assertEqual( - repr(test_obj), "value = 1\nname = test\ncontents = ['a']\n") + repr(test_obj), "contents = ['a']\nname = test\nvalue = 1\n") self.assertEqual(len(test_obj), 2) self.assertEqual(test_obj["value"], 1) test_obj["test"] = 1 @@ -36,6 +36,5 @@ class TestGeneralObjectTests(unittest.TestCase): test_obj1 = GeneralObject("a", name="test", value=1) test_obj2 = GeneralObject("b", name="test2", value=2) test_obj3 = GeneralObject("a", name="test", x=1, y=2) - self.assertTrue(test_obj1 == test_obj2 ) - self.assertFalse(test_obj1 == test_obj3 ) - + self.assertTrue(test_obj1 == test_obj2) + self.assertFalse(test_obj1 == test_obj3) diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py index 960f2c81..9c3154f3 100644 --- a/wqflask/tests/base/test_trait.py +++ b/wqflask/tests/base/test_trait.py @@ -38,9 +38,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): dataset={}) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_with_empty_trait_info(self, - g_mock, requests_mock): """Empty trait info""" requests_mock.return_value = TestNilResponse() @@ -49,9 +48,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): dataset=mock.MagicMock()) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_with_non_empty_trait_info(self, - g_mock, requests_mock): """Test that attributes are set""" mock_dataset = mock.MagicMock() @@ -66,9 +64,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): self.assertEqual(test_trait.d, 4) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_utf8_parsing(self, - g_mock, requests_mock): """Test that utf-8 strings are parsed correctly""" utf_8_string = "test_string" |