Skip to content

Commit

Permalink
[16.0][IMP] partner_identification: use odoo_test_helper in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Mar 3, 2023
1 parent be46e64 commit 3548f2b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
24 changes: 1 addition & 23 deletions partner_identification/tests/fake_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,10 @@
from odoo import fields, models


def setup_test_model(env, model_cls):
"""Pass a test model class and initialize it.
Courtesy of SBidoul from https://github.com/OCA/mis-builder :)
"""
model_cls._build_model(env.registry, env.cr)
env.registry.setup_models(env.cr)
env.registry.init_models(
env.cr, [model_cls._name], dict(env.context, update_custom_fields=True)
)


def teardown_test_model(env, model_cls):
"""Pass a test model class and deinitialize it.
Courtesy of SBidoul from https://github.com/OCA/mis-builder :)
"""
if not getattr(model_cls, "_teardown_no_delete", False):
del env.registry.models[model_cls._name]
env.registry.setup_models(env.cr)


class ResPartner(models.Model):
_name = "res.partner"
_inherit = "res.partner"
_teardown_no_delete = True
_description = "Fake Model"

social_security = fields.Char(
compute=lambda s: s._compute_identification("social_security", "SSN"),
Expand Down
14 changes: 10 additions & 4 deletions partner_identification/tests/test_res_partner.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo_test_helper import FakeModelLoader

from odoo.exceptions import ValidationError
from odoo.tests import common

from .fake_models import ResPartner, setup_test_model, teardown_test_model


class TestResPartner(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
setup_test_model(cls.env, ResPartner)

cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .fake_models import ResPartner

cls.loader.update_registry((ResPartner,))

bad_cat = cls.env["res.partner.id_category"].create(
{"code": "another_code", "name": "another_name"}
)
Expand All @@ -36,7 +42,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
teardown_test_model(cls.env, ResPartner)
cls.loader.restore_registry()
super().tearDownClass()

def test_compute_identification(self):
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo-test-helper

0 comments on commit 3548f2b

Please sign in to comment.