Browse Source

partner_identification: fix/imp tests on res.partner

pull/644/head
Simone Orsi 7 years ago
committed by tarteo
parent
commit
32fec0e2fd
  1. 4
      partner_identification/README.rst
  2. 3
      partner_identification/__init__.py
  3. 4
      partner_identification/__manifest__.py
  4. 3
      partner_identification/models/__init__.py
  5. 2
      partner_identification/models/res_partner.py
  6. 2
      partner_identification/models/res_partner_id_category.py
  7. 2
      partner_identification/models/res_partner_id_number.py
  8. 3
      partner_identification/tests/__init__.py
  9. 47
      partner_identification/tests/fake_models.py
  10. 19
      partner_identification/tests/test_partner_identification.py
  11. 71
      partner_identification/tests/test_res_partner.py

4
partner_identification/README.rst

@ -1,4 +1,4 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
@ -21,7 +21,7 @@ and vary from country to country.
Installation
============
No specific installation step required
No specific installation step required.
Configuration

3
partner_identification/__init__.py

@ -1,4 +1 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

4
partner_identification/__manifest__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2004-2010 Tiny SPRL http://tiny.be
# Copyright 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
# http://www.camptocamp.at
@ -28,5 +26,5 @@
'ACSONE SA/NV,'
'LasLabs,'
'Odoo Community Association (OCA)',
'website': 'https://odoo-community.org/',
'website': 'https://github.com/OCA/partner-contact',
}

3
partner_identification/models/__init__.py

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner_id_number
from . import res_partner_id_category
from . import res_partner

2
partner_identification/models/res_partner.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2004-2010 Tiny SPRL http://tiny.be
# Copyright 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
# http://www.camptocamp.at

2
partner_identification/models/res_partner_id_category.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2004-2010 Tiny SPRL http://tiny.be
# Copyright 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
# http://www.camptocamp.at

2
partner_identification/models/res_partner_id_number.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2004-2010 Tiny SPRL http://tiny.be
# Copyright 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
# http://www.camptocamp.at

3
partner_identification/tests/__init__.py

@ -1,5 +1,2 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_partner_identification
from . import test_res_partner

47
partner_identification/tests/fake_models.py

@ -0,0 +1,47 @@
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE
# Copyright 2018 Camptocamp
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
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
social_security = fields.Char(
compute=lambda s: s._compute_identification(
'social_security', 'SSN',
),
inverse=lambda s: s._inverse_identification(
'social_security', 'SSN',
),
search=lambda s, *a: s._search_identification(
'SSN', *a
),
)

19
partner_identification/tests/test_partner_identification.py

@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from psycopg2._psycopg import IntegrityError
from odoo.tests import common
from odoo.exceptions import ValidationError
from odoo.tools import mute_logger
class TestPartnerIdentificationBase(common.TransactionCase):
def test_base_functionalities(self):
"""Dummy CRUD test
"""
def test_create_id_category(self):
partner_id_category = self.env['res.partner.id_category'].create({
'code': 'id_code',
'name': 'id_name',
@ -18,13 +16,22 @@ class TestPartnerIdentificationBase(common.TransactionCase):
self.assertEqual(partner_id_category.name, 'id_name')
self.assertEqual(partner_id_category.code, 'id_code')
@mute_logger('odoo.sql_db')
def test_update_partner_with_no_category(self):
partner_1 = self.env.ref('base.res_partner_1')
self.assertEqual(len(partner_1.id_numbers), 0)
# create without required category
with self.assertRaises(IntegrityError), self.cr.savepoint():
with self.assertRaises(IntegrityError):
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',
})]})
def test_update_partner_with_category(self):
partner_1 = self.env.ref('base.res_partner_1')
partner_id_category = self.env['res.partner.id_category'].create({
'code': 'new_code',
'name': 'new_name',
})
# successful creation
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',

71
partner_identification/tests/test_res_partner.py

@ -1,80 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo.tests import common
from odoo.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = 'res.partner'
social_security = fields.Char(
compute=lambda s: s._compute_identification(
'social_security', 'SSN',
),
inverse=lambda s: s._inverse_identification(
'social_security', 'SSN',
),
search=lambda s, *a: s._search_identification(
'SSN', *a
),
)
from .fake_models import ResPartner, setup_test_model, teardown_test_model
class TestResPartner(common.SavepointCase):
@classmethod
def _init_test_model(cls, model_cls):
""" Build a model from model_cls in order to test abstract models.
Note that this does not actually create a table in the database, so
there may be some unidentified edge cases.
Args:
model_cls (openerp.models.BaseModel): Class of model to initialize
Returns:
model_cls: Instance
"""
registry = cls.env.registry
cr = cls.env.cr
inst = model_cls._build_model(registry, cr)
model = cls.env[model_cls._inherit].with_context(todo=[])
model._prepare_setup()
model._setup_base()
model._setup_fields()
model._setup_complete()
model._auto_init()
model.init()
return inst
at_install = False
post_install = True
@classmethod
def setUpClass(cls):
super(TestResPartner, cls).setUpClass()
cls.env.registry.enter_test_mode()
cls._init_test_model(ResPartner)
def setUp(self):
super(TestResPartner, self).setUp()
bad_cat = self.env['res.partner.id_category'].create({
super().setUpClass()
setup_test_model(cls.env, ResPartner)
bad_cat = cls.env['res.partner.id_category'].create({
'code': 'another_code',
'name': 'another_name',
})
self.env['res.partner.id_number'].create({
cls.env['res.partner.id_number'].create({
'name': 'Bad ID',
'category_id': bad_cat.id,
'partner_id': self.env.user.partner_id.id,
'partner_id': cls.env.user.partner_id.id,
})
self.partner_id_category = self.env['res.partner.id_category'].create({
cls.partner_id_category = cls.env['res.partner.id_category'].create({
'code': 'id_code',
'name': 'id_name',
})
self.partner = self.env.user.partner_id
self.partner_id = self.env['res.partner.id_number'].create({
cls.partner = cls.env.user.partner_id
cls.partner_id = cls.env['res.partner.id_number'].create({
'name': 'Good ID',
'category_id': self.partner_id_category.id,
'partner_id': self.partner.id,
'category_id': cls.partner_id_category.id,
'partner_id': cls.partner.id,
})
@classmethod
def tearDownClass(cls):
teardown_test_model(cls.env, ResPartner)
super().tearDownClass()
def test_compute_identification(self):
""" It should set the proper field to the proper ID name. """
self.partner._compute_identification('name', 'id_code')

Loading…
Cancel
Save