mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] base_external_dbsource: Migration to 17.0
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
{
|
{
|
||||||
"name": "External Database Sources",
|
"name": "External Database Sources",
|
||||||
"version": "16.0.1.0.1",
|
"version": "17.0.1.0.0",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
"author": "Daniel Reis, " "LasLabs, " "Odoo Community Association (OCA)",
|
"author": "Daniel Reis, " "LasLabs, " "Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/server-backend",
|
"website": "https://github.com/OCA/server-backend",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<odoo>
|
<odoo noupdate="1">
|
||||||
<record model="base.external.dbsource" id="demo_postgre">
|
<record model="base.external.dbsource" id="demo_postgre">
|
||||||
<field name="name">PostgreSQL local</field>
|
<field name="name">PostgreSQL local</field>
|
||||||
<field name="conn_string">dbname='postgres' password=%s</field>
|
<field name="conn_string">dbname='postgres' password=%s</field>
|
||||||
|
|||||||
@@ -7,20 +7,21 @@ from odoo.tests import common
|
|||||||
|
|
||||||
|
|
||||||
class TestBaseExternalDbsource(common.TransactionCase):
|
class TestBaseExternalDbsource(common.TransactionCase):
|
||||||
def setUp(self):
|
@classmethod
|
||||||
super(TestBaseExternalDbsource, self).setUp()
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
# Obtain current odoo instance DB connection settings
|
# 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
|
# Adapt to the format expected by this module
|
||||||
password = connection_info.get("password", "")
|
password = connection_info.get("password", "")
|
||||||
connection_info["password"] = "%s"
|
connection_info["password"] = "%s"
|
||||||
connection_info["dbname"] = connection_info["database"]
|
connection_info["dbname"] = connection_info["database"]
|
||||||
del connection_info["database"]
|
del connection_info["database"]
|
||||||
# Create a proper dbsource record to test
|
# 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(
|
"conn_string": " ".join(
|
||||||
"%s='%s'" % item for item in connection_info.items()
|
f"{key}='{value}'" for key, value in connection_info.items()
|
||||||
),
|
),
|
||||||
"connector": "postgresql",
|
"connector": "postgresql",
|
||||||
"name": "test postgres with current odoo config",
|
"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
|
expect = self.dbsource.conn_string + "PWD=%s;" % self.dbsource.password
|
||||||
self.assertEqual(self.dbsource.conn_string_full, expect)
|
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
|
# Interface
|
||||||
|
|
||||||
def test_execute_asserts_query_arg(self):
|
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:
|
with mock.patch.object(type(self.dbsource), "connection_open") as connection:
|
||||||
res = self.dbsource.conn_open()
|
res = self.dbsource.conn_open()
|
||||||
self.assertEqual(res, connection().__enter__())
|
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()
|
||||||
|
|||||||
@@ -27,21 +27,21 @@
|
|||||||
groups="base.group_multi_company"
|
groups="base.group_multi_company"
|
||||||
options="{'no_create': True}"
|
options="{'no_create': True}"
|
||||||
/>
|
/>
|
||||||
|
<field name="connector" />
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="password" password="True" />
|
<field name="password" password="True" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group col="1">
|
<group string="Connection String">
|
||||||
<group>
|
|
||||||
<field name="connector" />
|
|
||||||
</group>
|
|
||||||
<group string="Connection string" col="1">
|
|
||||||
<field
|
<field
|
||||||
name="conn_string"
|
name="conn_string"
|
||||||
nolabel="1"
|
nolabel="1"
|
||||||
placeholder="Please check the tooltip for connection string examples"
|
placeholder="Please check the tooltip for connection string examples"
|
||||||
/>
|
/>
|
||||||
|
<group />
|
||||||
|
</group>
|
||||||
|
<group col="1">
|
||||||
<button
|
<button
|
||||||
name="connection_test"
|
name="connection_test"
|
||||||
string="Test Connection"
|
string="Test Connection"
|
||||||
@@ -49,7 +49,6 @@
|
|||||||
icon="fa-refresh"
|
icon="fa-refresh"
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user