From e6a309d07d53891424ea587ba3f8a1dc939cbef7 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 28 Mar 2019 09:44:19 +0000 Subject: [PATCH] [FIX] base_external_dbsource: Reuse Odoo DB settings for tests Before, postgres configuration was hardcoded. This worked OK for OCA's CI infrastructure, but failed in any other out there that had different defaults. There's no need to hardcode it; Odoo already must have Postgres connection settings, so let's use those instead. This will make tests testable across different CI infrastructures. --- base_external_dbsource/README.rst | 1 + base_external_dbsource/readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 1 + .../tests/test_base_external_dbsource.py | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/base_external_dbsource/README.rst b/base_external_dbsource/README.rst index a58882c8..cd46404f 100644 --- a/base_external_dbsource/README.rst +++ b/base_external_dbsource/README.rst @@ -96,6 +96,7 @@ Contributors * Gervais Naoussi * Dave Lasley * Sergio Teruel (https://wwww.tecnativa.com) +* Jairo Llopis (https://wwww.tecnativa.com) Maintainers ~~~~~~~~~~~ diff --git a/base_external_dbsource/readme/CONTRIBUTORS.rst b/base_external_dbsource/readme/CONTRIBUTORS.rst index 7826d82d..c6c89ba5 100644 --- a/base_external_dbsource/readme/CONTRIBUTORS.rst +++ b/base_external_dbsource/readme/CONTRIBUTORS.rst @@ -3,3 +3,4 @@ * Gervais Naoussi * Dave Lasley * Sergio Teruel (https://wwww.tecnativa.com) +* Jairo Llopis (https://wwww.tecnativa.com) diff --git a/base_external_dbsource/static/description/index.html b/base_external_dbsource/static/description/index.html index 44247431..0c0ae80c 100644 --- a/base_external_dbsource/static/description/index.html +++ b/base_external_dbsource/static/description/index.html @@ -447,6 +447,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Gervais Naoussi <gervaisnaoussi@gmail.com>
  • Dave Lasley <dave@laslabs.com>
  • Sergio Teruel <sergio.teruel@tecnativa.com> (https://wwww.tecnativa.com)
  • +
  • Jairo Llopis <jairo.llopis@tecnativa.com> (https://wwww.tecnativa.com)
  • diff --git a/base_external_dbsource/tests/test_base_external_dbsource.py b/base_external_dbsource/tests/test_base_external_dbsource.py index 0ee52ee2..917c0ac6 100644 --- a/base_external_dbsource/tests/test_base_external_dbsource.py +++ b/base_external_dbsource/tests/test_base_external_dbsource.py @@ -3,6 +3,7 @@ import mock from odoo.tests import common +from odoo.sql_db import connection_info_for from ..exceptions import ConnectionFailedError, ConnectionSuccessError @@ -11,7 +12,22 @@ class TestBaseExternalDbsource(common.TransactionCase): def setUp(self): super(TestBaseExternalDbsource, self).setUp() - self.dbsource = self.env.ref('base_external_dbsource.demo_postgre') + # Obtain current odoo instance DB connection settings + connection_info = connection_info_for(self.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({ + "conn_string": " ".join( + "%s='%s'" % item for item in connection_info.items() + ), + "connector": "postgresql", + "name": "test postgres with current odoo config", + "password": password, + }) def _test_adapter_method( self, method_name, side_effect=None, return_value=None,