diff options
author | Munyoki Kilyungi | 2022-12-01 19:18:15 +0300 |
---|---|---|
committer | zsloan | 2022-12-01 15:11:13 -0600 |
commit | 0d399493056c9c4618141fcb385dd3daf32b8d42 (patch) | |
tree | 17ceaf508e1a1afe67356344ec5f086b56b4682f /wqflask/tests | |
parent | 96a1652c8359a1215d8ad330ac05d19b1f6d98a3 (diff) | |
download | genenetwork2-0d399493056c9c4618141fcb385dd3daf32b8d42.tar.gz |
Reproduce ValueError when query_sql returns None
* wqflask/tests/unit/base/test_data_set.py (TestDatasetAccessionId):
New test cases.
Diffstat (limited to 'wqflask/tests')
-rw-r--r-- | wqflask/tests/unit/base/test_data_set.py | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/wqflask/tests/unit/base/test_data_set.py b/wqflask/tests/unit/base/test_data_set.py index 5e6068f9..744c8a94 100644 --- a/wqflask/tests/unit/base/test_data_set.py +++ b/wqflask/tests/unit/base/test_data_set.py @@ -2,10 +2,12 @@ import unittest from unittest import mock +from dataclasses import dataclass +from gn3.monads import MonadicDict from wqflask import app from base.data_set import DatasetType - +from base.data_set.dataset import DataSet GEN_MENU_JSON = """ { @@ -118,6 +120,22 @@ GEN_MENU_JSON = """ } """ +class MockPhenotypeDataset(DataSet): + def setup(self): + self.type = "Publish" + self.query_for_group = "" + self.group = "" + + + def check_confidentiality(self): + pass + + def retrieve_other_names(self): + pass + +@dataclass +class MockGroup: + name = "Group" class TestDataSetTypes(unittest.TestCase): """Tests for the DataSetType class""" @@ -182,3 +200,39 @@ class TestDataSetTypes(unittest.TestCase): '"HC_M2_0606_P": "ProbeSet", ' '"BXDPublish": "Publish"}')) + +class TestDatasetAccessionId(unittest.TestCase): + """Tests for the DataSetType class""" + + @mock.patch("base.data_set.dataset.query_sql") + @mock.patch("base.data_set.dataset.DatasetGroup") + def test_get_accession_id(self, mock_dataset_group, mock_query_sql): + def mock_fn(): + yield MonadicDict({"accession_id": 7}) + mock_dataset_group.return_value = MockGroup() + mock_query_sql.return_value = mock_fn() + sample_dataset = MockPhenotypeDataset( + name="BXD-LongevityPublish", + get_samplelist=False, + group_name="BXD", + redis_conn=mock.Mock() + ) + sample_dataset\ + .accession_id\ + .bind(lambda x: self.assertEqual(7, x)) + + @mock.patch("base.data_set.dataset.query_sql") + @mock.patch("base.data_set.dataset.DatasetGroup") + def test_get_accession_id_empty_return(self, mock_dataset_group, + mock_query_sql): + mock_dataset_group.return_value = MockGroup() + mock_query_sql.return_value = None + sample_dataset = MockPhenotypeDataset( + name="BXD-LongevityPublish", + get_samplelist=False, + group_name="BXD", + redis_conn=mock.Mock() + ) + sample_dataset\ + .accession_id\ + .bind(lambda x: self.assertNone(x)) |