diff options
author | Frederick Muriuki Muriithi | 2023-03-23 18:41:38 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-03-23 18:41:38 +0300 |
commit | 98e9726405df3cce81356534335259a446b0c458 (patch) | |
tree | d9f31fec832f0fdd2750bd9c26d84b54413d1adb /tests/unit/test_db_utils.py | |
parent | 6630f9fca98826872a62651c89f95eecb7c8a898 (diff) | |
download | genenetwork3-98e9726405df3cce81356534335259a446b0c458.tar.gz |
tests: Set up fixture and mock out config variable
Diffstat (limited to 'tests/unit/test_db_utils.py')
-rw-r--r-- | tests/unit/test_db_utils.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/tests/unit/test_db_utils.py b/tests/unit/test_db_utils.py index 68f80a0..a319692 100644 --- a/tests/unit/test_db_utils.py +++ b/tests/unit/test_db_utils.py @@ -6,9 +6,14 @@ from types import SimpleNamespace import pytest +import gn3 from gn3.db_utils import database_connector from gn3.db_utils import parse_db_url +@pytest.fixture(scope="class") +def setup_app(request, fxtr_app): + """Setup the fixtures for the class.""" + request.cls.app = fxtr_app class TestDatabase(TestCase): """class contains testd for db connection functions""" @@ -31,10 +36,14 @@ class TestDatabase(TestCase): results, SimpleNamespace, "database not created successfully") @pytest.mark.unit_test - @mock.patch("gn3.db_utils.SQL_URI", - "mysql://username:4321@localhost/test") + @pytest.mark.usefixtures("setup_app") def test_parse_db_url(self): """test for parsing db_uri env variable""" - results = parse_db_url() - expected_results = ("localhost", "username", "4321", "test", None) - self.assertEqual(results, expected_results) + print(self.__dict__) + with self.app.app_context(), mock.patch.dict(# pylint: disable=[no-member] + gn3.db_utils.current_app.config, + {"SQL_URI": "mysql://username:4321@localhost/test"}, + clear=True): + results = parse_db_url() + expected_results = ("localhost", "username", "4321", "test", None) + self.assertEqual(results, expected_results) |