From bb82a8d1f69e838b2ce6cfa7bace8cbb528eeda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 2 Dec 2023 12:02:16 +0100 Subject: [PATCH] Wait until the expected result is fetched in Shopify test scenario Closes #12794 (grafted from dd11633bfa87f06b7c7f18a8bd444cb468582da2) --HG-- branch : 7.0 --- .../tests/scenario_web_shop_shopify.rst | 10 ++++++++-- .../tests/scenario_web_shop_shopify_secondary_unit.rst | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst b/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst index 07c1cc3a03..c3216a3092 100644 --- a/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst +++ b/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst @@ -24,6 +24,8 @@ Imports:: >>> from trytond.modules.account_invoice.tests.tools import ( ... set_fiscalyear_invoice_sequences) + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 + Activate modules:: >>> config = activate_modules([ @@ -358,7 +360,11 @@ Check inventory item:: >>> inventory_items = ProductInventoryItem.find([]) >>> inventory_item_ids = [i.shopify_identifier ... for inv in inventory_items for i in inv.shopify_identifiers] - >>> inventory_levels = location.inventory_levels() + >>> for _ in range(MAX_SLEEP): + ... inventory_levels = location.inventory_levels() + ... if inventory_levels: + ... break + ... time.sleep(FETCH_SLEEP) >>> sorted(l.available for l in inventory_levels ... if l.available and l.inventory_item_id in inventory_item_ids) [5, 10] @@ -627,7 +633,7 @@ Clean up:: >>> for category in ShopifyIdentifier.find( ... [('record', 'like', 'product.category,%')]): ... shopify.CustomCollection.find(category.shopify_identifier).destroy() - >>> time.sleep(1) + >>> time.sleep(FETCH_SLEEP) >>> customer.destroy() >>> shopify.ShopifyResource.clear_session() diff --git a/modules/web_shop_shopify/tests/scenario_web_shop_shopify_secondary_unit.rst b/modules/web_shop_shopify/tests/scenario_web_shop_shopify_secondary_unit.rst index b7525ef11a..c59677ec12 100644 --- a/modules/web_shop_shopify/tests/scenario_web_shop_shopify_secondary_unit.rst +++ b/modules/web_shop_shopify/tests/scenario_web_shop_shopify_secondary_unit.rst @@ -24,6 +24,8 @@ Imports:: >>> from trytond.modules.account_invoice.tests.tools import ( ... set_fiscalyear_invoice_sequences) + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 + Activate modules:: >>> config = activate_modules([ @@ -190,7 +192,11 @@ Run fetch order:: ... cron_fetch_order, = Cron.find([ ... ('method', '=', 'web.shop|shopify_fetch_order'), ... ]) - ... cron_fetch_order.click('run_once') + ... for _ in range(MAX_SLEEP): + ... cron_fetch_order.click('run_once') + ... if Sale.find([]): + ... break + ... time.sleep(FETCH_SLEEP) >>> sale, = Sale.find([]) >>> len(sale.lines)