mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user