Skip to content

Commit

Permalink
add tests for recompute action
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillot authored and sebastienbeau committed Aug 31, 2020
1 parent 61131bf commit 0283ada
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions shopinvader_search_engine/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import test_action_server
from . import test_delete_product
33 changes: 33 additions & 0 deletions shopinvader_search_engine/tests/test_action_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.queue_job.tests.common import JobMixin
from odoo.addons.shopinvader.tests.common import ProductCommonCase


class ActionServerCase(ProductCommonCase, JobMixin):
def test_action_server_on_product_template(self):
job = self.job_counter()
bindings = self.env["shopinvader.product"].search([], limit=4)
action = self.env.ref(
"shopinvader_search_engine.action_recompute_shopinvader_product"
)
action.with_context(
active_model="product.template",
active_ids=bindings.mapped("record_id").ids,
).run()
self.assertEqual(job.count_created(), 4)

def test_action_server_on_product_category(self):
self.backend.bind_all_category()
job = self.job_counter()
bindings = self.env["shopinvader.category"].search([], limit=4)
action = self.env.ref(
"shopinvader_search_engine.action_recompute_shopinvader_category"
)
action.with_context(
active_model="product.category",
active_ids=bindings.mapped("record_id").ids,
).run()
self.assertEqual(job.count_created(), 4)
3 changes: 1 addition & 2 deletions shopinvader_search_engine/views/product_category_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
<field name="model_id" ref="product.model_product_category"/>
<field name="binding_model_id" ref="product.model_product_category"/>
<field name="code">
for categ in records:
categ.shopinvader_bind_ids._jobify_recompute_json(force_export=True)
records.mapped("shopinvader_bind_ids")._jobify_recompute_json(force_export=True)
</field>
</record>

Expand Down
4 changes: 1 addition & 3 deletions shopinvader_search_engine/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
<field name="model_id" ref="product.model_product_template"/>
<field name="binding_model_id" ref="product.model_product_template"/>
<field name="code">
for template in records:
for variant in obj.product_variant_ids:
variant.shopinvader_bind_ids._jobify_recompute_json(force_export=True)
records.mapped("product_variant_ids.shopinvader_bind_ids")._jobify_recompute_json(force_export=True)
</field>
</record>

Expand Down

0 comments on commit 0283ada

Please sign in to comment.