Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
fkantelberg committed Nov 18, 2024
1 parent 623d39b commit b567782
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ def test_apply_action(env):

odoo = sys.modules["odoo"] = mock.MagicMock()
sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()
sys.modules["odoo.release"] = odoo.release
odoo.release.version_info = (14, 0)
env._init_odoo.return_value = True
Expand Down
2 changes: 2 additions & 0 deletions tests/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def env():
def test_test(pytest_mock, env):
odoo = sys.modules["odoo"] = mock.MagicMock()
tools = sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()
sys.modules["odoo.release"] = odoo.release
odoo.release.version_info = (14, 0)

Expand Down
8 changes: 5 additions & 3 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ def test_env(env):
with env.env("odoo"):
pass

odoo = sys.modules["odoo"] = mock.MagicMock()
reg = odoo.registry.return_value = mock.MagicMock()
sys.modules["odoo"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
registry = sys.modules["odoo.modules.registry"] = mock.MagicMock()
reg = registry.Registry.return_value = mock.MagicMock()
cr = reg.cursor.return_value = mock.MagicMock()

# Test the normal commit
with env.env("odoo"):
odoo.registry.assert_called_once_with("odoo")
registry.Registry.assert_called_once_with("odoo")
cr.commit.assert_not_called()

cr.commit.assert_called_once()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def env():
def test_migrate(repos, env):
odoo = sys.modules["odoo"] = mock.MagicMock()
tools = sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()
tools.config.__getitem__.return_value = "odoo"
sys.modules["odoo.release"] = odoo.release
odoo.release.version_info = (14, 0)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def test_get_installed_modules(env):
def test_install_all(env):
odoo = sys.modules["odoo"] = mock.MagicMock()
sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()

env.install_all("odoo", ["module"])
odoo.modules.registry.Registry.new.assert_called_once_with(
Expand All @@ -101,6 +103,8 @@ def test_install_all(env):
def test_update_all(env):
odoo = sys.modules["odoo"] = mock.MagicMock()
sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()

env.update_specific("odoo", installed=True)
odoo.modules.registry.Registry.new.assert_called_once_with(
Expand All @@ -112,6 +116,8 @@ def test_update_all(env):
def test_update_listed(env):
odoo = sys.modules["odoo"] = mock.MagicMock()
sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()
env._get_modules = mock.MagicMock()

env.update_specific("odoo", listed=True)
Expand Down Expand Up @@ -143,6 +149,8 @@ def test_update(env):
# Quite complex and we have to mock plenty of stuff
odoo = sys.modules["odoo"] = mock.MagicMock()
tools = sys.modules["odoo.tools"] = mock.MagicMock()
sys.modules["odoo.modules"] = mock.MagicMock()
sys.modules["odoo.modules.registry"] = mock.MagicMock()
sys.modules["odoo.release"] = odoo.release
tools.config.__getitem__.return_value = "odoo"
odoo.release.version_info = (14, 0)
Expand Down

0 comments on commit b567782

Please sign in to comment.