Skip to content

Commit

Permalink
adapt test class method for product
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu.saison committed Sep 18, 2023
1 parent 47dcb85 commit 801f744
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo.addons.shopinvader_locomotive.tests.test_shopinvader_partner import (
CommonShopinvaderPartner,
)
from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin

_logger = logging.getLogger(__name__)

Expand All @@ -18,7 +19,7 @@
_logger.debug(err)


class TestShopinvaderWishlistSync(CommonShopinvaderPartner):
class TestShopinvaderWishlistSync(CommonShopinvaderPartner, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_product_binding/models/shopinvader_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ShopinvaderBackend(models.Model):
"etc.",
)
filter_ids = fields.Many2many(comodel_name="product.filter", string="Filter")

@api.model
def _to_compute_nbr_content(self):
"""
Expand Down
43 changes: 43 additions & 0 deletions shopinvader_product_binding/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,46 @@ def setUpClass(cls):
cls.base_pricelist = cls.env.ref("product.list0")
cls.base_pricelist.currency_id = cls.env.ref("base.USD")
cls.shopinvader_variant.record_id.currency_id = cls.env.ref("base.USD")


class ProductUtilsMixin(CommonCase):
def _bind_products(self, products, backend=None):
backend = backend or self.backend
bind_wizard_model = self.env["shopinvader.variant.binding.wizard"]
bind_wizard = bind_wizard_model.create(
{
"backend_id": backend.id,
"product_ids": [(6, 0, products.ids)],
"run_immediately": True,
}
)
bind_wizard.bind_products()

def _refresh_json_data(self, products, backend=None):
"""Force recomputation of JSON data for given products.
Especially helpful if your module adds new JSON keys
but the product are already there and computed w/out your key.
"""
if not products:
return
backend = backend or self.backend
# TODO: remove hasattr check once `jsonify_stored` is ready.
# The json-store machinery comes from search engine module.
# We rely on it for product data BUT only
# `shopinvader_search_engine` requires that dependency.
# Hence, tests that need fresh product data because they add
# new keys to ir.exports record will be broken w/out refresh
# IF `shopinvader_search_engine` is installed (like on Travis).
# `jsonify_stored` will extrapolate the feature
# and allow to get rid of this hack.
# For full story see
# https://github.com/shopinvader/odoo-shopinvader/pull/783
if not hasattr(self.env["shopinvader.variant"], "recompute_json"):
return
invader_variants = products
if invader_variants._name == "product.product":
invader_variants = products.shopinvader_bind_ids
invader_variants.filtered_domain(
[("backend_id", "=", backend.id)]
).recompute_json()
4 changes: 3 additions & 1 deletion shopinvader_product_binding/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from odoo import fields
from odoo.tools import mute_logger

from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin

from .common import ProductCommonCase


class ProductCase(ProductCommonCase):
class ProductCase(ProductCommonCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from odoo.addons.component.tests.common import ComponentRegistryCase
from odoo.addons.product_seasonality.tests.common import CommonCaseWithLines
from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import UtilsMixin

# Reminders for lines' data (from CommonCaseWithLines):
Expand Down Expand Up @@ -39,7 +40,7 @@


class TestProductSeasonalityCase(
CommonCaseWithLines, UtilsMixin, ComponentRegistryCase
CommonCaseWithLines, UtilsMixin, ComponentRegistryCase, ProductUtilsMixin
):
@classmethod
def setUpClass(cls):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.component.tests.common import ComponentRegistryCase
from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import UtilsMixin
from odoo.addons.shopinvader_search_engine.tests.test_backend import BackendCaseBase

Expand Down Expand Up @@ -41,7 +42,9 @@ def _create_line(self, **kw):
return self.env["shopinvader.seasonal.config.line"].create(vals)


class TestProductSeasonalityCaseNoJobs(TestProductSeasonalityCaseBase):
class TestProductSeasonalityCaseNoJobs(
TestProductSeasonalityCaseBase, ProductUtilsMixin
):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
3 changes: 2 additions & 1 deletion shopinvader_product_stock/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import UtilsMixin

from .common import StockCommonCase


class TestProductProduct(StockCommonCase, UtilsMixin):
class TestProductProduct(StockCommonCase, UtilsMixin, ProductUtilsMixin):
"""Tests for product stock info."""

def _expectect_qty_by_wh(self, warehouse_recs, prod):
Expand Down
41 changes: 0 additions & 41 deletions shopinvader_restapi/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,6 @@ def _install_lang_odoo(env, lang_xml_id, full_install=False):


class UtilsMixin(object):
def _bind_products(self, products, backend=None):
backend = backend or self.backend
bind_wizard_model = self.env["shopinvader.variant.binding.wizard"]
bind_wizard = bind_wizard_model.create(
{
"backend_id": backend.id,
"product_ids": [(6, 0, products.ids)],
"run_immediately": True,
}
)
bind_wizard.bind_products()

def _refresh_json_data(self, products, backend=None):
"""Force recomputation of JSON data for given products.
Especially helpful if your module adds new JSON keys
but the product are already there and computed w/out your key.
"""
if not products:
return
backend = backend or self.backend
# TODO: remove hasattr check once `jsonify_stored` is ready.
# The json-store machinery comes from search engine module.
# We rely on it for product data BUT only
# `shopinvader_search_engine` requires that dependency.
# Hence, tests that need fresh product data because they add
# new keys to ir.exports record will be broken w/out refresh
# IF `shopinvader_search_engine` is installed (like on Travis).
# `jsonify_stored` will extrapolate the feature
# and allow to get rid of this hack.
# For full story see
# https://github.com/shopinvader/odoo-shopinvader/pull/783
if not hasattr(self.env["shopinvader.variant"], "recompute_json"):
return
invader_variants = products
if invader_variants._name == "product.product":
invader_variants = products.shopinvader_bind_ids
invader_variants.filtered_domain(
[("backend_id", "=", backend.id)]
).recompute_json()

def _install_lang(self, lang_xml_id):
return _install_lang_odoo(self.env, lang_xml_id)

Expand Down
3 changes: 2 additions & 1 deletion shopinvader_sale_packaging/tests/test_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import CommonCase
from odoo.addons.shopinvader_restapi.tests.test_cart_item import ItemCaseMixin


class ConnectedItemCase(ItemCaseMixin, CommonCase):
class ConnectedItemCase(ItemCaseMixin, CommonCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
3 changes: 2 additions & 1 deletion shopinvader_sale_packaging/tests/test_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import CommonCase


class TestSaleOrderPackaging(CommonCase):
class TestSaleOrderPackaging(CommonCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# @author Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_wishlist.tests.test_wishlist import CommonWishlistCase


class WishlistCase(CommonWishlistCase):
class WishlistCase(CommonWishlistCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
7 changes: 5 additions & 2 deletions shopinvader_wishlist/tests/test_product_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
from odoo import exceptions
from odoo.tools import mute_logger

from odoo.addons.shopinvader_product_binding.tests.common import ProductCommonCase
from odoo.addons.shopinvader_product_binding.tests.common import (
ProductCommonCase,
ProductUtilsMixin,
)


class ProductSet(ProductCommonCase):
class ProductSet(ProductCommonCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super(ProductSet, cls).setUpClass()
Expand Down
3 changes: 2 additions & 1 deletion shopinvader_wishlist/tests/test_wishlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from odoo import exceptions

from odoo.addons.shopinvader_product_binding.tests.common import ProductUtilsMixin
from odoo.addons.shopinvader_restapi.tests.common import CommonCase


Expand Down Expand Up @@ -52,7 +53,7 @@ def _check_data(self, record, data):
self.assertEqual(list_line[key], dline.get(key))


class WishlistCase(CommonWishlistCase):
class WishlistCase(CommonWishlistCase, ProductUtilsMixin):
@classmethod
def setUpClass(cls):
super(WishlistCase, cls).setUpClass()
Expand Down

0 comments on commit 801f744

Please sign in to comment.