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:
@@ -15,7 +15,7 @@ _logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class BaseExternalDbsource(models.Model):
|
class BaseExternalDbsource(models.Model):
|
||||||
""" It provides logic for connection to an external data source
|
"""It provides logic for connection to an external data source
|
||||||
|
|
||||||
Classes implementing this interface must provide the following methods
|
Classes implementing this interface must provide the following methods
|
||||||
suffixed with the adapter type. See the method definitions and examples
|
suffixed with the adapter type. See the method definitions and examples
|
||||||
@@ -96,11 +96,11 @@ class BaseExternalDbsource(models.Model):
|
|||||||
# Interface
|
# Interface
|
||||||
|
|
||||||
def change_table(self, name):
|
def change_table(self, name):
|
||||||
""" Change the table that is used for CRUD operations """
|
"""Change the table that is used for CRUD operations"""
|
||||||
self.current_table = name
|
self.current_table = name
|
||||||
|
|
||||||
def connection_close(self, connection):
|
def connection_close(self, connection):
|
||||||
""" It closes the connection to the data source.
|
"""It closes the connection to the data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -111,7 +111,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def connection_open(self):
|
def connection_open(self):
|
||||||
""" It provides a context manager for the data source.
|
"""It provides a context manager for the data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -128,7 +128,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
_logger.exception("Connection close failure.")
|
_logger.exception("Connection close failure.")
|
||||||
|
|
||||||
def execute(self, query=None, execute_params=None, metadata=False, **kwargs):
|
def execute(self, query=None, execute_params=None, metadata=False, **kwargs):
|
||||||
""" Executes a query and returns a list of rows.
|
"""Executes a query and returns a list of rows.
|
||||||
|
|
||||||
"execute_params" can be a dict of values, that can be referenced
|
"execute_params" can be a dict of values, that can be referenced
|
||||||
in the SQL statement using "%(key)s" or, in the case of Oracle,
|
in the SQL statement using "%(key)s" or, in the case of Oracle,
|
||||||
@@ -168,7 +168,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
def connection_test(self):
|
def connection_test(self):
|
||||||
""" It tests the connection
|
"""It tests the connection
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ConnectionSuccessError: On connection success
|
ConnectionSuccessError: On connection success
|
||||||
@@ -187,7 +187,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def remote_browse(self, record_ids, *args, **kwargs):
|
def remote_browse(self, record_ids, *args, **kwargs):
|
||||||
""" It browses for and returns the records from remote by ID
|
"""It browses for and returns the records from remote by ID
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -205,7 +205,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(record_ids, *args, **kwargs)
|
return method(record_ids, *args, **kwargs)
|
||||||
|
|
||||||
def remote_create(self, vals, *args, **kwargs):
|
def remote_create(self, vals, *args, **kwargs):
|
||||||
""" It creates a record on the remote data source.
|
"""It creates a record on the remote data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -223,7 +223,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(vals, *args, **kwargs)
|
return method(vals, *args, **kwargs)
|
||||||
|
|
||||||
def remote_delete(self, record_ids, *args, **kwargs):
|
def remote_delete(self, record_ids, *args, **kwargs):
|
||||||
""" It deletes records by ID on remote
|
"""It deletes records by ID on remote
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -241,7 +241,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(record_ids, *args, **kwargs)
|
return method(record_ids, *args, **kwargs)
|
||||||
|
|
||||||
def remote_search(self, query, *args, **kwargs):
|
def remote_search(self, query, *args, **kwargs):
|
||||||
""" It searches the remote for the query.
|
"""It searches the remote for the query.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -259,7 +259,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(query, *args, **kwargs)
|
return method(query, *args, **kwargs)
|
||||||
|
|
||||||
def remote_update(self, record_ids, vals, *args, **kwargs):
|
def remote_update(self, record_ids, vals, *args, **kwargs):
|
||||||
""" It updates the remote records with the vals
|
"""It updates the remote records with the vals
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -300,7 +300,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
# Compatibility & Private
|
# Compatibility & Private
|
||||||
|
|
||||||
def conn_open(self):
|
def conn_open(self):
|
||||||
""" It opens and returns a connection to the remote data source.
|
"""It opens and returns a connection to the remote data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -313,7 +313,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return connection
|
return connection
|
||||||
|
|
||||||
def _get_adapter_method(self, method_prefix):
|
def _get_adapter_method(self, method_prefix):
|
||||||
""" It returns the connector adapter method for ``method_prefix``.
|
"""It returns the connector adapter method for ``method_prefix``.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
method_prefix: (str) Prefix of adapter method (such as
|
method_prefix: (str) Prefix of adapter method (such as
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
return res, adapter
|
return res, adapter
|
||||||
|
|
||||||
def test_conn_string_full(self):
|
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.conn_string = "User=Derp;"
|
||||||
self.dbsource.password = "password"
|
self.dbsource.password = "password"
|
||||||
expect = self.dbsource.conn_string + "PWD=%s;" % self.dbsource.password
|
expect = self.dbsource.conn_string + "PWD=%s;" % self.dbsource.password
|
||||||
@@ -62,37 +62,37 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
# Interface
|
# Interface
|
||||||
|
|
||||||
def test_connection_success(self):
|
def test_connection_success(self):
|
||||||
""" It should raise for successful connection """
|
"""It should raise for successful connection"""
|
||||||
with self.assertRaises(ConnectionSuccessError):
|
with self.assertRaises(ConnectionSuccessError):
|
||||||
self.dbsource.connection_test()
|
self.dbsource.connection_test()
|
||||||
|
|
||||||
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(self.dbsource, "connection_open") as conn:
|
||||||
conn.side_effect = Exception
|
conn.side_effect = Exception
|
||||||
with self.assertRaises(ConnectionFailedError):
|
with self.assertRaises(ConnectionFailedError):
|
||||||
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(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()
|
||||||
|
|
||||||
def test_connection_close(self):
|
def test_connection_close(self):
|
||||||
""" It should call adapter's close method """
|
"""It should call adapter's close method"""
|
||||||
args = [mock.MagicMock()]
|
args = [mock.MagicMock()]
|
||||||
res, adapter = self._test_adapter_method("connection_close", args=args)
|
res, adapter = self._test_adapter_method("connection_close", args=args)
|
||||||
adapter.assert_called_once_with(args[0])
|
adapter.assert_called_once_with(args[0])
|
||||||
|
|
||||||
def test_execute_asserts_query_arg(self):
|
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):
|
with self.assertRaises(TypeError):
|
||||||
self.dbsource.execute()
|
self.dbsource.execute()
|
||||||
|
|
||||||
def test_execute_calls_adapter(self):
|
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")
|
expect = ("query", "execute", "metadata")
|
||||||
return_value = "rows", "cols"
|
return_value = "rows", "cols"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
@@ -101,7 +101,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
adapter.assert_called_once_with(*expect)
|
adapter.assert_called_once_with(*expect)
|
||||||
|
|
||||||
def test_execute_return(self):
|
def test_execute_return(self):
|
||||||
""" It should return rows if not metadata """
|
"""It should return rows if not metadata"""
|
||||||
expect = (True, True, False)
|
expect = (True, True, False)
|
||||||
return_value = "rows", "cols"
|
return_value = "rows", "cols"
|
||||||
res, adapter = self._test_adapter_method(
|
res, adapter = self._test_adapter_method(
|
||||||
@@ -110,7 +110,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, return_value[0])
|
self.assertEqual(res, return_value[0])
|
||||||
|
|
||||||
def test_execute_return_metadata(self):
|
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)
|
expect = (True, True, True)
|
||||||
return_value = "rows", "cols"
|
return_value = "rows", "cols"
|
||||||
res, adapter = self._test_adapter_method(
|
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]})
|
self.assertEqual(res, {"rows": return_value[0], "cols": return_value[1]})
|
||||||
|
|
||||||
def test_remote_browse(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
self.dbsource.current_table = "table"
|
||||||
@@ -130,7 +130,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, adapter())
|
self.assertEqual(res, adapter())
|
||||||
|
|
||||||
def test_remote_browse_asserts_current_table(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
@@ -139,7 +139,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_remote_create(self):
|
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"
|
args = {"val": "Value"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
self.dbsource.current_table = "table"
|
||||||
@@ -150,7 +150,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, adapter())
|
self.assertEqual(res, adapter())
|
||||||
|
|
||||||
def test_remote_create_asserts_current_table(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
@@ -159,7 +159,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_remote_delete(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
self.dbsource.current_table = "table"
|
||||||
@@ -170,7 +170,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, adapter())
|
self.assertEqual(res, adapter())
|
||||||
|
|
||||||
def test_remote_delete_asserts_current_table(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
@@ -179,7 +179,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_remote_search(self):
|
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"
|
args = {"search": "query"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
self.dbsource.current_table = "table"
|
||||||
@@ -190,7 +190,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, adapter())
|
self.assertEqual(res, adapter())
|
||||||
|
|
||||||
def test_remote_search_asserts_current_table(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
@@ -199,7 +199,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_remote_update(self):
|
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"
|
args = [1], {"vals": "Value"}, "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
self.dbsource.current_table = "table"
|
self.dbsource.current_table = "table"
|
||||||
@@ -210,7 +210,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.assertEqual(res, adapter())
|
self.assertEqual(res, adapter())
|
||||||
|
|
||||||
def test_remote_update_asserts_current_table(self):
|
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"
|
args = [1], "args"
|
||||||
kwargs = {"kwargs": True}
|
kwargs = {"kwargs": True}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
@@ -221,7 +221,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
# Postgres
|
# Postgres
|
||||||
|
|
||||||
def test_execute_postgresql(self):
|
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")
|
expect = ("query", "execute", "metadata")
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "_execute_generic", autospec=True
|
self.dbsource, "_execute_generic", autospec=True
|
||||||
@@ -233,7 +233,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
# Old API Compat
|
# Old API Compat
|
||||||
|
|
||||||
def test_execute_calls_adapter_old_api(self):
|
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"]
|
expect = [None, None, "metadata"]
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "execute_postgresql", autospec=True
|
self.dbsource, "execute_postgresql", autospec=True
|
||||||
@@ -244,7 +244,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
psql.assert_called_once_with(*expect)
|
psql.assert_called_once_with(*expect)
|
||||||
|
|
||||||
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(
|
||||||
self.dbsource, "connection_open", autospec=True
|
self.dbsource, "connection_open", autospec=True
|
||||||
) as connection:
|
) as connection:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class BaseExternalDbsource(models.Model):
|
class BaseExternalDbsource(models.Model):
|
||||||
""" It provides logic for connection to a MSSQL data source. """
|
"""It provides logic for connection to a MSSQL data source."""
|
||||||
|
|
||||||
_inherit = "base.external.dbsource"
|
_inherit = "base.external.dbsource"
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.dbsource = self.env.ref("base_external_dbsource_mssql.demo_mssql")
|
self.dbsource = self.env.ref("base_external_dbsource_mssql.demo_mssql")
|
||||||
|
|
||||||
def test_connection_close_mssql(self):
|
def test_connection_close_mssql(self):
|
||||||
""" It should close the connection """
|
"""It should close the connection"""
|
||||||
connection = mock.MagicMock()
|
connection = mock.MagicMock()
|
||||||
res = self.dbsource.connection_close_mssql(connection)
|
res = self.dbsource.connection_close_mssql(connection)
|
||||||
self.assertEqual(res, connection.close())
|
self.assertEqual(res, connection.close())
|
||||||
|
|
||||||
def test_connection_open_mssql(self):
|
def test_connection_open_mssql(self):
|
||||||
""" It should call SQLAlchemy open """
|
"""It should call SQLAlchemy open"""
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "_connection_open_sqlalchemy"
|
self.dbsource, "_connection_open_sqlalchemy"
|
||||||
) as parent_method:
|
) as parent_method:
|
||||||
@@ -29,7 +29,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
parent_method.assert_called_once_with()
|
parent_method.assert_called_once_with()
|
||||||
|
|
||||||
def test_excecute_mssql(self):
|
def test_excecute_mssql(self):
|
||||||
""" It should pass args to SQLAlchemy execute """
|
"""It should pass args to SQLAlchemy execute"""
|
||||||
expect = "sqlquery", "sqlparams", "metadata"
|
expect = "sqlquery", "sqlparams", "metadata"
|
||||||
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
||||||
self.dbsource.execute_mssql(*expect)
|
self.dbsource.execute_mssql(*expect)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ base_external_dbsource.BaseExternalDbsource.CONNECTORS.append(("mysql", "MySQL")
|
|||||||
|
|
||||||
|
|
||||||
class BaseExternalDbsource(models.Model):
|
class BaseExternalDbsource(models.Model):
|
||||||
""" It provides logic for connection to a MySQL data source. """
|
"""It provides logic for connection to a MySQL data source."""
|
||||||
|
|
||||||
_inherit = "base.external.dbsource"
|
_inherit = "base.external.dbsource"
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,19 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.dbsource = self.env.ref("base_external_dbsource_mysql.demo_mysql")
|
self.dbsource = self.env.ref("base_external_dbsource_mysql.demo_mysql")
|
||||||
|
|
||||||
def test_connection_close_mysql(self):
|
def test_connection_close_mysql(self):
|
||||||
""" It should close the connection """
|
"""It should close the connection"""
|
||||||
connection = mock.MagicMock()
|
connection = mock.MagicMock()
|
||||||
res = self.dbsource.connection_close_mysql(connection)
|
res = self.dbsource.connection_close_mysql(connection)
|
||||||
self.assertEqual(res, connection.close())
|
self.assertEqual(res, connection.close())
|
||||||
|
|
||||||
def test_connection_open_mysql(self):
|
def test_connection_open_mysql(self):
|
||||||
""" It should call SQLAlchemy open """
|
"""It should call SQLAlchemy open"""
|
||||||
with mock.patch.object(self.dbsource, "connection_open_mysql") as parent_method:
|
with mock.patch.object(self.dbsource, "connection_open_mysql") as parent_method:
|
||||||
self.dbsource.connection_open_mysql()
|
self.dbsource.connection_open_mysql()
|
||||||
parent_method.assert_called_once_with()
|
parent_method.assert_called_once_with()
|
||||||
|
|
||||||
def test_excecute_mysql(self):
|
def test_excecute_mysql(self):
|
||||||
""" It should pass args to SQLAlchemy execute """
|
"""It should pass args to SQLAlchemy execute"""
|
||||||
expect = "sqlquery", "sqlparams", "metadata"
|
expect = "sqlquery", "sqlparams", "metadata"
|
||||||
with mock.patch.object(self.dbsource, "execute_mysql") as parent_method:
|
with mock.patch.object(self.dbsource, "execute_mysql") as parent_method:
|
||||||
self.dbsource.execute_mysql(*expect)
|
self.dbsource.execute_mysql(*expect)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class BaseExternalDbsource(models.Model):
|
class BaseExternalDbsource(models.Model):
|
||||||
""" It provides logic for connection to a SQLite data source. """
|
"""It provides logic for connection to a SQLite data source."""
|
||||||
|
|
||||||
_inherit = "base.external.dbsource"
|
_inherit = "base.external.dbsource"
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
self.dbsource = self.env.ref("base_external_dbsource_sqlite.demo_sqlite")
|
self.dbsource = self.env.ref("base_external_dbsource_sqlite.demo_sqlite")
|
||||||
|
|
||||||
def test_connection_close_sqlite(self):
|
def test_connection_close_sqlite(self):
|
||||||
""" It should close the connection """
|
"""It should close the connection"""
|
||||||
connection = mock.MagicMock()
|
connection = mock.MagicMock()
|
||||||
res = self.dbsource.connection_close_sqlite(connection)
|
res = self.dbsource.connection_close_sqlite(connection)
|
||||||
self.assertEqual(res, connection.close())
|
self.assertEqual(res, connection.close())
|
||||||
|
|
||||||
def test_connection_open_sqlite(self):
|
def test_connection_open_sqlite(self):
|
||||||
""" It should call SQLAlchemy open """
|
"""It should call SQLAlchemy open"""
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, "_connection_open_sqlalchemy"
|
self.dbsource, "_connection_open_sqlalchemy"
|
||||||
) as parent_method:
|
) as parent_method:
|
||||||
@@ -30,14 +30,14 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
parent_method.assert_called_once_with()
|
parent_method.assert_called_once_with()
|
||||||
|
|
||||||
def test_excecute_sqlite(self):
|
def test_excecute_sqlite(self):
|
||||||
""" It should pass args to SQLAlchemy execute """
|
"""It should pass args to SQLAlchemy execute"""
|
||||||
expect = "sqlquery", "sqlparams", "metadata"
|
expect = "sqlquery", "sqlparams", "metadata"
|
||||||
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
||||||
self.dbsource.execute_sqlite(*expect)
|
self.dbsource.execute_sqlite(*expect)
|
||||||
parent_method.assert_called_once_with(*expect)
|
parent_method.assert_called_once_with(*expect)
|
||||||
|
|
||||||
def test_execute_sqlit_without_sqlparams(self):
|
def test_execute_sqlit_without_sqlparams(self):
|
||||||
""" It should pass args to SQLAlchemy execute """
|
"""It should pass args to SQLAlchemy execute"""
|
||||||
expect = "sqlquery", None, "metadata"
|
expect = "sqlquery", None, "metadata"
|
||||||
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
with mock.patch.object(self.dbsource, "_execute_sqlalchemy") as parent_method:
|
||||||
self.dbsource.execute_sqlite(*expect)
|
self.dbsource.execute_sqlite(*expect)
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ class ExternalSystem(models.Model):
|
|||||||
_description = "External System"
|
_description = "External System"
|
||||||
|
|
||||||
name = fields.Char(
|
name = fields.Char(
|
||||||
required=True, help="This is the canonical (humanized) name for the system.",
|
required=True,
|
||||||
|
help="This is the canonical (humanized) name for the system.",
|
||||||
)
|
)
|
||||||
host = fields.Char(
|
host = fields.Char(
|
||||||
help="This is the domain or IP address that the system can be reached " "at.",
|
help="This is the domain or IP address that the system can be reached " "at.",
|
||||||
@@ -56,7 +57,10 @@ class ExternalSystem(models.Model):
|
|||||||
default=lambda s: [(6, 0, s.env.user.company_id.ids)],
|
default=lambda s: [(6, 0, s.env.user.company_id.ids)],
|
||||||
help="Access to this system is restricted to these companies.",
|
help="Access to this system is restricted to these companies.",
|
||||||
)
|
)
|
||||||
system_type = fields.Selection(selection="_get_system_types", required=True,)
|
system_type = fields.Selection(
|
||||||
|
selection="_get_system_types",
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
interface = fields.Reference(
|
interface = fields.Reference(
|
||||||
selection="_get_system_types",
|
selection="_get_system_types",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
|
|||||||
@@ -43,12 +43,15 @@ class TestExternalSystem(Common):
|
|||||||
{"name": "Test", "system_type": "external.system.os"}
|
{"name": "Test", "system_type": "external.system.os"}
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
record.interface._name, "external.system.os",
|
record.interface._name,
|
||||||
|
"external.system.os",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_create_context_override(self):
|
def test_create_context_override(self):
|
||||||
"""It should allow for interface create override with context."""
|
"""It should allow for interface create override with context."""
|
||||||
model = self.env["external.system"].with_context(no_create_interface=True,)
|
model = self.env["external.system"].with_context(
|
||||||
|
no_create_interface=True,
|
||||||
|
)
|
||||||
record = model.create({"name": "Test", "system_type": "external.system.os"})
|
record = model.create({"name": "Test", "system_type": "external.system.os"})
|
||||||
self.assertFalse(record.interface)
|
self.assertFalse(record.interface)
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class GlobalDiscount(models.Model):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_global_discount_vals(self, base, **kwargs):
|
def _get_global_discount_vals(self, base, **kwargs):
|
||||||
""" Prepare the dict of values to create to obtain the discounted
|
"""Prepare the dict of values to create to obtain the discounted
|
||||||
amount
|
amount
|
||||||
|
|
||||||
:param float base: the amount to discount
|
:param float base: the amount to discount
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Base(models.AbstractModel):
|
|||||||
# To generate externals IDS.
|
# To generate externals IDS.
|
||||||
match.export_data(fields)
|
match.export_data(fields)
|
||||||
ext_id = match.get_external_id()
|
ext_id = match.get_external_id()
|
||||||
row["id"] = ext_id[match.id] if match else row.get("id", u"")
|
row["id"] = ext_id[match.id] if match else row.get("id", "")
|
||||||
# Store the modified row, in the same order as fields
|
# Store the modified row, in the same order as fields
|
||||||
newdata.append(tuple(row[f] for f in fields))
|
newdata.append(tuple(row[f] for f in fields))
|
||||||
# We will import the patched data to get updates on matches
|
# We will import the patched data to get updates on matches
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class BaseImportMatch(models.Model):
|
|||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
"""Automatic self-descriptive name for the setting records."""
|
"""Automatic self-descriptive name for the setting records."""
|
||||||
for one in self:
|
for one in self:
|
||||||
one.name = u"{}: {}".format(
|
one.name = "{}: {}".format(
|
||||||
one.model_id.display_name,
|
one.model_id.display_name,
|
||||||
" + ".join(one.field_ids.mapped("display_name")),
|
" + ".join(one.field_ids.mapped("display_name")),
|
||||||
)
|
)
|
||||||
@@ -163,9 +163,10 @@ class BaseImportMatchField(models.Model):
|
|||||||
@api.depends("conditional", "field_id", "imported_value")
|
@api.depends("conditional", "field_id", "imported_value")
|
||||||
def _compute_display_name(self):
|
def _compute_display_name(self):
|
||||||
for one in self:
|
for one in self:
|
||||||
pattern = u"{name} ({cond})" if one.conditional else u"{name}"
|
pattern = "{name} ({cond})" if one.conditional else "{name}"
|
||||||
one.display_name = pattern.format(
|
one.display_name = pattern.format(
|
||||||
name=one.field_id.name, cond=one.imported_value,
|
name=one.field_id.name,
|
||||||
|
cond=one.imported_value,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange("field_id", "match_id", "conditional", "imported_value")
|
@api.onchange("field_id", "match_id", "conditional", "imported_value")
|
||||||
|
|||||||
@@ -86,9 +86,12 @@ class ImportCase(TransactionCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.env.ref("base.res_partner_address_4").function, "Bug Fixer"
|
self.env.ref("base.res_partner_address_4").function, "Bug Fixer"
|
||||||
)
|
)
|
||||||
self.assertTrue(self.env.ref("base.res_partner_address_4").child_ids,)
|
self.assertTrue(
|
||||||
|
self.env.ref("base.res_partner_address_4").child_ids,
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(self.env.ref("base.res_partner_address_4").child_ids), 3,
|
len(self.env.ref("base.res_partner_address_4").child_ids),
|
||||||
|
3,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
set(self.env.ref("base.res_partner_address_4").mapped("child_ids.name")),
|
set(self.env.ref("base.res_partner_address_4").mapped("child_ids.name")),
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ class ResUsersRole(models.Model):
|
|||||||
help="Associated group's category",
|
help="Associated group's category",
|
||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
comment = fields.Html(string="Internal Notes",)
|
comment = fields.Html(
|
||||||
|
string="Internal Notes",
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends("line_ids.user_id")
|
@api.depends("line_ids.user_id")
|
||||||
def _compute_user_ids(self):
|
def _compute_user_ids(self):
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ class IrActionsServerNavigateLine(models.Model):
|
|||||||
def _onchange_field_id(self):
|
def _onchange_field_id(self):
|
||||||
# check out the docstring of this in odoo/models.py
|
# check out the docstring of this in odoo/models.py
|
||||||
lines = self.action_id.resolve_2many_commands(
|
lines = self.action_id.resolve_2many_commands(
|
||||||
"navigate_line_ids", self.env.context.get("navigate_line_ids", []),
|
"navigate_line_ids",
|
||||||
|
self.env.context.get("navigate_line_ids", []),
|
||||||
)
|
)
|
||||||
lines = sum(map(self.new, lines), self.browse([]))
|
lines = sum(map(self.new, lines), self.browse([]))
|
||||||
model = lines[-1:].field_id.relation or self.action_id.model_id.model
|
model = lines[-1:].field_id.relation or self.action_id.model_id.model
|
||||||
|
|||||||
Reference in New Issue
Block a user