Skip to content

Commit

Permalink
[ADD] test_helper_extended: extends test_helper with one more field i…
Browse files Browse the repository at this point in the history
…n test.mixin
  • Loading branch information
nilshamerlinck committed Oct 10, 2023
1 parent 9ccb57d commit 04987cd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ install:
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
- pip install -e .
- mv tests/test_helper test_helper
- mv tests/test_helper* .

script:
- travis_run_tests
Expand Down
1 change: 1 addition & 0 deletions tests/test_helper_extended/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions tests/test_helper_extended/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).


{
"name": "Test Helper Extended",
"summary": "Another fake module extending fake module Test Helper for testing",
"version": "0.0.0",
"category": "Uncategorized",
"website": "www.akretion.com",
"author": " Akretion",
"license": "LGPL-3",
"application": False,
"installable": True,
"external_dependencies": {"python": [], "bin": []},
"depends": ["test_helper"],
"data": [],
"demo": [],
"qweb": [],
}
1 change: 1 addition & 0 deletions tests/test_helper_extended/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_mixin
10 changes: 10 additions & 0 deletions tests/test_helper_extended/models/test_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models


class TestMixin(models.AbstractModel):
_inherit = "test.mixin"
_description = "Test Mixin Extension"

test_char_02 = fields.Char()
1 change: 1 addition & 0 deletions tests/test_helper_extended/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_registry
37 changes: 37 additions & 0 deletions tests/test_helper_extended/tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.release import version_info

if version_info[0] < 15:
from odoo.tests import SavepointCase as TransactionCase
else:
# Odoo 15 and later: TransactionCase rolls back between tests
from odoo.tests import TransactionCase

from odoo_test_helper import FakeModelLoader


class TestMixin(TransactionCase):
def test_mixin_after_reloading_parent_module(self):
self.assertIn("test.mixin", self.env.registry)
self.assertIn("test_char", self.env["test.mixin"]._fields)
self.assertIn("test_char_02", self.env["test.mixin"]._fields)

loader = FakeModelLoader(self.env, "odoo.addons.test_helper")
loader.backup_registry()

# trigger reload of parent module: test_helper
loader.update_registry(())

self.assertIn("test.mixin", self.env.registry)
self.assertIn("test_char", self.env["test.mixin"]._fields)
# new field should not be there anymore
self.assertNotIn("test_char_02", self.env["test.mixin"]._fields)

# but now we restore registry
loader.restore_registry()

self.assertIn("test.mixin", self.env.registry)
self.assertIn("test_char", self.env["test.mixin"]._fields)
# new field should be there again
self.assertIn("test_char_02", self.env["test.mixin"]._fields)

0 comments on commit 04987cd

Please sign in to comment.