mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] base_external_dbsource: Migration to 14.0
This commit is contained in:
committed by
Víctor Martínez
parent
4f6d0671c6
commit
e489035275
@@ -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": "13.0.1.0.0",
|
"version": "14.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,12 +0,0 @@
|
|||||||
# Copyright 2016 LasLabs Inc.
|
|
||||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionFailedError(UserError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionSuccessError(UserError):
|
|
||||||
pass
|
|
||||||
@@ -8,8 +8,7 @@ from contextlib import contextmanager
|
|||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
from odoo import _, api, fields, models, tools
|
from odoo import _, api, fields, models, tools
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
from ..exceptions import ConnectionFailedError, ConnectionSuccessError
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
# to allow for override.
|
# to allow for override.
|
||||||
PWD_STRING = "PWD=%s;"
|
PWD_STRING = "PWD=%s;"
|
||||||
|
|
||||||
name = fields.Char("Datasource name", required=True, size=64)
|
name = fields.Char("Datasource name", required=True)
|
||||||
conn_string = fields.Text(
|
conn_string = fields.Text(
|
||||||
"Connection string",
|
"Connection string",
|
||||||
help="""
|
help="""
|
||||||
@@ -59,7 +58,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
conn_string_full = fields.Text(readonly=True, compute="_compute_conn_string_full")
|
conn_string_full = fields.Text(readonly=True, compute="_compute_conn_string_full")
|
||||||
password = fields.Char("Password", size=40)
|
password = fields.Char("Password")
|
||||||
client_cert = fields.Text()
|
client_cert = fields.Text()
|
||||||
client_key = fields.Text()
|
client_key = fields.Text()
|
||||||
ca_certs = fields.Char(help="Path to CA Certs file on server.")
|
ca_certs = fields.Char(help="Path to CA Certs file on server.")
|
||||||
@@ -173,14 +172,15 @@ class BaseExternalDbsource(models.Model):
|
|||||||
with self.connection_open():
|
with self.connection_open():
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ConnectionFailedError(
|
raise ValidationError(
|
||||||
_("Connection test failed:\n" "Here is what we got instead:\n%s")
|
_("Connection test failed:\n" "Here is what we got instead:\n%s")
|
||||||
% tools.ustr(e)
|
% tools.ustr(e)
|
||||||
)
|
)
|
||||||
raise ConnectionSuccessError(
|
raise ValidationError(
|
||||||
_("Connection test succeeded:\n" "Everything seems properly set up!")
|
_("Connection test succeeded:\n" "Everything seems properly set up!")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def remote_browse(self, record_ids, *args, **kwargs):
|
def remote_browse(self, record_ids, *args, **kwargs):
|
||||||
"""It browses for and returns the records from remote by ID
|
"""It browses for and returns the records from remote by ID
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import mock
|
|||||||
from odoo.sql_db import connection_info_for
|
from odoo.sql_db import connection_info_for
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
from ..exceptions import ConnectionFailedError, ConnectionSuccessError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class TestBaseExternalDbsource(common.TransactionCase):
|
class TestBaseExternalDbsource(common.TransactionCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -63,14 +62,14 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
|
|
||||||
def test_connection_success(self):
|
def test_connection_success(self):
|
||||||
""" It should raise for successful connection """
|
""" It should raise for successful connection """
|
||||||
with self.assertRaises(ConnectionSuccessError):
|
with self.assertRaises(ValidationError):
|
||||||
self.dbsource.connection_test()
|
self.dbsource.connection_test()
|
||||||
|
|
||||||
def test_connection_fail(self):
|
def test_connection_fail(self):
|
||||||
""" It should raise for failed/invalid connection """
|
""" It should raise for failed/invalid connection """
|
||||||
with mock.patch.object(self.dbsource, "connection_open") as conn:
|
with mock.patch.object(self.dbsource, "connection_open") as conn:
|
||||||
conn.side_effect = Exception
|
conn.side_effect = Exception
|
||||||
with self.assertRaises(ConnectionFailedError):
|
with self.assertRaises(ValidationError):
|
||||||
self.dbsource.connection_test()
|
self.dbsource.connection_test()
|
||||||
|
|
||||||
def test_connection_open_calls_close(self):
|
def test_connection_open_calls_close(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user