mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] update pre-commit
This commit is contained in:
@@ -53,7 +53,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
return res, adapter
|
||||
|
||||
def test_conn_string_full(self):
|
||||
""" It should add password if string interpolation not detected """
|
||||
"""It should add password if string interpolation not detected"""
|
||||
self.dbsource.conn_string = "User=Derp;"
|
||||
self.dbsource.password = "password"
|
||||
expect = self.dbsource.conn_string + "PWD=%s;" % self.dbsource.password
|
||||
@@ -62,37 +62,37 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
# Interface
|
||||
|
||||
def test_connection_success(self):
|
||||
""" It should raise for successful connection """
|
||||
"""It should raise for successful connection"""
|
||||
with self.assertRaises(ConnectionSuccessError):
|
||||
self.dbsource.connection_test()
|
||||
|
||||
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:
|
||||
conn.side_effect = Exception
|
||||
with self.assertRaises(ConnectionFailedError):
|
||||
self.dbsource.connection_test()
|
||||
|
||||
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 self.dbsource.connection_open():
|
||||
pass
|
||||
close.assert_called_once()
|
||||
|
||||
def test_connection_close(self):
|
||||
""" It should call adapter's close method """
|
||||
"""It should call adapter's close method"""
|
||||
args = [mock.MagicMock()]
|
||||
res, adapter = self._test_adapter_method("connection_close", args=args)
|
||||
adapter.assert_called_once_with(args[0])
|
||||
|
||||
def test_execute_asserts_query_arg(self):
|
||||
""" It should raise a TypeError if query and sqlquery not in args """
|
||||
"""It should raise a TypeError if query and sqlquery not in args"""
|
||||
with self.assertRaises(TypeError):
|
||||
self.dbsource.execute()
|
||||
|
||||
def test_execute_calls_adapter(self):
|
||||
""" It should call the adapter methods with proper args """
|
||||
"""It should call the adapter methods with proper args"""
|
||||
expect = ("query", "execute", "metadata")
|
||||
return_value = "rows", "cols"
|
||||
res, adapter = self._test_adapter_method(
|
||||
@@ -101,7 +101,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
adapter.assert_called_once_with(*expect)
|
||||
|
||||
def test_execute_return(self):
|
||||
""" It should return rows if not metadata """
|
||||
"""It should return rows if not metadata"""
|
||||
expect = (True, True, False)
|
||||
return_value = "rows", "cols"
|
||||
res, adapter = self._test_adapter_method(
|
||||
@@ -110,7 +110,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, return_value[0])
|
||||
|
||||
def test_execute_return_metadata(self):
|
||||
""" It should return rows and cols if metadata """
|
||||
"""It should return rows and cols if metadata"""
|
||||
expect = (True, True, True)
|
||||
return_value = "rows", "cols"
|
||||
res, adapter = self._test_adapter_method(
|
||||
@@ -119,7 +119,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, {"rows": return_value[0], "cols": return_value[1]})
|
||||
|
||||
def test_remote_browse(self):
|
||||
""" It should call the adapter method with proper args """
|
||||
"""It should call the adapter method with proper args"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
self.dbsource.current_table = "table"
|
||||
@@ -130,7 +130,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, adapter())
|
||||
|
||||
def test_remote_browse_asserts_current_table(self):
|
||||
""" It should raise AssertionError if a table not selected """
|
||||
"""It should raise AssertionError if a table not selected"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
with self.assertRaises(AssertionError):
|
||||
@@ -139,7 +139,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
)
|
||||
|
||||
def test_remote_create(self):
|
||||
""" It should call the adapter method with proper args """
|
||||
"""It should call the adapter method with proper args"""
|
||||
args = {"val": "Value"}, "args"
|
||||
kwargs = {"kwargs": True}
|
||||
self.dbsource.current_table = "table"
|
||||
@@ -150,7 +150,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, adapter())
|
||||
|
||||
def test_remote_create_asserts_current_table(self):
|
||||
""" It should raise AssertionError if a table not selected """
|
||||
"""It should raise AssertionError if a table not selected"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
with self.assertRaises(AssertionError):
|
||||
@@ -159,7 +159,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
)
|
||||
|
||||
def test_remote_delete(self):
|
||||
""" It should call the adapter method with proper args """
|
||||
"""It should call the adapter method with proper args"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
self.dbsource.current_table = "table"
|
||||
@@ -170,7 +170,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, adapter())
|
||||
|
||||
def test_remote_delete_asserts_current_table(self):
|
||||
""" It should raise AssertionError if a table not selected """
|
||||
"""It should raise AssertionError if a table not selected"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
with self.assertRaises(AssertionError):
|
||||
@@ -179,7 +179,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
)
|
||||
|
||||
def test_remote_search(self):
|
||||
""" It should call the adapter method with proper args """
|
||||
"""It should call the adapter method with proper args"""
|
||||
args = {"search": "query"}, "args"
|
||||
kwargs = {"kwargs": True}
|
||||
self.dbsource.current_table = "table"
|
||||
@@ -190,7 +190,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, adapter())
|
||||
|
||||
def test_remote_search_asserts_current_table(self):
|
||||
""" It should raise AssertionError if a table not selected """
|
||||
"""It should raise AssertionError if a table not selected"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
with self.assertRaises(AssertionError):
|
||||
@@ -199,7 +199,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
)
|
||||
|
||||
def test_remote_update(self):
|
||||
""" It should call the adapter method with proper args """
|
||||
"""It should call the adapter method with proper args"""
|
||||
args = [1], {"vals": "Value"}, "args"
|
||||
kwargs = {"kwargs": True}
|
||||
self.dbsource.current_table = "table"
|
||||
@@ -210,7 +210,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
self.assertEqual(res, adapter())
|
||||
|
||||
def test_remote_update_asserts_current_table(self):
|
||||
""" It should raise AssertionError if a table not selected """
|
||||
"""It should raise AssertionError if a table not selected"""
|
||||
args = [1], "args"
|
||||
kwargs = {"kwargs": True}
|
||||
with self.assertRaises(AssertionError):
|
||||
@@ -221,7 +221,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
# Postgres
|
||||
|
||||
def test_execute_postgresql(self):
|
||||
""" It should call generic executor with proper args """
|
||||
"""It should call generic executor with proper args"""
|
||||
expect = ("query", "execute", "metadata")
|
||||
with mock.patch.object(
|
||||
self.dbsource, "_execute_generic", autospec=True
|
||||
@@ -233,7 +233,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
# Old API Compat
|
||||
|
||||
def test_execute_calls_adapter_old_api(self):
|
||||
""" It should call the adapter correctly if old kwargs provided """
|
||||
"""It should call the adapter correctly if old kwargs provided"""
|
||||
expect = [None, None, "metadata"]
|
||||
with mock.patch.object(
|
||||
self.dbsource, "execute_postgresql", autospec=True
|
||||
@@ -244,7 +244,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
psql.assert_called_once_with(*expect)
|
||||
|
||||
def test_conn_open(self):
|
||||
""" It should return open connection for use """
|
||||
"""It should return open connection for use"""
|
||||
with mock.patch.object(
|
||||
self.dbsource, "connection_open", autospec=True
|
||||
) as connection:
|
||||
|
||||
Reference in New Issue
Block a user