Skip to content

Commit

Permalink
server_environment: running_env default to test (fix #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Apr 2, 2020
1 parent 28004f8 commit 121a432
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions server_environment/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions server_environment/server_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@
"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"
"We strongly recommend against using the rc file but instead use an "
"explicit config file with this content:\n"
"[options]\nrunning_env = dev"
)

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 or env variable."
)
# safe default
system_base_config["running_env"] = "test"


_load_running_env()


ck_path = None
if _dir:
Expand Down
7 changes: 6 additions & 1 deletion server_environment/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@


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 is not None:
config["running_env"] = self._test_case_running_env
server_env._load_running_env()

def tearDown(self):
super().tearDown()
Expand Down
10 changes: 10 additions & 0 deletions server_environment/tests/test_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# 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 .common import ServerEnvironmentCase
Expand All @@ -25,3 +27,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 = "" # empty -> no env set

def test_running_env_default(self):
self.assertEqual(config["running_env"], "test")

0 comments on commit 121a432

Please sign in to comment.