diff --git a/base_external_dbsource/__manifest__.py b/base_external_dbsource/__manifest__.py index aa99ee3f..d0f8da45 100644 --- a/base_external_dbsource/__manifest__.py +++ b/base_external_dbsource/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "External Database Sources", - "version": "16.0.1.0.1", + "version": "17.0.1.0.0", "category": "Tools", "author": "Daniel Reis, " "LasLabs, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/server-backend", diff --git a/base_external_dbsource/demo/base_external_dbsource.xml b/base_external_dbsource/demo/base_external_dbsource.xml index 6ae471ad..4aa0e0aa 100644 --- a/base_external_dbsource/demo/base_external_dbsource.xml +++ b/base_external_dbsource/demo/base_external_dbsource.xml @@ -1,5 +1,5 @@ - + PostgreSQL local dbname='postgres' password=%s diff --git a/base_external_dbsource/models/base_external_dbsource.py b/base_external_dbsource/models/base_external_dbsource.py index 114dc48d..6f457444 100644 --- a/base_external_dbsource/models/base_external_dbsource.py +++ b/base_external_dbsource/models/base_external_dbsource.py @@ -329,7 +329,7 @@ class BaseExternalDbsource(models.Model): except AttributeError: raise NotImplementedError( _( - '"%(method)s" method not found, check that all assets are installed ' + '"%(method)s" method not found, check that all assets are installed' "for the %(connector)s connector type.", method=method, conector=self.connector, diff --git a/base_external_dbsource/tests/test_base_external_dbsource.py b/base_external_dbsource/tests/test_base_external_dbsource.py index e4db7ba1..e796e987 100644 --- a/base_external_dbsource/tests/test_base_external_dbsource.py +++ b/base_external_dbsource/tests/test_base_external_dbsource.py @@ -7,20 +7,21 @@ from odoo.tests import common class TestBaseExternalDbsource(common.TransactionCase): - def setUp(self): - super(TestBaseExternalDbsource, self).setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() # Obtain current odoo instance DB connection settings - connection_info = connection_info_for(self.env.cr.dbname)[1] + connection_info = connection_info_for(cls.env.cr.dbname)[1] # Adapt to the format expected by this module password = connection_info.get("password", "") connection_info["password"] = "%s" connection_info["dbname"] = connection_info["database"] del connection_info["database"] # Create a proper dbsource record to test - self.dbsource = self.env["base.external.dbsource"].create( + cls.dbsource = cls.env["base.external.dbsource"].create( { "conn_string": " ".join( - "%s='%s'" % item for item in connection_info.items() + f"{key}='{value}'" for key, value in connection_info.items() ), "connector": "postgresql", "name": "test postgres with current odoo config", @@ -57,6 +58,16 @@ class TestBaseExternalDbsource(common.TransactionCase): expect = self.dbsource.conn_string + "PWD=%s;" % self.dbsource.password self.assertEqual(self.dbsource.conn_string_full, expect) + self.dbsource.conn_string = "User=Derp;" + self.dbsource.password = "" + expect = self.dbsource.conn_string + self.assertEqual(self.dbsource.conn_string_full, expect) + + self.dbsource.conn_string = "User=Derp;PWD=%s;" + self.dbsource.password = "password" + expect = self.dbsource.conn_string % self.dbsource.password + self.assertEqual(self.dbsource.conn_string_full, expect) + # Interface def test_execute_asserts_query_arg(self): @@ -228,3 +239,20 @@ class TestBaseExternalDbsource(common.TransactionCase): with mock.patch.object(type(self.dbsource), "connection_open") as connection: res = self.dbsource.conn_open() self.assertEqual(res, connection().__enter__()) + + def test_connection_close(self): + """It should call the close method on the connection object""" + mock_connection = mock.Mock() + self.dbsource.connection_close(mock_connection) + mock_connection.close.assert_called_once() + + def test_execute_missing_query_and_params(self): + """It should raise a TypeError if both query and execute_params are missing""" + with self.assertRaises(TypeError): + self.dbsource.execute(metadata=True) + + def test_connection_close_postgresql(self): + """It should call the close method on the connection object""" + mock_connection = mock.Mock() + self.dbsource.connection_close_postgresql(mock_connection) + mock_connection.close.assert_called_once() diff --git a/base_external_dbsource/views/base_external_dbsource.xml b/base_external_dbsource/views/base_external_dbsource.xml index 3445feef..9afa68a4 100644 --- a/base_external_dbsource/views/base_external_dbsource.xml +++ b/base_external_dbsource/views/base_external_dbsource.xml @@ -1,66 +1,65 @@ - - base.external.dbsource.tree - base.external.dbsource - tree - - - - - - - - - - base.external.dbsource.form - base.external.dbsource - -
- - + + base.external.dbsource.tree + base.external.dbsource + tree + + + + + + + + + + base.external.dbsource.form + base.external.dbsource + + + - - + + + + + + + - - + + + - - - - + +