Browse Source
Refactor tests of module 'base_exception'.
Refactor tests of module 'base_exception'.
Defines a new mechanism to build odoo classes that are only defined during testing.pull/1557/head
Jordi Ballester
7 years ago
committed by
Iván Todorovich
9 changed files with 109 additions and 133 deletions
-
3base_exception/__init__.py
-
1base_exception/__manifest__.py
-
28base_exception/models/base_exception.py
-
8base_exception/security/tmp_test_model_access_rule.xml
-
3base_exception/tests/__init__.py
-
14base_exception/tests/common.py
-
73base_exception/tests/purchase_test.py
-
35base_exception/tests/test_base_exception.py
-
77base_exception/tests/test_tmp_model.py
@ -1,5 +1,2 @@ |
|||
# Copyright 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import wizard, models |
|||
from .tests import test_tmp_model |
@ -1,8 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<data> |
|||
<function |
|||
model="base.exception" |
|||
name="_import_acl_for_tmp_test_model"/> |
|||
</data> |
|||
</odoo> |
@ -1,3 +1,4 @@ |
|||
|
|||
from . import test_tmp_model |
|||
from . import common |
|||
from . import purchase_test |
|||
from . import test_base_exception |
@ -0,0 +1,14 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 ACSONE SA/NV (<http://acsone.eu>) |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|||
|
|||
|
|||
def setup_test_model(env, model_clses): |
|||
for model_cls in model_clses: |
|||
model_cls._build_model(env.registry, env.cr) |
|||
|
|||
env.registry.setup_models(env.cr) |
|||
env.registry.init_models( |
|||
env.cr, [model_cls._name for model_cls in model_clses], |
|||
dict(env.context, update_custom_fields=True) |
|||
) |
@ -0,0 +1,73 @@ |
|||
# Copyright 2016 Akretion Mourad EL HADJ MIMOUNE |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|||
from odoo import api, fields, models |
|||
|
|||
|
|||
class PurchaseTest(models.Model): |
|||
_inherit = 'base.exception' |
|||
_name = "base.exception.test.purchase" |
|||
_description = "Base Ecxeption Test Model" |
|||
|
|||
rule_group = fields.Selection( |
|||
selection_add=[('test_base', 'test')], |
|||
default='test_base', |
|||
) |
|||
name = fields.Char(required=True) |
|||
user_id = fields.Many2one('res.users', string='Responsible') |
|||
state = fields.Selection( |
|||
[('draft', 'New'), ('cancel', 'Cancelled'), |
|||
('purchase', 'Purchase'), |
|||
('to approve', 'To approve'), ('done', 'Done')], |
|||
string="Status", readonly=True, default='draft') |
|||
active = fields.Boolean(default=True) |
|||
partner_id = fields.Many2one('res.partner', string='Partner') |
|||
line_ids = fields.One2many( |
|||
'base.exception.test.purchase.line', 'lead_id') |
|||
amount_total = fields.Float( |
|||
compute='_compute_amount_total', store=True) |
|||
|
|||
@api.depends('line_ids') |
|||
def _compute_amount_total(cls): |
|||
for record in cls: |
|||
for line in record.line_ids: |
|||
record.amount_total += line.amount * line.qty |
|||
|
|||
@api.constrains('ignore_exception', 'line_ids', 'state') |
|||
def test_purchase_check_exception(cls): |
|||
orders = cls.filtered(lambda s: s.state == 'purchase') |
|||
if orders: |
|||
orders._check_exception() |
|||
|
|||
@api.multi |
|||
def button_approve(cls, force=False): |
|||
cls.write({'state': 'to approve'}) |
|||
return {} |
|||
|
|||
@api.multi |
|||
def button_draft(cls): |
|||
cls.write({'state': 'draft'}) |
|||
return {} |
|||
|
|||
@api.multi |
|||
def button_confirm(cls): |
|||
cls.write({'state': 'purchase'}) |
|||
return True |
|||
|
|||
@api.multi |
|||
def button_cancel(cls): |
|||
cls.write({'state': 'cancel'}) |
|||
|
|||
def test_base_get_lines(cls): |
|||
cls.ensure_one() |
|||
return cls.line_ids |
|||
|
|||
|
|||
class LineTest(models.Model): |
|||
_name = "base.exception.test.purchase.line" |
|||
_description = "Base Exception Test Model Line" |
|||
|
|||
name = fields.Char() |
|||
lead_id = fields.Many2one('base.exception.test.purchase', |
|||
ondelete='cascade') |
|||
qty = fields.Float() |
|||
amount = fields.Float() |
@ -1,77 +0,0 @@ |
|||
# Copyright 2017 Akretion (http://www.akretion.com) |
|||
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com> |
|||
import os |
|||
from odoo import api, fields, models, tools |
|||
import logging |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
testing = tools.config.get('test_enable') or os.environ.get('ODOO_TEST_ENABLE') |
|||
if testing: |
|||
class PurchaseTest(models.Model): |
|||
_inherit = 'base.exception' |
|||
_name = "base.exception.test.purchase" |
|||
_description = "Base Ecxeption Test Model" |
|||
|
|||
rule_group = fields.Selection( |
|||
selection_add=[('test_base', 'test')], |
|||
default='test_base', |
|||
) |
|||
name = fields.Char(required=True) |
|||
user_id = fields.Many2one('res.users', string='Responsible') |
|||
state = fields.Selection( |
|||
[('draft', 'New'), ('cancel', 'Cancelled'), |
|||
('purchase', 'Purchase'), |
|||
('to approve', 'To approve'), ('done', 'Done')], |
|||
string="Status", readonly=True, default='draft') |
|||
active = fields.Boolean(default=True) |
|||
partner_id = fields.Many2one('res.partner', string='Partner') |
|||
line_ids = fields.One2many( |
|||
'base.exception.test.purchase.line', 'lead_id') |
|||
amount_total = fields.Float( |
|||
compute='_compute_amount_total', store=True) |
|||
|
|||
@api.depends('line_ids') |
|||
def _compute_amount_total(self): |
|||
for record in self: |
|||
for line in record.line_ids: |
|||
record.amount_total += line.amount * line.qty |
|||
|
|||
@api.constrains('ignore_exception', 'line_ids', 'state') |
|||
def test_purchase_check_exception(self): |
|||
orders = self.filtered(lambda s: s.state == 'purchase') |
|||
if orders: |
|||
orders._check_exception() |
|||
|
|||
@api.multi |
|||
def button_approve(self, force=False): |
|||
self.write({'state': 'to approve'}) |
|||
return {} |
|||
|
|||
@api.multi |
|||
def button_draft(self): |
|||
self.write({'state': 'draft'}) |
|||
return {} |
|||
|
|||
@api.multi |
|||
def button_confirm(self): |
|||
self.write({'state': 'purchase'}) |
|||
return True |
|||
|
|||
@api.multi |
|||
def button_cancel(self): |
|||
self.write({'state': 'cancel'}) |
|||
|
|||
def test_base_get_lines(self): |
|||
self.ensure_one() |
|||
return self.line_ids |
|||
|
|||
class LineTest(models.Model): |
|||
_name = "base.exception.test.purchase.line" |
|||
_description = "Base Ecxeption Test Model Line" |
|||
|
|||
name = fields.Char() |
|||
lead_id = fields.Many2one('base.exception.test.purchase', |
|||
ondelete='cascade') |
|||
qty = fields.Float() |
|||
amount = fields.Float() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue