mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[FIX]
- problems with tests - pre-commit
This commit is contained in:
@@ -43,7 +43,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
if kwargs is None:
|
if kwargs is None:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
adapter = "%s_postgresql" % method_name
|
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:
|
if side_effect is not None:
|
||||||
adapter.side_effect = side_effect
|
adapter.side_effect = side_effect
|
||||||
elif return_value is not None:
|
elif return_value is not None:
|
||||||
@@ -67,14 +67,14 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
|
|
||||||
def test_connection_fail(self):
|
def test_connection_fail(self):
|
||||||
"""It should raise for failed/invalid connection"""
|
"""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
|
conn.side_effect = Exception
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.dbsource.connection_test()
|
self.dbsource.connection_test()
|
||||||
|
|
||||||
def test_connection_open_calls_close(self):
|
def test_connection_open_calls_close(self):
|
||||||
"""It should close connection after context ends"""
|
"""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():
|
with self.dbsource.connection_open():
|
||||||
pass
|
pass
|
||||||
close.assert_called_once()
|
close.assert_called_once()
|
||||||
@@ -121,7 +121,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
"""It should call the adapter method with proper args"""
|
"""It should call the adapter method with proper args"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
type(self.dbsource).current_table = "table"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_browse", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should raise AssertionError if a table not selected"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
|
type(self.dbsource).current_table = False
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_browse", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should call the adapter method with proper args"""
|
||||||
args = {"val": "Value"}, "args"
|
args = {"val": "Value"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
type(self.dbsource).current_table = "table"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_create", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should raise AssertionError if a table not selected"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
|
type(self.dbsource).current_table = False
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_create", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should call the adapter method with proper args"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
type(self.dbsource).current_table = "table"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_delete", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should raise AssertionError if a table not selected"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
|
type(self.dbsource).current_table = False
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_delete", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should call the adapter method with proper args"""
|
||||||
args = {"search": "query"}, "args"
|
args = {"search": "query"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
type(self.dbsource).current_table = "table"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_search", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should raise AssertionError if a table not selected"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
|
type(self.dbsource).current_table = False
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_search", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should call the adapter method with proper args"""
|
||||||
args = [1], {"vals": "Value"}, "args"
|
args = [1], {"vals": "Value"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
type(self.dbsource).current_table = "table"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_update", create=True, args=args, kwargs=kwargs
|
"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"""
|
"""It should raise AssertionError if a table not selected"""
|
||||||
args = [1], "args"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
|
type(self.dbsource).current_table = False
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
"remote_update", create=True, args=args, kwargs=kwargs
|
"remote_update", create=True, args=args, kwargs=kwargs
|
||||||
@@ -223,7 +228,8 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
"""It should call generic executor with proper args"""
|
"""It should call generic executor with proper args"""
|
||||||
expect = ("query", "execute", "metadata")
|
expect = ("query", "execute", "metadata")
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "_execute_generic", autospec=True
|
type(self.dbsource),
|
||||||
|
"_execute_generic",
|
||||||
) as execute:
|
) as execute:
|
||||||
execute.return_value = "rows", "cols"
|
execute.return_value = "rows", "cols"
|
||||||
self.dbsource.execute(*expect)
|
self.dbsource.execute(*expect)
|
||||||
@@ -235,7 +241,8 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
"""It should call the adapter correctly if old kwargs provided"""
|
"""It should call the adapter correctly if old kwargs provided"""
|
||||||
expect = [None, None, "metadata"]
|
expect = [None, None, "metadata"]
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "execute_postgresql", autospec=True
|
type(self.dbsource),
|
||||||
|
"execute_postgresql",
|
||||||
) as psql:
|
) as psql:
|
||||||
psql.return_value = "rows", "cols"
|
psql.return_value = "rows", "cols"
|
||||||
self.dbsource.execute(*expect, sqlparams="params", sqlquery="query")
|
self.dbsource.execute(*expect, sqlparams="params", sqlquery="query")
|
||||||
@@ -244,8 +251,6 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
|
|
||||||
def test_conn_open(self):
|
def test_conn_open(self):
|
||||||
"""It should return open connection for use"""
|
"""It should return open connection for use"""
|
||||||
with mock.patch.object(
|
with mock.patch.object(type(self.dbsource), "connection_open") as connection:
|
||||||
self.dbsource, "connection_open", autospec=True
|
|
||||||
) as connection:
|
|
||||||
res = self.dbsource.conn_open()
|
res = self.dbsource.conn_open()
|
||||||
self.assertEqual(res, connection().__enter__())
|
self.assertEqual(res, connection().__enter__())
|
||||||
|
|||||||
Reference in New Issue
Block a user