commit
75da59c939
|
|
@ -31,8 +31,6 @@ install:
|
|||
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
|
||||
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
|
||||
- travis_install_nightly
|
||||
# Requirements to test server_environment modules
|
||||
- printf '[options]\n\nrunning_env = dev\n' > ${HOME}/.openerp_serverrc
|
||||
- ln -s ${TRAVIS_BUILD_DIR}/server_environment_files_sample ${TRAVIS_BUILD_DIR}/server_environment_files
|
||||
|
||||
script:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ used values are 'dev', 'test', 'production'::
|
|||
Values associated to keys containing 'passw' are only displayed in the 'dev'
|
||||
environment.
|
||||
|
||||
If you don't provide any value, `test` is used as a safe default.
|
||||
|
||||
You have several possibilities to set configuration values:
|
||||
|
||||
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,
|
||||
'0': False, 'no': False, 'false': False, '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"
|
||||
|
||||
def _load_running_env():
|
||||
if not system_base_config.get("running_env"):
|
||||
_logger.warning("`running_env` not found. Using default = `test`.")
|
||||
_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"] = "test"
|
||||
|
||||
|
||||
_load_running_env()
|
||||
|
||||
ck_path = None
|
||||
if _dir:
|
||||
|
|
@ -164,9 +169,6 @@ class ServerConfiguration(models.TransientModel):
|
|||
"""
|
||||
ModelClass = super(ServerConfiguration, cls)._build_model(pool, cr)
|
||||
ModelClass._add_columns()
|
||||
ModelClass.running_env = system_base_config['running_env']
|
||||
# Only show passwords in development
|
||||
ModelClass.show_passwords = ModelClass.running_env in ('dev',)
|
||||
ModelClass._arch = None
|
||||
ModelClass._build_osv()
|
||||
return ModelClass
|
||||
|
|
@ -175,6 +177,10 @@ class ServerConfiguration(models.TransientModel):
|
|||
def _format_key(cls, section, key):
|
||||
return '%s_I_%s' % (section, key)
|
||||
|
||||
@property
|
||||
def show_passwords(self):
|
||||
return system_base_config["running_env"] in ("dev",)
|
||||
|
||||
@classmethod
|
||||
def _format_key_display_name(cls, key_name):
|
||||
return key_name.replace('_I_', ' | ')
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from unittest.mock import patch
|
|||
|
||||
from odoo.tests import common
|
||||
from odoo.addons.server_environment import server_env
|
||||
from odoo.tools.config import config
|
||||
|
||||
import odoo.addons.server_environment.models.server_env_mixin as \
|
||||
server_env_mixin
|
||||
|
|
@ -15,15 +14,6 @@ import odoo.addons.server_environment.models.server_env_mixin as \
|
|||
|
||||
class ServerEnvironmentCase(common.SavepointCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self._original_running_env = config.get('running_env')
|
||||
config['running_env'] = 'testing'
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
config['running_env'] = self._original_running_env
|
||||
|
||||
@contextmanager
|
||||
def set_config_dir(self, path):
|
||||
original_dir = server_env._dir
|
||||
|
|
|
|||
|
|
@ -2,10 +2,21 @@
|
|||
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.tools.config import config as odoo_config
|
||||
|
||||
from odoo.addons.server_environment import server_env
|
||||
from .common import ServerEnvironmentCase
|
||||
|
||||
|
||||
class TestRunningEnvDefault(ServerEnvironmentCase):
|
||||
def test_running_env_default(self):
|
||||
"""When var is not provided it defaults to `test`."""
|
||||
self.assertEqual(odoo_config["running_env"], "test")
|
||||
|
||||
|
||||
@patch.dict(odoo_config.options, {"running_env": "testing"})
|
||||
class TestEnvironmentVariables(ServerEnvironmentCase):
|
||||
|
||||
def test_env_variables(self):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
# Copyright 2018 Camptocamp (https://www.camptocamp.com).
|
||||
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.tools.config import config as odoo_config
|
||||
|
||||
from odoo.addons.server_environment import server_env
|
||||
from . import common
|
||||
|
||||
|
|
@ -11,7 +16,7 @@ class TestEnv(common.ServerEnvironmentCase):
|
|||
view = model.fields_view_get()
|
||||
self.assertTrue(view)
|
||||
|
||||
def test_default(self):
|
||||
def _test_default(self, hidden_pwd=False):
|
||||
model = self.env['server.config']
|
||||
rec = model.create({})
|
||||
defaults = rec.default_get([])
|
||||
|
|
@ -20,11 +25,20 @@ class TestEnv(common.ServerEnvironmentCase):
|
|||
pass_checked = False
|
||||
for default in defaults:
|
||||
if 'passw' in default:
|
||||
self.assertNotEqual(defaults[default],
|
||||
'**********')
|
||||
check = self.assertEqual if hidden_pwd else self.assertNotEqual
|
||||
check(defaults[default], "**********")
|
||||
pass_checked = True
|
||||
self.assertTrue(pass_checked)
|
||||
|
||||
@patch.dict(odoo_config.options, {"running_env": "dev"})
|
||||
def test_default_dev(self):
|
||||
self._test_default()
|
||||
|
||||
@patch.dict(odoo_config.options, {"running_env": "whatever"})
|
||||
def test_default_non_dev_env(self):
|
||||
self._test_default(hidden_pwd=True)
|
||||
|
||||
@patch.dict(odoo_config.options, {"running_env": "testing"})
|
||||
def test_value_retrival(self):
|
||||
with self.set_config_dir('testfiles'):
|
||||
parser = server_env._load_config()
|
||||
|
|
|
|||
Loading…
Reference in New Issue