From d1d625942f1eb2a3eba4f96d21a332da387c86a1 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Wed, 1 Apr 2020 12:15:57 +0200 Subject: [PATCH] server_environemnt: running_env default to `dev` (fix #44) --- server_environment/server_env.py | 16 ++++++++++------ server_environment/tests/common.py | 6 +++++- .../tests/test_environment_variable.py | 9 +++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/server_environment/server_env.py b/server_environment/server_env.py index 4d2af55c..702f30cc 100644 --- a/server_environment/server_env.py +++ b/server_environment/server_env.py @@ -58,14 +58,18 @@ "off": False, } -if not system_base_config.get("running_env", False): - raise Exception( - "The parameter 'running_env' has not be set neither in base config " - "file option -c or in openerprc.\n" + +if not system_base_config.get("running_env"): + _logger.warning( + "`running_env` not found. Using default = `dev`." + ) + _logger.warning( "We strongly recommend against using the rc file but instead use an " - "explicit config file with this content:\n" - "[options]\nrunning_env = dev" + "explicit config file or env variable." ) + # safe default + system_base_config["running_env"] = "dev" + ck_path = None if _dir: diff --git a/server_environment/tests/common.py b/server_environment/tests/common.py index 781ce256..d89cd268 100644 --- a/server_environment/tests/common.py +++ b/server_environment/tests/common.py @@ -13,10 +13,14 @@ class ServerEnvironmentCase(common.SavepointCase): + + _test_case_running_env = "testing" + def setUp(self): super().setUp() self._original_running_env = config.get("running_env") - config["running_env"] = "testing" + if self._test_case_running_env: + config["running_env"] = self._test_case_running_env def tearDown(self): super().tearDown() diff --git a/server_environment/tests/test_environment_variable.py b/server_environment/tests/test_environment_variable.py index 17474067..410eb8b1 100644 --- a/server_environment/tests/test_environment_variable.py +++ b/server_environment/tests/test_environment_variable.py @@ -3,6 +3,7 @@ from odoo.addons.server_environment import server_env +from odoo.tools.config import config from .common import ServerEnvironmentCase @@ -25,3 +26,11 @@ def test_env_variables_override(self): parser = server_env._load_config() val = parser.get("external_service.ftp", "user") self.assertEqual(val, "foo") + + +class TestRunningEnv(ServerEnvironmentCase): + + _test_case_running_env = "" + + def test_running_env_default(self): + self.assertEqual(config["running_env"], "dev")