Skip to content
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

[18.0][FIX] server_environment: test independent from the working env #212

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading