- problems with tests
 - pre-commit
This commit is contained in:
bilbonet
2022-08-17 15:56:59 +02:00
parent d9cd2cc774
commit 4ba29febee
2 changed files with 41 additions and 36 deletions

View File

@@ -43,7 +43,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
if kwargs is None:
kwargs = {}
adapter = "%s_postgresql" % method_name
with mock.patch.object(self.dbsource, adapter, create=create) as adapter:
with mock.patch.object(type(self.dbsource), adapter, create=create) as adapter:
if side_effect is not None:
adapter.side_effect = side_effect
elif return_value is not None:
@@ -67,14 +67,14 @@ class TestBaseExternalDbsource(common.TransactionCase):
def test_connection_fail(self):
"""It should raise for failed/invalid connection"""
with mock.patch.object(self.dbsource, "connection_open") as conn:
with mock.patch.object(type(self.dbsource), "connection_open") as conn:
conn.side_effect = Exception
with self.assertRaises(ValidationError):
self.dbsource.connection_test()
def test_connection_open_calls_close(self):
"""It should close connection after context ends"""
with mock.patch.object(self.dbsource, "connection_close") as close:
with mock.patch.object(type(self.dbsource), "connection_close") as close:
with self.dbsource.connection_open():
pass
close.assert_called_once()
@@ -121,7 +121,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter method with proper args"""
args = [1], "args"
kwargs = {"kwargs": True}
self.dbsource.current_table = "table"
type(self.dbsource).current_table = "table"
res, adapter = self._test_adapter_method(
"remote_browse", create=True, args=args, kwargs=kwargs
)
@@ -132,6 +132,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should raise AssertionError if a table not selected"""
args = [1], "args"
kwargs = {"kwargs": True}
type(self.dbsource).current_table = False
with self.assertRaises(AssertionError):
res, adapter = self._test_adapter_method(
"remote_browse", create=True, args=args, kwargs=kwargs
@@ -141,7 +142,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter method with proper args"""
args = {"val": "Value"}, "args"
kwargs = {"kwargs": True}
self.dbsource.current_table = "table"
type(self.dbsource).current_table = "table"
res, adapter = self._test_adapter_method(
"remote_create", create=True, args=args, kwargs=kwargs
)
@@ -152,6 +153,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should raise AssertionError if a table not selected"""
args = [1], "args"
kwargs = {"kwargs": True}
type(self.dbsource).current_table = False
with self.assertRaises(AssertionError):
res, adapter = self._test_adapter_method(
"remote_create", create=True, args=args, kwargs=kwargs
@@ -161,7 +163,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter method with proper args"""
args = [1], "args"
kwargs = {"kwargs": True}
self.dbsource.current_table = "table"
type(self.dbsource).current_table = "table"
res, adapter = self._test_adapter_method(
"remote_delete", create=True, args=args, kwargs=kwargs
)
@@ -172,6 +174,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should raise AssertionError if a table not selected"""
args = [1], "args"
kwargs = {"kwargs": True}
type(self.dbsource).current_table = False
with self.assertRaises(AssertionError):
res, adapter = self._test_adapter_method(
"remote_delete", create=True, args=args, kwargs=kwargs
@@ -181,7 +184,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter method with proper args"""
args = {"search": "query"}, "args"
kwargs = {"kwargs": True}
self.dbsource.current_table = "table"
type(self.dbsource).current_table = "table"
res, adapter = self._test_adapter_method(
"remote_search", create=True, args=args, kwargs=kwargs
)
@@ -192,6 +195,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should raise AssertionError if a table not selected"""
args = [1], "args"
kwargs = {"kwargs": True}
type(self.dbsource).current_table = False
with self.assertRaises(AssertionError):
res, adapter = self._test_adapter_method(
"remote_search", create=True, args=args, kwargs=kwargs
@@ -201,7 +205,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter method with proper args"""
args = [1], {"vals": "Value"}, "args"
kwargs = {"kwargs": True}
self.dbsource.current_table = "table"
type(self.dbsource).current_table = "table"
res, adapter = self._test_adapter_method(
"remote_update", create=True, args=args, kwargs=kwargs
)
@@ -212,6 +216,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should raise AssertionError if a table not selected"""
args = [1], "args"
kwargs = {"kwargs": True}
type(self.dbsource).current_table = False
with self.assertRaises(AssertionError):
res, adapter = self._test_adapter_method(
"remote_update", create=True, args=args, kwargs=kwargs
@@ -223,7 +228,8 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call generic executor with proper args"""
expect = ("query", "execute", "metadata")
with mock.patch.object(
self.dbsource, "_execute_generic", autospec=True
type(self.dbsource),
"_execute_generic",
) as execute:
execute.return_value = "rows", "cols"
self.dbsource.execute(*expect)
@@ -235,7 +241,8 @@ class TestBaseExternalDbsource(common.TransactionCase):
"""It should call the adapter correctly if old kwargs provided"""
expect = [None, None, "metadata"]
with mock.patch.object(
self.dbsource, "execute_postgresql", autospec=True
type(self.dbsource),
"execute_postgresql",
) as psql:
psql.return_value = "rows", "cols"
self.dbsource.execute(*expect, sqlparams="params", sqlquery="query")
@@ -244,8 +251,6 @@ class TestBaseExternalDbsource(common.TransactionCase):
def test_conn_open(self):
"""It should return open connection for use"""
with mock.patch.object(
self.dbsource, "connection_open", autospec=True
) as connection:
with mock.patch.object(type(self.dbsource), "connection_open") as connection:
res = self.dbsource.conn_open()
self.assertEqual(res, connection().__enter__())