aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_db_utils.py
diff options
context:
space:
mode:
authorAlexander Kabui2021-04-12 09:54:12 +0300
committerGitHub2021-04-12 09:54:12 +0300
commit31ac939f58bf7b6d353ced995ca395376203b25f (patch)
tree41770a0e4ec3441045fca9bc48de794e444b80ba /tests/unit/test_db_utils.py
parent5151987063eab58b10a2dd8e831ec036df217531 (diff)
downloadgenenetwork3-31ac939f58bf7b6d353ced995ca395376203b25f.tar.gz
Integrate correlation API
- add new api for gn2-gn3 sample r integration - delete map for sample list to values - add db util file - add python msql-client dependency - add db for fetching lit correlation results - add unittests for db utils - add tests for db_utils - modify api for fetching lit correlation results - refactor Mock Database Connector and unittests - add sql url parser - add SQL URI env variable - refactor code for db utils - modify return data for lit correlation - refactor tissue correlation endpoint - replace db_instance with conn
Diffstat (limited to 'tests/unit/test_db_utils.py')
-rw-r--r--tests/unit/test_db_utils.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/unit/test_db_utils.py b/tests/unit/test_db_utils.py
new file mode 100644
index 0000000..0f2de9e
--- /dev/null
+++ b/tests/unit/test_db_utils.py
@@ -0,0 +1,37 @@
+"""module contains test for db_utils"""
+
+from unittest import TestCase
+from unittest import mock
+
+from types import SimpleNamespace
+
+from gn3.db_utils import database_connector
+from gn3.db_utils import parse_db_url
+
+
+class TestDatabase(TestCase):
+ """class contains testd for db connection functions"""
+
+ @mock.patch("gn3.db_utils.mdb")
+ @mock.patch("gn3.db_utils.parse_db_url")
+ def test_database_connector(self, mock_db_parser, mock_sql):
+ """test for creating database connection"""
+ mock_db_parser.return_value = ("localhost", "guest", "4321", "users")
+ callable_cursor = lambda: SimpleNamespace(execute=3)
+ cursor_object = SimpleNamespace(cursor=callable_cursor)
+ mock_sql.connect.return_value = cursor_object
+ mock_sql.close.return_value = None
+ results = database_connector()
+
+ mock_sql.connect.assert_called_with(
+ "localhost", "guest", "4321", "users")
+ self.assertIsInstance(
+ results, tuple, "database not created successfully")
+
+ @mock.patch("gn3.db_utils.SQL_URI",
+ "mysql://username:4321@localhost/test")
+ def test_parse_db_url(self):
+ """test for parsing db_uri env variable"""
+ results = parse_db_url()
+ expected_results = ("localhost", "username", "4321", "test")
+ self.assertEqual(results, expected_results)