-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[17.0][IMP] server_environment: add possibility of auto creating records #188
Open
vincent-hatakeyama
wants to merge
1
commit into
OCA:17.0
Choose a base branch
from
xcgd:17.0-server_environment_autocreate
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {}, | ||
} |
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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
# 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) | ||
from unittest.mock import patch | ||
|
||
from odoo_test_helper import FakeModelLoader | ||
|
||
from odoo.tests import tagged | ||
from odoo.tools.config import config as odoo_config | ||
|
||
from .. import server_env | ||
from ..models import server_env_mixin | ||
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"}]) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.loader.restore_registry() | ||
super().tearDownClass() | ||
|
||
@patch.dict(odoo_config.options, {"running_env": "autocreate"}) | ||
def test_autocreate(self): | ||
original_serv_config = server_env_mixin.serv_config | ||
try: | ||
with self.set_config_dir("testfiles"): | ||
parser = server_env._load_config() | ||
server_env_mixin.serv_config = parser | ||
# Needed to force _register_hook with auto creation | ||
self.loader.update_registry(tuple()) | ||
|
||
# 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") | ||
|
||
# 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") | ||
finally: | ||
server_env_mixin.serv_config = original_serv_config |
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,11 @@ | ||
[external_service.ftp] | ||
__autocreate={"description": "ftp server"} | ||
; host=sftp.example.com | ||
; user=foo | ||
; password=bar | ||
|
||
[external_service.ftp2] | ||
__autocreate={"description": "ftp2"} | ||
host=sftp2.example.com | ||
user=monty | ||
password=python |
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you loop on all the models? This mixin will be inherited by a specific model and that model only should be set up...
Something like this would be better.