Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] component: Migration to 15.0 #423

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^component/|
^component_event/|
^connector/|
^connector_base_product/|
Expand Down
18 changes: 11 additions & 7 deletions component/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Components
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector-lightgray.png?logo=github
:target: https://github.com/OCA/connector/tree/14.0/component
:target: https://github.com/OCA/connector/tree/15.0/component
:alt: OCA/connector
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/connector-14-0/connector-14-0-component
:target: https://translation.odoo-community.org/projects/connector-15-0/connector-15-0-component
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/102/14.0
:target: https://runbot.odoo-community.org/runbot/102/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -63,10 +63,9 @@ component level)::


In order for tests using components to work, you will need to use the base
classes provided by `odoo.addons.component.tests.common`:
class provided by `odoo.addons.component.tests.common`:

* `TransactionComponentCase`
* `SavepointComponentCase`

There are also some specific base classes for testing the component registry,
using the ComponentRegistryCase as a base class. See the docstrings in
Expand All @@ -85,6 +84,11 @@ Changelog
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ]

15.0.1.0.0 (2021-11-25)
~~~~~~~~~~~~~~~~~~~~~~~

* [MIGRATION] from 14.0

14.0.1.0.0 (2020-10-22)
~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -106,7 +110,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/connector/issues/new?body=module:%20component%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/connector/issues/new?body=module:%20component%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -145,6 +149,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-guewen|

This module is part of the `OCA/connector <https://github.com/OCA/connector/tree/14.0/component>`_ project on GitHub.
This module is part of the `OCA/connector <https://github.com/OCA/connector/tree/15.0/component>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions component/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Components",
"summary": "Add capabilities to register and use decoupled components,"
" as an alternative to model classes",
"version": "14.0.1.1.0",
"version": "15.0.1.0.0",
"author": "Camptocamp," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/connector",
"license": "LGPL-3",
Expand All @@ -16,7 +16,7 @@
"cachetools",
]
},
"installable": False,
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["guewen"],
}
2 changes: 1 addition & 1 deletion component/i18n/component.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down
5 changes: 5 additions & 0 deletions component/readme/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ]

15.0.1.0.0 (2021-11-25)
~~~~~~~~~~~~~~~~~~~~~~~

* [MIGRATION] from 14.0

14.0.1.0.0 (2020-10-22)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 1 addition & 2 deletions component/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ component level)::


In order for tests using components to work, you will need to use the base
classes provided by `odoo.addons.component.tests.common`:
class provided by `odoo.addons.component.tests.common`:

* `TransactionComponentCase`
* `SavepointComponentCase`

There are also some specific base classes for testing the component registry,
using the ComponentRegistryCase as a base class. See the docstrings in
Expand Down
32 changes: 19 additions & 13 deletions component/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Components</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/connector/tree/14.0/component"><img alt="OCA/connector" src="https://img.shields.io/badge/github-OCA%2Fconnector-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/connector-14-0/connector-14-0-component"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/102/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/connector/tree/15.0/component"><img alt="OCA/connector" src="https://img.shields.io/badge/github-OCA%2Fconnector-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/connector-15-0/connector-15-0-component"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/102/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module implements a component system and is a base block for the Connector
Framework. It can be used without using the full Connector though.</p>
<p>Documentation: <a class="reference external" href="http://odoo-connector.com/">http://odoo-connector.com/</a></p>
Expand All @@ -376,9 +376,10 @@ <h1 class="title">Components</h1>
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id4">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="id5">Changelog</a><ul>
<li><a class="reference internal" href="#id1" id="id6">14.0.1.0.0 (2020-10-22)</a></li>
<li><a class="reference internal" href="#id2" id="id7">13.0.1.0.0 (2019-10-23)</a></li>
<li><a class="reference internal" href="#id3" id="id8">12.0.1.0.0 (2018-10-02)</a></li>
<li><a class="reference internal" href="#id1" id="id6">15.0.1.0.0 (2021-11-25)</a></li>
<li><a class="reference internal" href="#id2" id="id7">14.0.1.0.0 (2020-10-22)</a></li>
<li><a class="reference internal" href="#id3" id="id8">13.0.1.0.0 (2019-10-23)</a></li>
<li><a class="reference internal" href="#id4" id="id9">12.0.1.0.0 (2018-10-02)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="id9">Bug Tracker</a></li>
Expand Down Expand Up @@ -414,10 +415,9 @@ <h1><a class="toc-backref" href="#id4">Usage</a></h1>
external_data = backend_adapter.read(external_id)
</pre>
<p>In order for tests using components to work, you will need to use the base
classes provided by <cite>odoo.addons.component.tests.common</cite>:</p>
class provided by <cite>odoo.addons.component.tests.common</cite>:</p>
<ul class="simple">
<li><cite>TransactionComponentCase</cite></li>
<li><cite>SavepointComponentCase</cite></li>
</ul>
<p>There are also some specific base classes for testing the component registry,
using the ComponentRegistryCase as a base class. See the docstrings in
Expand All @@ -435,19 +435,25 @@ <h1><a class="toc-backref" href="#id5">Changelog</a></h1>
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ] -->
<div class="section" id="id1">
<h2><a class="toc-backref" href="#id6">14.0.1.0.0 (2020-10-22)</a></h2>
<h2><a class="toc-backref" href="#id6">15.0.1.0.0 (2021-11-25)</a></h2>
<ul class="simple">
<li>[MIGRATION] from 14.0</li>
</ul>
</div>
<div class="section" id="id2">
<h2><a class="toc-backref" href="#id7">14.0.1.0.0 (2020-10-22)</a></h2>
<ul class="simple">
<li>[MIGRATION] from 13.0</li>
</ul>
</div>
<div class="section" id="id2">
<h2><a class="toc-backref" href="#id7">13.0.1.0.0 (2019-10-23)</a></h2>
<div class="section" id="id3">
<h2><a class="toc-backref" href="#id8">13.0.1.0.0 (2019-10-23)</a></h2>
<ul class="simple">
<li>[MIGRATION] from 12.0</li>
</ul>
</div>
<div class="section" id="id3">
<h2><a class="toc-backref" href="#id8">12.0.1.0.0 (2018-10-02)</a></h2>
<div class="section" id="id4">
<h2><a class="toc-backref" href="#id9">12.0.1.0.0 (2018-10-02)</a></h2>
<ul class="simple">
<li>[MIGRATION] from 11.0 branched at rev. 324e006</li>
</ul>
Expand All @@ -458,7 +464,7 @@ <h1><a class="toc-backref" href="#id9">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/connector/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/connector/issues/new?body=module:%20component%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/connector/issues/new?body=module:%20component%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -485,7 +491,7 @@ <h2><a class="toc-backref" href="#id13">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/guewen"><img alt="guewen" src="https://github.com/guewen.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector/tree/14.0/component">OCA/connector</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector/tree/15.0/component">OCA/connector</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
95 changes: 26 additions & 69 deletions component/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

import copy
import sys
import unittest
from contextlib import contextmanager

Expand Down Expand Up @@ -83,28 +82,6 @@ def setUp(self):
)


class SavepointComponentCase(common.SavepointCase, ComponentMixin):
simahawk marked this conversation as resolved.
Show resolved Hide resolved
"""A SavepointCase that loads all the components

It it used like an usual Odoo's SavepointCase, but it ensures
that all the components of the current addon and its dependencies
are loaded.

"""

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.setUpComponent()

# pylint: disable=W8106
def setUp(self):
# resolve an inheritance issue (common.SavepointCase does not call
# super)
common.SavepointCase.setUp(self)
ComponentMixin.setUp(self)


class ComponentRegistryCase(
unittest.TestCase, common.MetaCase("DummyCase", (object,), {})
):
Expand All @@ -115,10 +92,9 @@ class ComponentRegistryCase(
or not, or when you want to create additional components in your tests.

If you only want to *use* the components of the tested addon in your tests,
then consider using one of:
then consider using:

* :class:`TransactionComponentCase`
* :class:`SavepointComponentCase`

This test case creates a special
:class:`odoo.addons.component.core.ComponentRegistry` for the purpose of
Expand Down Expand Up @@ -152,32 +128,6 @@ class ComponentRegistryCase(

"""

if sys.version_info < (3, 8):
# Copy/paste from
# https://github.com/odoo/odoo/blob/0218d870d319af4f263d5e9aa324990f7cc90139/
# odoo/tests/common.py#L248-L268
# Partial backport of bpo-24412, merged in CPython 3.8
_class_cleanups = []

@classmethod
def addClassCleanup(cls, function, *args, **kwargs):
"""Same as addCleanup, except the cleanup items are called even if
setUpClass fails (unlike tearDownClass). Backport of bpo-24412."""
cls._class_cleanups.append((function, args, kwargs))

@classmethod
def doClassCleanups(cls):
"""Execute all class cleanup functions.
Normally called for you after tearDownClass.
Backport of bpo-24412."""
cls.tearDown_exceptions = []
while cls._class_cleanups:
function, args, kwargs = cls._class_cleanups.pop()
try:
function(*args, **kwargs)
except Exception:
cls.tearDown_exceptions.append(sys.exc_info())

@staticmethod
def _setup_registry(class_or_instance):
# keep the original classes registered by the metaclass
Expand Down Expand Up @@ -231,34 +181,41 @@ def _build_components(self, *classes):


class TransactionComponentRegistryCase(common.TransactionCase, ComponentRegistryCase):
"""Adds Odoo Transaction in the base Component TestCase"""
"""Adds Odoo Transaction in the base Component TestCase.

# pylint: disable=W8106
def setUp(self):
# resolve an inheritance issue (common.TransactionCase does not use
# super)
common.TransactionCase.setUp(self)
ComponentRegistryCase._setup_registry(self)
self.collection = self.env["collection.base"]
This class doesn't set up the registry for you.
You're supposed to explicitly call `_setup_registry` and `_teardown_registry`
when you need it, either on setUpClass and tearDownClass or setUp and tearDown.
yankinmax marked this conversation as resolved.
Show resolved Hide resolved

class MyTestCase(TransactionComponentRegistryCase):
def setUp(self):
super().setUp()
self._setup_registry(self)

def tearDown(self):
ComponentRegistryCase._teardown_registry(self)
common.TransactionCase.tearDown(self)
def tearDown(self):
self._teardown_registry(self)
super().tearDown()

class MyTestCase(TransactionComponentRegistryCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._setup_registry(cls)

class SavepointComponentRegistryCase(common.SavepointCase, ComponentRegistryCase):
"""Adds Odoo Transaction with Savepoint in the base Component TestCase"""
@classmethod
def tearDownClass(cls):
cls._teardown_registry(cls)
super().tearDownClass()
"""

# pylint: disable=W8106
@classmethod
def setUpClass(cls):
# resolve an inheritance issue (common.SavepointCase does not use
# resolve an inheritance issue (common.TransactionCase does not use
# super)
common.SavepointCase.setUpClass()
ComponentRegistryCase._setup_registry(cls)
common.TransactionCase.setUpClass()
cls.collection = cls.env["collection.base"]

@classmethod
def tearDownClass(cls):
ComponentRegistryCase._teardown_registry(cls)
common.SavepointCase.tearDownClass()
common.TransactionCase.tearDownClass()
12 changes: 12 additions & 0 deletions component/tests/test_build_component.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright 2017 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

# Tell pylint to not bother us for all our fake component classes
# pylint: disable=consider-merging-classes-inherited

import mock

from odoo.addons.component.core import AbstractComponent, Component
Expand All @@ -24,6 +27,14 @@ class TestBuildComponent(TransactionComponentRegistryCase):

"""

def setUp(self):
super().setUp()
self._setup_registry(self)

def tearDown(self):
self._teardown_registry(self)
super().tearDown()

def test_no_name(self):
"""Ensure that a component has a _name"""

Expand Down Expand Up @@ -113,6 +124,7 @@ class Component4(Component):
self.comp_registry["component4"].__bases__,
)

# pylint: disable=W8110
def test_custom_build(self):
"""Check that we can hook at the end of a Component build"""

Expand Down
8 changes: 7 additions & 1 deletion component/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ class TestComponent(TransactionComponentRegistryCase):

def setUp(self):
super().setUp()
self.collection = self.env["collection.base"]
self._setup_registry(self)
self._setUpComponents()

def tearDown(self):
self._teardown_registry(self)
super().tearDown()

def _setUpComponents(self):
# create some Component to play with
class Component1(Component):
_name = "component1"
Expand Down
Loading