aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorzsloan2020-07-28 12:51:54 -0500
committerzsloan2020-07-28 12:51:54 -0500
commit8e93afc7bcbb5bc12e43b0cdd2158894f633ae87 (patch)
treed1ba4c6a62023259679682f33e20bbc307955ab2 /wqflask/tests
parent92088d72ad284a664eb1a53127c13ca2e6b4f602 (diff)
parent40f761b5b1f4e5fe24dde4ace91065f1007c0aa1 (diff)
downloadgenenetwork2-8e93afc7bcbb5bc12e43b0cdd2158894f633ae87.tar.gz
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into testing
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/base/data.py110
-rw-r--r--wqflask/tests/base/test_data_set.py135
-rw-r--r--wqflask/tests/base/test_webqtl_case_data.py39
3 files changed, 269 insertions, 15 deletions
diff --git a/wqflask/tests/base/data.py b/wqflask/tests/base/data.py
new file mode 100644
index 00000000..06a5a989
--- /dev/null
+++ b/wqflask/tests/base/data.py
@@ -0,0 +1,110 @@
+gen_menu_json = """
+{
+ "datasets": {
+ "human": {
+ "HLC": {
+ "Liver mRNA": [
+ [
+ "320",
+ "HLC_0311",
+ "GSE9588 Human Liver Normal (Mar11) Both Sexes"
+ ]
+ ],
+ "Phenotypes": [
+ [
+ "635",
+ "HLCPublish",
+ "HLC Published Phenotypes"
+ ]
+ ]
+ }
+ },
+ "mouse": {
+ "BXD": {
+ "Genotypes": [
+ [
+ "600",
+ "BXDGeno",
+ "BXD Genotypes"
+ ]
+ ],
+ "Hippocampus mRNA": [
+ [
+ "112",
+ "HC_M2_0606_P",
+ "Hippocampus Consortium M430v2 (Jun06) PDNN"
+ ]
+ ],
+ "Phenotypes": [
+ [
+ "602",
+ "BXDPublish",
+ "BXD Published Phenotypes"
+ ]
+ ]
+ }
+ }
+ },
+ "groups": {
+ "human": [
+ [
+ "HLC",
+ "Liver: Normal Gene Expression with Genotypes (Merck)",
+ "Family:None"
+ ]
+ ],
+ "mouse": [
+ [
+ "BXD",
+ "BXD",
+ "Family:None"
+ ]
+ ]
+ },
+ "species": [
+ [
+ "human",
+ "Human"
+ ],
+ [
+ "mouse",
+ "Mouse"
+ ]
+ ],
+ "types": {
+ "human": {
+ "HLC": [
+ [
+ "Phenotypes",
+ "Traits and Cofactors",
+ "Phenotypes"
+ ],
+ [
+ "Liver mRNA",
+ "Liver mRNA",
+ "Molecular Trait Datasets"
+ ]
+ ]
+ },
+ "mouse": {
+ "BXD": [
+ [
+ "Phenotypes",
+ "Traits and Cofactors",
+ "Phenotypes"
+ ],
+ [
+ "Genotypes",
+ "DNA Markers and SNPs",
+ "Genotypes"
+ ],
+ [
+ "Hippocampus mRNA",
+ "Hippocampus mRNA",
+ "Molecular Trait Datasets"
+ ]
+ ]
+ }
+ }
+}
+"""
diff --git a/wqflask/tests/base/test_data_set.py b/wqflask/tests/base/test_data_set.py
index 44a54c7e..94780a5d 100644
--- a/wqflask/tests/base/test_data_set.py
+++ b/wqflask/tests/base/test_data_set.py
@@ -1,25 +1,18 @@
+"""Tests for wqflask/base/data_set.py"""
+
import unittest
import mock
from wqflask import app
-
+from data import gen_menu_json
from base.data_set import DatasetType
-
-class TestDataSetTypes(unittest.TestCase):
- def setUp(self):
- self.app_context = app.app_context()
- self.app_context.push()
- def tearDown(self):
- self.app_context.pop()
+class TestDataSetTypes(unittest.TestCase):
+ """Tests for the DataSetType class"""
- @mock.patch('base.data_set.g')
- def test_data_set_type(self, db_mock):
- with app.app_context():
- db_mock.get = mock.Mock()
- r = mock.Mock()
- r.get.return_value = """
+ def setUp(self):
+ self.test_dataset = """
{
"AD-cases-controls-MyersGeno": "Geno",
"AD-cases-controls-MyersPublish": "Publish",
@@ -32,4 +25,116 @@ class TestDataSetTypes(unittest.TestCase):
"B139_K_1206_R": "ProbeSet"
}
"""
- self.assertEqual(DatasetType(r)("All Phenotypes"), "Publish")
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
+ @mock.patch('base.data_set.g')
+ def test_data_set_type(self, db_mock):
+ """Test that DatasetType returns correctly if the Redis Instance is not empty
+ and the name variable exists in the dictionary
+
+ """
+ with app.app_context():
+ db_mock.get = mock.Mock()
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = self.test_dataset
+ self.assertEqual(DatasetType(redis_mock)
+ ("All Phenotypes"), "Publish")
+ redis_mock.get.assert_called_once_with("dataset_structure")
+
+ @mock.patch('base.data_set.requests.get')
+ def test_data_set_type_with_empty_redis(self, request_mock):
+ """Test that DatasetType returns correctly if the Redis Instance is empty and
+ the name variable exists in the dictionary
+
+ """
+ with app.app_context():
+ request_mock.return_value.content = gen_menu_json
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = None
+ data_set = DatasetType(redis_mock)
+ 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"}')
+
+ @mock.patch('base.data_set.g')
+ def test_set_dataset_key_mrna(self, db_mock):
+ with app.app_context():
+ db_mock.db.execute.return_value = [1, 2, 3]
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = self.test_dataset
+ data_set = DatasetType(redis_mock)
+ data_set.set_dataset_key("mrna_expr", "Test")
+ 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 = """"""
+ db_mock.db.execute.assert_called_with(
+ ("SELECT ProbeSetFreeze.Id FROM ProbeSetFreeze " +
+ "WHERE ProbeSetFreeze.Name = \"Test\" ")
+ )
+
+ @mock.patch('base.data_set.g')
+ def test_set_dataset_key_pheno(self, db_mock):
+ with app.app_context():
+ db_mock.db.execute.return_value = [1, 2, 3]
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = self.test_dataset
+ data_set = DatasetType(redis_mock)
+ data_set.set_dataset_key("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"}')
+ expected_db_call = """"""
+ db_mock.db.execute.assert_called_with(
+ ("SELECT InfoFiles.GN_AccesionId " +
+ "FROM InfoFiles, PublishFreeze, InbredSet " +
+ "WHERE InbredSet.Name = 'Test' AND "
+ "PublishFreeze.InbredSetId = InbredSet.Id AND " +
+ "InfoFiles.InfoPageName = PublishFreeze.Name")
+ )
+
+ @mock.patch('base.data_set.g')
+ def test_set_dataset_other_pheno(self, db_mock):
+ with app.app_context():
+ db_mock.db.execute.return_value = [1, 2, 3]
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = self.test_dataset
+ 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"}')
+ expected_db_call = """"""
+ db_mock.db.execute.assert_called_with(
+ ("SELECT PublishFreeze.Name " +
+ "FROM PublishFreeze, InbredSet " +
+ "WHERE InbredSet.Name = 'Test' AND "
+ "PublishFreeze.InbredSetId = InbredSet.Id")
+ )
+
+ @mock.patch('base.data_set.g')
+ def test_set_dataset_geno(self, db_mock):
+ with app.app_context():
+ db_mock.db.execute.return_value = [1, 2, 3]
+ redis_mock = mock.Mock()
+ redis_mock.get.return_value = self.test_dataset
+ data_set = DatasetType(redis_mock)
+ data_set.set_dataset_key("geno", "Test")
+ 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 = """"""
+ db_mock.db.execute.assert_called_with(
+ ("SELECT GenoFreeze.Id FROM GenoFreeze WHERE GenoFreeze.Name = \"Test\" ")
+ )
diff --git a/wqflask/tests/base/test_webqtl_case_data.py b/wqflask/tests/base/test_webqtl_case_data.py
new file mode 100644
index 00000000..8e8ba482
--- /dev/null
+++ b/wqflask/tests/base/test_webqtl_case_data.py
@@ -0,0 +1,39 @@
+"""Tests for wqflask/base/webqtlCaseData.py"""
+import unittest
+
+from wqflask import app # Required because of utility.tools in webqtlCaseData.py
+from base.webqtlCaseData import webqtlCaseData
+
+class TestWebqtlCaseData(unittest.TestCase):
+ """Tests for WebqtlCaseData class"""
+
+ def setUp(self):
+ self.w = webqtlCaseData(name="Test",
+ value=0,
+ variance=0.0,
+ num_cases=10,
+ name2="Test2")
+
+ def test_webqtl_case_data_repr(self):
+ self.assertEqual(
+ repr(self.w),
+ "<webqtlCaseData> value=0.000 variance=0.000 ndata=10 name=Test name2=Test2"
+ )
+
+ def test_class_outlier(self):
+ self.assertEqual(self.w.class_outlier, "")
+
+ def test_display_value(self):
+ self.assertEqual(self.w.display_value, "0.000")
+ self.w.value = None
+ self.assertEqual(self.w.display_value, "x")
+
+ def test_display_variance(self):
+ self.assertEqual(self.w.display_variance, "0.000")
+ self.w.variance = None
+ self.assertEqual(self.w.display_variance, "x")
+
+ def test_display_num_cases(self):
+ self.assertEqual(self.w.display_num_cases, "10")
+ self.w.num_cases = None
+ self.assertEqual(self.w.display_num_cases, "x")