odoo-test-helper
================
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. image:: https://badge.fury.io/py/odoo-test-helper.svg
:target: http://badge.fury.io/py/odoo-test-helper
odoo-test-helper is toolbox for writing odoo test
Loading Fake models
~~~~~~~~~~~~~~~~~~~
Sometime you build an abstract module that can be use by many modules.
In such case, if you want to test it with real records you need to register real models.
One solution is to create a `module_test` module
with a little implementation that use your abstract model.
One other solution is define test only models and load them in tests.
This lib makes this possible and easy.
Example
~~~~~~~
There is an example of test here:
* `test_example.py <https://github.com/akretion/odoo-test-helper/blob/master/tests/test_helper/tests/test_example.py>`_.
This example load the class ResPartner from the file:
* `models.py <https://github.com/akretion/odoo-test-helper/blob/master/tests/test_helper/tests/models.py>`_.
Real implementation case can be found in the following module
* `connector_search_engine <https://github.com/OCA/search-engine/tree/12.0/connector_search_engine>`_.
* `base_url <https://github.com/shopinvader/odoo-shopinvader/tree/12.0/base_url>`_.
How to import
~~~~~~~~~~~~~~~
Be carefull importing fake class must be done in the right way.
Importing a file will automatically add all the class in the "module_to_models"
variable. The import **must** be done after the backup !
Wrong way
----------
.. code-block:: python
from odoo.tests import SavepointCase
from odoo_test_helper import FakeModelLoader
# The fake class is imported here !! It's wrong
# And be carefull even if you only import ResPartner
# all class in the file models will be proceded by odoo
# so no **direct import** of a file that contain fake model
from .models import ResPartner
class TestMixin(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestMixin, cls).setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
cls.loader.update_registry((ResPartner,))
@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
super(TestMixin, cls).tearDownClass()
def test_create(self):
partner = self.env["res.partner"].create({"name": "BAR", "test_char": "youhou"})
self.assertEqual(partner.name, "FOO-BAR")
self.assertEqual(partner.test_char, "youhou")
Right Way
----------
.. code-block:: python
from odoo.tests import SavepointCase
from odoo_test_helper import FakeModelLoader
class TestMixin(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestMixin, cls).setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
# The fake class is imported here !! After the backup_registry
from .models import ResPartner
cls.loader.update_registry((ResPartner,))
@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
super(TestMixin, cls).tearDownClass()
def test_create(self):
partner = self.env["res.partner"].create({"name": "BAR", "test_char": "youhou"})
self.assertEqual(partner.name, "FOO-BAR")
self.assertEqual(partner.test_char, "youhou")
Contributor
~~~~~~~~~~~~
* Sébastien BEAU <sebastien.beau@akretion.com>
* Laurent Mignon <laurent.mignon@acsone.eu>
* Simone Orsi <simone.orsi@camptocamp.com>
History
~~~~~~~~
This module is inspired of the following mixin code that can be found in OCA and shopinvader repository
* Mixin in OCA: https://github.com/OCA/search-engine/blob/7fd85a74180cfff30e212fca01ebeba6c54ee294/connector_search_engine/tests/models_mixin.py
* Mixin in Shopinvader: https://github.com/shopinvader/odoo-shopinvader/blob/b81b921ea52c911e5b33afac88adb8f9a1c02626/base_url/tests/models_mixin.py
Intial Authors are
* Laurent Mignon <laurent.mignon@acsone.eu>
* Simone Orsi <simone.orsi@camptocamp.com>
Refactor/extraction have been done by
* Sébastien BEAU <sebastien.beau@akretion.com>
This refactor try to load all class correctly like Odoo does with the exact same syntax
Note this refactor/extraction have been done to fix the test of the following issue
https://github.com/shopinvader/odoo-shopinvader/pull/607
Changes
~~~~~~~
.. Future (?)
.. ----------
.. - ...
2.1.1
-----
[FIX] FakeModelLoader: avoid loading module again on restore_registry() for Odoo 15.0+
[FIX] Ensures registy is cleaned up in addons without models
2.1.0
-----
- [IMP] Allow to ignore Odoo core modules to avoid warning
2.0.5
-----
- .gitignore added
2.0.4
-----
- [FIX] AttributeError in Odoo 15+, regression introduced in 2.0.3
2.0.3
-----
- [FIX] restore_registry in Odoo 16
See odoo/odoo@cd12293
This new attribute is the source of truth for the base classes
and in setup_models (called further down in the modified code in this PR),
the model's base classes are reset from it:
https://github.com/odoo/odoo/blob/e1f06479a526c703ccabc441b1e194646206b966/odoo/models.py#L2728-L2730.
The test failure fixed by this PR can be inspected in
https://app.travis-ci.com/github/OCA/odoo-test-helper/builds/258453331
2.0.2
-----
- Fix ``mock`` import for v15
2.0.1
-----
- Fix support for Odoo 15.0
2.0.0
-----
- Move to OCA
- Re-license to LGPL
1.1.0
-----
- Refactoring (misc imp/fix)
1.0.0
-----
- Initial release
Raw data
{
"_id": null,
"home_page": "http://github.com/OCA/odoo-test-helper",
"name": "odoo-test-helper",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Odoo Community Association (OCA)",
"author_email": "support@odoo-community.org",
"download_url": "https://files.pythonhosted.org/packages/46/bc/fb54851788e4eecce0ad458221f3dfe3711dbeee7fd2b64d7263646238fc/odoo-test-helper-2.1.1.tar.gz",
"platform": null,
"description": "odoo-test-helper\n================\n\n.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.png\n :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html\n :alt: License: LGPL-3\n.. image:: https://badge.fury.io/py/odoo-test-helper.svg\n :target: http://badge.fury.io/py/odoo-test-helper\n\nodoo-test-helper is toolbox for writing odoo test\n\n\nLoading Fake models\n~~~~~~~~~~~~~~~~~~~\n\nSometime you build an abstract module that can be use by many modules.\nIn such case, if you want to test it with real records you need to register real models.\n\nOne solution is to create a `module_test` module\nwith a little implementation that use your abstract model.\n\nOne other solution is define test only models and load them in tests.\nThis lib makes this possible and easy.\n\nExample\n~~~~~~~\n\nThere is an example of test here:\n\n* `test_example.py <https://github.com/akretion/odoo-test-helper/blob/master/tests/test_helper/tests/test_example.py>`_.\n\nThis example load the class ResPartner from the file:\n\n* `models.py <https://github.com/akretion/odoo-test-helper/blob/master/tests/test_helper/tests/models.py>`_.\n\n\nReal implementation case can be found in the following module\n\n* `connector_search_engine <https://github.com/OCA/search-engine/tree/12.0/connector_search_engine>`_.\n* `base_url <https://github.com/shopinvader/odoo-shopinvader/tree/12.0/base_url>`_.\n\n\nHow to import\n~~~~~~~~~~~~~~~\n\nBe carefull importing fake class must be done in the right way.\nImporting a file will automatically add all the class in the \"module_to_models\"\nvariable. The import **must** be done after the backup !\n\n\n\n\n\n\nWrong way\n----------\n\n\n.. code-block:: python\n\n from odoo.tests import SavepointCase\n\n from odoo_test_helper import FakeModelLoader\n\n # The fake class is imported here !! It's wrong\n # And be carefull even if you only import ResPartner\n # all class in the file models will be proceded by odoo\n # so no **direct import** of a file that contain fake model\n from .models import ResPartner\n\n\n\n\n\n class TestMixin(SavepointCase):\n @classmethod\n def setUpClass(cls):\n super(TestMixin, cls).setUpClass()\n cls.loader = FakeModelLoader(cls.env, cls.__module__)\n cls.loader.backup_registry()\n\n cls.loader.update_registry((ResPartner,))\n\n @classmethod\n def tearDownClass(cls):\n cls.loader.restore_registry()\n super(TestMixin, cls).tearDownClass()\n\n def test_create(self):\n partner = self.env[\"res.partner\"].create({\"name\": \"BAR\", \"test_char\": \"youhou\"})\n self.assertEqual(partner.name, \"FOO-BAR\")\n self.assertEqual(partner.test_char, \"youhou\")\n\n\nRight Way\n----------\n\n.. code-block:: python\n\n from odoo.tests import SavepointCase\n\n from odoo_test_helper import FakeModelLoader\n\n\n class TestMixin(SavepointCase):\n @classmethod\n def setUpClass(cls):\n super(TestMixin, cls).setUpClass()\n cls.loader = FakeModelLoader(cls.env, cls.__module__)\n cls.loader.backup_registry()\n\n # The fake class is imported here !! After the backup_registry\n from .models import ResPartner\n\n cls.loader.update_registry((ResPartner,))\n\n @classmethod\n def tearDownClass(cls):\n cls.loader.restore_registry()\n super(TestMixin, cls).tearDownClass()\n\n def test_create(self):\n partner = self.env[\"res.partner\"].create({\"name\": \"BAR\", \"test_char\": \"youhou\"})\n self.assertEqual(partner.name, \"FOO-BAR\")\n self.assertEqual(partner.test_char, \"youhou\")\n\n\n\n\nContributor\n~~~~~~~~~~~~\n\n* S\u00e9bastien BEAU <sebastien.beau@akretion.com>\n* Laurent Mignon <laurent.mignon@acsone.eu>\n* Simone Orsi <simone.orsi@camptocamp.com>\n\n\nHistory\n~~~~~~~~\n\nThis module is inspired of the following mixin code that can be found in OCA and shopinvader repository\n\n* Mixin in OCA: https://github.com/OCA/search-engine/blob/7fd85a74180cfff30e212fca01ebeba6c54ee294/connector_search_engine/tests/models_mixin.py\n\n* Mixin in Shopinvader: https://github.com/shopinvader/odoo-shopinvader/blob/b81b921ea52c911e5b33afac88adb8f9a1c02626/base_url/tests/models_mixin.py\n\nIntial Authors are\n\n* Laurent Mignon <laurent.mignon@acsone.eu>\n* Simone Orsi <simone.orsi@camptocamp.com>\n\nRefactor/extraction have been done by\n\n* S\u00e9bastien BEAU <sebastien.beau@akretion.com>\n\nThis refactor try to load all class correctly like Odoo does with the exact same syntax\n\nNote this refactor/extraction have been done to fix the test of the following issue\n\nhttps://github.com/shopinvader/odoo-shopinvader/pull/607\n\nChanges\n~~~~~~~\n\n.. Future (?)\n.. ----------\n.. - ...\n\n2.1.1\n-----\n\n[FIX] FakeModelLoader: avoid loading module again on restore_registry() for Odoo 15.0+\n[FIX] Ensures registy is cleaned up in addons without models\n\n\n2.1.0\n-----\n\n- [IMP] Allow to ignore Odoo core modules to avoid warning\n\n2.0.5\n-----\n\n- .gitignore added\n\n2.0.4\n-----\n\n- [FIX] AttributeError in Odoo 15+, regression introduced in 2.0.3\n\n2.0.3\n-----\n\n- [FIX] restore_registry in Odoo 16\n\n See odoo/odoo@cd12293\n\n This new attribute is the source of truth for the base classes\n and in setup_models (called further down in the modified code in this PR),\n the model's base classes are reset from it:\n\n https://github.com/odoo/odoo/blob/e1f06479a526c703ccabc441b1e194646206b966/odoo/models.py#L2728-L2730.\n\n The test failure fixed by this PR can be inspected in\n https://app.travis-ci.com/github/OCA/odoo-test-helper/builds/258453331\n\n\n2.0.2\n-----\n\n- Fix ``mock`` import for v15\n\n2.0.1\n-----\n\n- Fix support for Odoo 15.0\n\n\n2.0.0\n-----\n\n- Move to OCA\n- Re-license to LGPL\n\n\n1.1.0\n-----\n\n- Refactoring (misc imp/fix)\n\n\n1.0.0\n-----\n\n- Initial release\n",
"bugtrack_url": null,
"license": "LGPLv3+",
"summary": "Odoo Test Helper",
"version": "2.1.1",
"project_urls": {
"Homepage": "http://github.com/OCA/odoo-test-helper"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a27a56f7a00207d65ed5e877ecbb254b4656e241abd0688f720827f300092a7f",
"md5": "a94960352306f6fc6baef7264a451cf9",
"sha256": "08c3a2f7a4ba1971eb8dab46c36c0f24f2dca735021c92929f5629adaf23b219"
},
"downloads": -1,
"filename": "odoo_test_helper-2.1.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "a94960352306f6fc6baef7264a451cf9",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6279,
"upload_time": "2023-10-17T08:41:39",
"upload_time_iso_8601": "2023-10-17T08:41:39.877842Z",
"url": "https://files.pythonhosted.org/packages/a2/7a/56f7a00207d65ed5e877ecbb254b4656e241abd0688f720827f300092a7f/odoo_test_helper-2.1.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "46bcfb54851788e4eecce0ad458221f3dfe3711dbeee7fd2b64d7263646238fc",
"md5": "4981f4a63c6e129e84369762a5b77048",
"sha256": "d5a511ebdbab2004a7721f4b9bf02ef5c419c178cd85d60feb25440b5adba69a"
},
"downloads": -1,
"filename": "odoo-test-helper-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "4981f4a63c6e129e84369762a5b77048",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11182,
"upload_time": "2023-10-17T08:41:41",
"upload_time_iso_8601": "2023-10-17T08:41:41.175974Z",
"url": "https://files.pythonhosted.org/packages/46/bc/fb54851788e4eecce0ad458221f3dfe3711dbeee7fd2b64d7263646238fc/odoo-test-helper-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-17 08:41:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "OCA",
"github_project": "odoo-test-helper",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"lcname": "odoo-test-helper"
}