Skip to content

Commit

Permalink
WIP: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Aug 9, 2023
1 parent c84c208 commit 5659c02
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion shopinvader_algolia/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from odoo.addons.connector_algolia.components.adapter import AlgoliaAdapter
from odoo.addons.connector_search_engine.tests.test_all import TestBindingIndexBase
from odoo.addons.shopinvader_v1_product.tests.common import _install_lang_odoo
from odoo.addons.shopinvader_v1_base.tests.common import _install_lang_odoo

try:
from vcr_unittest import VCRMixin
Expand Down
1 change: 1 addition & 0 deletions shopinvader_image/tests/test_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

class ShopinvaderCartCase(CommonConnectedCartCase):
def test_get_cart_image_info(self):
self.backend.bind_all_product()
response = self.service.dispatch("search")
self.assertIn("images", response["data"]["lines"]["items"][0]["product"])
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def setUpClass(cls):
(6, 0, cls.customer.ids)
]
cls.category = cls.shopinvader_variant.tmpl_record_id.categ_id
cls.categ_bind_wizard_model = cls.env[
"shopinvader_v1_product.category.binding.wizard"
]
cls.categ_bind_wizard_model = cls.env["shopinvader.category.binding.wizard"]
bind_wizard = cls.categ_bind_wizard_model.create(
{
"backend_id": cls.backend.id,
Expand Down
6 changes: 3 additions & 3 deletions shopinvader_search_engine/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class AgnosticBinding(models.Model):
"shopinvader_v1_product.ir_exp_shopinvader_variant"
)
cls.categ_export = cls.env.ref(
"shopinvader_v1_base.ir_exp_shopinvader_category"
"shopinvader_v1_product.ir_exp_shopinvader_category"
)
cls.ir_model_model = cls.env["ir.model"]
cls.variant_model = cls.ir_model_model._get("shopinvader_v1_product.variant")
cls.categ_model = cls.ir_model_model._get("shopinvader_v1_product.category")
cls.variant_model = cls.ir_model_model._get("shopinvader.variant")
cls.categ_model = cls.ir_model_model._get("shopinvader.category")
cls.agnostic_model = cls.ir_model_model._get(cls.AgnosticBinding._name)
cls.lang_en = cls.backend.lang_ids
cls.lang_fr = _install_lang_odoo(cls.env, "base.lang_fr")
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_v1_base/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _create_invader_partner(env, **kw):
class CommonMixin(RegistryMixin, ComponentMixin, UtilsMixin):
@staticmethod
def _setup_backend(cls):
cls.env = cls.env(context={"lang": "en_US"})
cls.env = cls.env(context={"lang": "en_US", "shopinvader_test": True})
cls.backend = cls.env.ref("shopinvader_v1_base.backend_1")
cls.shopinvader_session = {}
cls.existing_jobs = cls.env["queue.job"].browse()
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_v1_product/models/shopinvader_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,4 @@ def _get_shop_data(self):
return self.jsonify(exporter.get_json_parser(), one=True)

def _jsonify_get_exporter(self):
return self.env.ref("shopinvader_v1_base.ir_exp_shopinvader_variant").sudo()
return self.env.ref("shopinvader_v1_product.ir_exp_shopinvader_variant").sudo()
4 changes: 4 additions & 0 deletions shopinvader_v1_product/services/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class CartService(Component):

def _check_allowed_product(self, cart, params):
product = self.env["product.product"].browse(params["product_id"])
if self.env.context.get("shopinvader_test") and not self.env.context.get(
"test_check_shopinvader_product"
):
return True
if not product._add_to_cart_allowed(
self.shopinvader_backend, partner=self.partner
):
Expand Down
18 changes: 11 additions & 7 deletions shopinvader_v1_product/tests/test_cart_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
from odoo import exceptions
from odoo.tools import mute_logger

from odoo.addons.shopinvader_v1_base.tests.common import CommonCase
from odoo.addons.shopinvader_v1_base.tests.test_cart_item import ItemCaseMixin


class AbstractItemCase(ItemCaseMixin):
@classmethod
def setUpClass(cls):
super(AbstractItemCase, cls).setUpClass()
cls._setup_products()

class ItemCase(ItemCaseMixin, CommonCase):
@mute_logger("odoo.models.unlink")
def test_add_item_with_product_not_allowed(self):
self.remove_cart()
self.env = self.env(
context=dict(self.env.context, test_check_shopinvader_product=True)
)
self._setup_products()
with self.work_on_services(
partner=None, shopinvader_session=self.shopinvader_session
) as work:
self.service = work.component(usage="cart")

with self.assertRaises(exceptions.UserError):
self.add_item(self.product_1.id, 1)

0 comments on commit 5659c02

Please sign in to comment.