Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] add base class for simplifying test in dependency
- Loading branch information
1 parent
ade11ae
commit 57c9e25
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com) | ||
# Copyright 2018 ACSONE SA/NV | ||
# Sébastien BEAU <sebastien.beau@akretion.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from uuid import uuid4 | ||
from random import randint | ||
import mock | ||
from odoo import api, models | ||
from odoo.fields import first | ||
from odoo.addons.component.tests.common import SavepointComponentCase | ||
|
||
|
||
class TestSeBackend(models.Model): | ||
_name = 'test.se.backend' | ||
_inherit = 'se.backend.spec.abstract' | ||
_description = 'Unit Test SE Backend' | ||
|
||
def init(self): | ||
self.env['se.backend'].register_spec_backend(self) | ||
|
||
def _register_hook(self): | ||
self.env['se.backend'].register_spec_backend(self) | ||
|
||
|
||
class TestSeBackendCase(SavepointComponentCase): | ||
""" | ||
Tests With a fake Se Backend | ||
""" | ||
|
||
def _init_test_model(self, model_cls): | ||
""" | ||
Function to init/create a new Odoo Model during unit test. | ||
Based on base_kanban_stage/test/test_base_kanban_abstract.py | ||
:param model_cls: Odoo Model class | ||
:return: instance of model (empty) | ||
""" | ||
registry = self.env.registry | ||
print 'enter' | ||
registry.enter_test_mode() | ||
cr = self.env.cr | ||
model_cls._build_model(registry, cr) | ||
model = self.env[model_cls._name].with_context(todo=[]) | ||
model._prepare_setup() | ||
model._setup_base(partial=False) | ||
model._setup_fields(partial=False) | ||
model._setup_complete() | ||
model._auto_init() | ||
model.init() | ||
model._auto_end() | ||
return self.env[model_cls._name] | ||
|
||
def setUp(self): | ||
super(TestSeBackendCase, self).setUp() | ||
# To load a new Model, we have to use a new cursor and env. | ||
# Because there is a commit on the model._auto_init() | ||
# Based on base_kanban_stage/test/test_base_kanban_abstract.py | ||
# self.registry.enter_test_mode() | ||
# self.old_cursor = self.cr | ||
# self.cr = self.registry.cursor() | ||
self.cr.commit = mock.MagicMock() | ||
self.env = api.Environment(self.cr, self.uid, {}) | ||
self._init_test_model(TestSeBackend) | ||
self.se_backend = self.env['test.se.backend'].create({ | ||
'specific_model': 'test.se.backend', | ||
}) | ||
|
||
def tearDown(self): | ||
print 'tear down' | ||
self.registry.leave_test_mode() | ||
#selection = (TestSeBackend._name, TestSeBackend._description) | ||
#self.env['test.se.backend']._fields.get('specific_model').selection( | ||
# test_model).remove(selection) | ||
super(TestSeBackendCase, self).tearDown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
connector | ||
server-tools | ||
ak-incubator-base-jsonify https://github.com/akretion/ak-odoo-incubator 10.0 | ||
queue https://github.com/akretion/queue 10.0-add-job-counter-for-test |