[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.
This commit is contained in:
Jairo Llopis
2019-03-28 09:44:19 +00:00
committed by Sergio Teruel
parent c6a9bd39f7
commit 0a5ccebdfc
4 changed files with 20 additions and 1 deletions

View File

@@ -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,