Skip to content

Commit

Permalink
[FIX] server_environment: test independent from the working env
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Oct 29, 2024
1 parent 3a6f9fe commit c1efa58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions server_environment/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import odoo.addons.server_environment.models.server_env_mixin as server_env_mixin
from odoo.addons.server_environment import server_env

CLEAN_ENV = {
var: value
for (var, value) in os.environ.items()
if var not in ("RUNNING_ENV", "ODOO_STAGE")
}


class ServerEnvironmentCase(common.TransactionCase):
@contextmanager
Expand All @@ -24,13 +30,13 @@ def set_config_dir(self, path):
server_env._dir = original_dir

@contextmanager
def set_env_variables(self, public=None, secret=None):
newkeys = {}
def set_env_variables(self, public=None, secret=None, **env_vars):
newkeys = {**CLEAN_ENV, **env_vars}
if public:
newkeys["SERVER_ENV_CONFIG"] = public
if secret:
newkeys["SERVER_ENV_CONFIG_SECRET"] = secret
with patch.dict("os.environ", newkeys):
with patch.dict("os.environ", newkeys, clear=True):
yield

@contextmanager
Expand Down
4 changes: 3 additions & 1 deletion server_environment/tests/test_environment_variable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2018 Camptocamp (https://www.camptocamp.com).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)


from unittest.mock import patch

from odoo.tools.config import config as odoo_config
Expand All @@ -12,8 +11,11 @@


class TestRunningEnvDefault(ServerEnvironmentCase):
@patch.dict(odoo_config.options, {"running_env": None})
def test_running_env_default(self):
"""When var is not provided it defaults to `test`."""
with self.set_env_variables():
server_env._load_running_env()
self.assertEqual(odoo_config["running_env"], "test")


Expand Down

0 comments on commit c1efa58

Please sign in to comment.