aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/unit/base
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-09-05 15:20:52 +0300
committerBonfaceKilz2022-09-08 14:26:19 +0300
commitea9315da2333fc327616f94093e2603b8532e53a (patch)
tree9d0c619ed0112774a26801203ab04fab9083a223 /wqflask/tests/unit/base
parent4a3b8a0bbd7365eb56a77f6cb6252aaf799d5ecc (diff)
downloadgenenetwork2-ea9315da2333fc327616f94093e2603b8532e53a.tar.gz
Replace "g.db" mocks with "database_connection" mocks
* wqflask/tests/unit/base/test_trait.py: Delete "wqflask.app" import. (TestRetrieveTraitInfo.setUp): Delete it. (TestRetrieveTraitInfo.tearDown): Ditto. (TestRetrieveTraitInfo.test_retrieve_trait_info_with_empty_dataset): Replace "g" mock with "database_connection" mock. (test_retrieve_trait_info_with_empty_trait_info): Ditto. (test_retrieve_trait_info_with_non_empty_trait_info): Ditto. (test_retrieve_trait_info_utf8_parsing): Ditto. * wqflask/tests/wqflask/show_trait/test_show_trait.py (TestTraits): (test_get_nearest_marker): Ditto. (test_get_nearest_marker_empty_db): Ditto.
Diffstat (limited to 'wqflask/tests/unit/base')
-rw-r--r--wqflask/tests/unit/base/test_trait.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/wqflask/tests/unit/base/test_trait.py b/wqflask/tests/unit/base/test_trait.py
index 71fe0a44..e8c01ca9 100644
--- a/wqflask/tests/unit/base/test_trait.py
+++ b/wqflask/tests/unit/base/test_trait.py
@@ -3,7 +3,6 @@
import unittest
from unittest import mock
-from wqflask import app
from base.trait import GeneralTrait
from base.trait import retrieve_trait_info
@@ -32,25 +31,24 @@ class MockTrait(GeneralTrait):
class TestRetrieveTraitInfo(unittest.TestCase):
"""Tests for 'retrieve_trait_info'"""
-
- def setUp(self):
- self.app_context = app.app_context()
- self.app_context.push()
-
- def tearDown(self):
- self.app_context.pop()
-
- def test_retrieve_trait_info_with_empty_dataset(self):
+ @mock.patch('base.trait.database_connection')
+ def test_retrieve_trait_info_with_empty_dataset(self, mock_db):
"""Test that an exception is raised when dataset is empty"""
- with self.assertRaises(AssertionError):
+ conn = mock.MagicMock()
+ mock_db.return_value.__enter__.return_value = conn
+ with self.assertRaises(ValueError):
retrieve_trait_info(trait=mock.MagicMock(),
dataset={})
@mock.patch('base.trait.requests.get')
@mock.patch('base.trait.g', mock.Mock())
+ @mock.patch('base.trait.database_connection')
def test_retrieve_trait_info_with_empty_trait_info(self,
+ mock_db,
requests_mock):
"""Empty trait info"""
+ conn = mock.MagicMock()
+ mock_db.return_value.__enter__.return_value = conn
requests_mock.return_value = TestNilResponse()
with self.assertRaises(KeyError):
retrieve_trait_info(trait=mock.MagicMock(),
@@ -58,10 +56,14 @@ class TestRetrieveTraitInfo(unittest.TestCase):
@mock.patch('base.trait.requests.get')
@mock.patch('base.trait.g', mock.Mock())
+ @mock.patch('base.trait.database_connection')
def test_retrieve_trait_info_with_non_empty_trait_info(self,
+ mock_db,
requests_mock):
"""Test that attributes are set"""
mock_dataset = mock.MagicMock()
+ conn = mock.MagicMock()
+ mock_db.return_value.__enter__.return_value = conn
requests_mock.return_value = TestResponse()
type(mock_dataset).display_fields = mock.PropertyMock(
return_value=["a", "b", "c", "d"])
@@ -74,10 +76,14 @@ class TestRetrieveTraitInfo(unittest.TestCase):
@mock.patch('base.trait.requests.get')
@mock.patch('base.trait.g', mock.Mock())
+ @mock.patch('base.trait.database_connection')
def test_retrieve_trait_info_utf8_parsing(self,
+ mock_db,
requests_mock):
"""Test that utf-8 strings are parsed correctly"""
utf_8_string = "test_string"
+ conn = mock.MagicMock()
+ mock_db.return_value.__enter__.return_value = conn
mock_dataset = mock.MagicMock()
requests_mock.return_value = TestResponse()
type(mock_dataset).display_fields = mock.PropertyMock(