-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] server_environment: add possibility of auto creating records
- Loading branch information
1 parent
40c12a6
commit 3c8a812
Showing
8 changed files
with
169 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
- Thomas Binfeld \<<[email protected]>\> | ||
- Stéphane Bidoul \<<[email protected]>\> | ||
- Simone Orsi \<<[email protected]>\> | ||
- Vincent Hatakeyama \<<[email protected]>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import test_server_environment_autocreate | ||
from . import test_server_environment | ||
from . import test_environment_variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 XCG Consulting | ||
# @author Vincent Hatakeyama | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ExternalService(models.Model): | ||
_name = "external_service" | ||
_description = "External Service" | ||
_inherit = "server.env.mixin" | ||
|
||
name = fields.Char(required=True) | ||
description = fields.Char(required=True) | ||
host = fields.Char() | ||
user = fields.Char() | ||
password = fields.Char() | ||
|
||
@property | ||
def _server_env_fields(self): | ||
return { | ||
"host": {}, | ||
"user": {}, | ||
"password": {}, | ||
} |
76 changes: 76 additions & 0 deletions
76
server_environment/tests/test_server_environment_autocreate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2018 Camptocamp (https://www.camptocamp.com). | ||
# Copyright 2024 XCG Consulting (https://xcg-consulting.fr). | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) | ||
import configparser | ||
|
||
from odoo_test_helper import FakeModelLoader | ||
|
||
from odoo.tests import tagged | ||
|
||
from .. import server_env | ||
from . import common | ||
|
||
|
||
# Test need to be run post install otherwise the _register_hook is not called yet | ||
@tagged("post_install", "-at_install") | ||
class TestEnv(common.ServerEnvironmentCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
# Load fake models ->/ | ||
cls.loader = FakeModelLoader(cls.env, cls.__module__) | ||
cls.loader.backup_registry() | ||
from .models import ExternalService | ||
|
||
cls.loader.update_registry((ExternalService,)) | ||
cls.env["external_service"].create([{"name": "ftp2", "description": "another"}]) | ||
|
||
# Add our sections | ||
cls.old_serv_config = server_env.serv_config | ||
server_env.serv_config = configparser.ConfigParser(cls.old_serv_config) | ||
# update configuration with extra sections and values | ||
server_env.serv_config.add_section("external_service.ftp") | ||
server_env.serv_config.set( | ||
"external_service.ftp", "__autocreate", "{'description': 'ftp server'}" | ||
) | ||
server_env.serv_config.set("external_service.ftp", "host", "sftp.example.com") | ||
server_env.serv_config.set("external_service.ftp", "user", "foo") | ||
server_env.serv_config.set("external_service.ftp", "password", "bar") | ||
server_env.serv_config.add_section("external_service.ftp2") | ||
server_env.serv_config.set( | ||
"external_service.ftp2", "__autocreate", "{'description': 'ftp2'}" | ||
) | ||
server_env.serv_config.set("external_service.ftp2", "host", "sftp2.example.com") | ||
server_env.serv_config.set("external_service.ftp2", "user", "monty") | ||
server_env.serv_config.set("external_service.ftp2", "password", "python") | ||
# used to force _register_hook with auto creation | ||
cls.loader.update_registry(tuple()) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.loader.restore_registry() | ||
super().tearDownClass() | ||
server_env.serv_config = cls.old_serv_config | ||
|
||
def test_autocreate(self): | ||
# create record in setupClass | ||
# Test it has no xmlid | ||
record = self.env.ref("__server_environment__.external_service.ftp2", False) | ||
self.assertFalse(record) | ||
# look for it | ||
record = self.env["external_service"].search([("name", "=", "ftp2")]) | ||
self.assertEqual(len(record), 1) | ||
self.assertEqual(record.name, "ftp2") | ||
# different from __autocreate dict as it is created in setUpClass | ||
self.assertEqual(record.description, "another") | ||
self.assertEqual(record.host, "sftp2.example.com") | ||
self.assertEqual(record.user, "monty") | ||
self.assertEqual(record.password, "python") | ||
|
||
# auto created record | ||
record = self.env.ref("__server_environment__.external_service.ftp") | ||
self.assertEqual(record.name, "ftp") | ||
self.assertEqual(record.description, "ftp server") | ||
self.assertEqual(record.host, "sftp.example.com") | ||
self.assertEqual(record.user, "foo") | ||
self.assertEqual(record.password, "bar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
odoo-test-helper |