server_environment: running_env default to `test` (fix #44)
This commit is contained in:
parent
7f735e1606
commit
7d6ebde333
|
|
@ -8,6 +8,8 @@ used values are 'dev', 'test', 'production'::
|
||||||
Values associated to keys containing 'passw' are only displayed in the 'dev'
|
Values associated to keys containing 'passw' are only displayed in the 'dev'
|
||||||
environment.
|
environment.
|
||||||
|
|
||||||
|
If you don't provide any value, `test` is used as a safe default.
|
||||||
|
|
||||||
You have several possibilities to set configuration values:
|
You have several possibilities to set configuration values:
|
||||||
|
|
||||||
server_environment_files
|
server_environment_files
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,19 @@ ENV_VAR_NAMES = ('SERVER_ENV_CONFIG', 'SERVER_ENV_CONFIG_SECRET')
|
||||||
_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
|
_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
|
||||||
'0': False, 'no': False, 'false': False, 'off': False}
|
'0': False, 'no': False, 'false': False, 'off': False}
|
||||||
|
|
||||||
if not system_base_config.get('running_env', False):
|
|
||||||
raise Exception(
|
def _load_running_env():
|
||||||
"The parameter 'running_env' has not be set neither in base config "
|
if not system_base_config.get("running_env"):
|
||||||
"file option -c or in openerprc.\n"
|
_logger.warning("`running_env` not found. Using default = `test`.")
|
||||||
"We strongly recommend against using the rc file but instead use an "
|
_logger.warning(
|
||||||
"explicit config file with this content:\n"
|
"We strongly recommend against using the rc file but instead use an "
|
||||||
"[options]\nrunning_env = dev"
|
"explicit config file or env variable."
|
||||||
)
|
)
|
||||||
|
# safe default
|
||||||
|
system_base_config["running_env"] = "test"
|
||||||
|
|
||||||
|
|
||||||
|
_load_running_env()
|
||||||
|
|
||||||
ck_path = None
|
ck_path = None
|
||||||
if _dir:
|
if _dir:
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,14 @@ import odoo.addons.server_environment.models.server_env_mixin as \
|
||||||
|
|
||||||
class ServerEnvironmentCase(common.SavepointCase):
|
class ServerEnvironmentCase(common.SavepointCase):
|
||||||
|
|
||||||
|
_test_case_running_env = "testing"
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self._original_running_env = config.get('running_env')
|
self._original_running_env = config.get('running_env')
|
||||||
config['running_env'] = 'testing'
|
if self._test_case_running_env is not None:
|
||||||
|
config['running_env'] = self._test_case_running_env
|
||||||
|
server_env._load_running_env()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
|
||||||
|
from odoo.tools.config import config
|
||||||
|
|
||||||
from odoo.addons.server_environment import server_env
|
from odoo.addons.server_environment import server_env
|
||||||
from .common import ServerEnvironmentCase
|
from .common import ServerEnvironmentCase
|
||||||
|
|
||||||
|
|
@ -43,3 +45,11 @@ class TestEnvironmentVariables(ServerEnvironmentCase):
|
||||||
parser = server_env._load_config()
|
parser = server_env._load_config()
|
||||||
val = parser.get('external_service.ftp', 'user')
|
val = parser.get('external_service.ftp', 'user')
|
||||||
self.assertEqual(val, 'foo')
|
self.assertEqual(val, 'foo')
|
||||||
|
|
||||||
|
|
||||||
|
class TestRunningEnv(ServerEnvironmentCase):
|
||||||
|
|
||||||
|
_test_case_running_env = '' # empty -> no env set
|
||||||
|
|
||||||
|
def test_running_env_default(self):
|
||||||
|
self.assertEqual(config['running_env'], 'test')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue