Skip to content

Commit

Permalink
fixup! 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 10, 2020
1 parent 46337ae commit 5df8a5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 0 additions & 12 deletions server_environment/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
from unittest.mock import patch

from odoo.tests import common
from odoo.tools.config import config

import odoo.addons.server_environment.models.server_env_mixin as server_env_mixin
from odoo.addons.server_environment import server_env


class ServerEnvironmentCase(common.SavepointCase):

_test_case_running_env = "testing"

def setUp(self):
super().setUp()
self._original_running_env = config.get("running_env")
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()
config["running_env"] = self._original_running_env

@contextmanager
def set_config_dir(self, path):
Expand Down
12 changes: 7 additions & 5 deletions server_environment/tests/test_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo.tools.config import config
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


@patch.dict(odoo_config.options, {"running_env": "testing"})
class TestEnvironmentVariables(ServerEnvironmentCase):
def test_env_variables(self):
public = "[section]\n" "foo=bar\n" "bar=baz\n"
Expand All @@ -29,9 +32,8 @@ def test_env_variables_override(self):
self.assertEqual(val, "foo")


@patch.dict(odoo_config.options, {"running_env": ""})
class TestRunningEnv(ServerEnvironmentCase):

_test_case_running_env = "" # empty -> no env set

def test_running_env_default(self):
self.assertEqual(config["running_env"], "test")
server_env._load_running_env()
self.assertEqual(odoo_config["running_env"], "test")
5 changes: 5 additions & 0 deletions server_environment/tests/test_server_environment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# 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 .. import server_env
from . import common


@patch.dict(odoo_config.options, {"running_env": "testing"})
class TestEnv(common.ServerEnvironmentCase):
def test_view(self):
model = self.env["server.config"]
Expand Down

0 comments on commit 5df8a5a

Please sign in to comment.