From b47ea881ad2f6cdddaf414937ee825ca81e14c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 2 Dec 2023 12:02:10 +0100 Subject: [PATCH] Wait until the expected result is fetched in Stripe test scenario Closes #12221 (grafted from 308c41a979f1ed1ffdd713f2dd00a729c902bb0d) --HG-- branch : 6.0 --- .../tests/scenario_account_payment_stripe.rst | 54 +++++++++++++------ ...cenario_account_payment_stripe_dispute.rst | 38 ++++++++----- ...scenario_account_payment_stripe_intent.rst | 29 ++++++---- 3 files changed, 85 insertions(+), 36 deletions(-) diff --git a/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst b/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst index 3200a68019..abe099dc59 100644 --- a/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst +++ b/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst @@ -16,6 +16,8 @@ Imports:: >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ ... create_chart, get_accounts + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 + Activate modules:: >>> config = activate_modules('account_payment_stripe') @@ -119,9 +121,12 @@ Process the payment:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -228,9 +233,12 @@ Make payment with customer:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' @@ -304,9 +312,12 @@ Capture lower amount:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -323,9 +334,13 @@ Refund some amount:: ... ('method', '=', 'account.payment.stripe.refund|stripe_create'), ... ]) >>> cron_refund_create.click('run_once') - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.amount == Decimal('2.00'): + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.amount Decimal('2.00') >>> payment.state @@ -341,9 +356,13 @@ Simulate charge.refunded event with full amount:: >>> refund.amount = Decimal('2') >>> refund.click('approve') >>> cron_refund_create.click('run_once') - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.amount == Decimal('0.00'): + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.amount Decimal('0.00') >>> payment.state @@ -359,7 +378,12 @@ Try to refund more:: >>> refund.amount = Decimal('10') >>> refund.click('approve') >>> cron_refund_create.click('run_once') - >>> cron_fetch_events.click('run_once') - >>> refund.reload() + + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... refund.reload() + ... if refund.state == 'failed': + ... break + ... time.sleep(FETCH_SLEEP) >>> refund.state 'failed' diff --git a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst index c4fdc43f4d..94c3625f04 100644 --- a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst +++ b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst @@ -16,6 +16,8 @@ Imports:: >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ ... create_chart, get_accounts + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 + Activate modules:: >>> config = activate_modules('account_payment_stripe') @@ -102,9 +104,12 @@ Create fully disputed payment:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -195,9 +200,12 @@ Create partial disputed payment:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -266,9 +274,12 @@ Create won disputed payment:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -280,9 +291,12 @@ Simulate charge.dispute.closed event:: >>> dispute = stripe.Dispute.modify(charge.dispute, ... evidence={'uncategorized_text': 'winning_evidence'}) - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> payment.amount diff --git a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst index 289b5c170c..b332616273 100644 --- a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst +++ b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst @@ -16,6 +16,8 @@ Imports:: >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ ... create_chart, get_accounts + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 + Activate modules:: >>> config = activate_modules('account_payment_stripe') @@ -118,9 +120,12 @@ Process off-session the payment:: >>> payment.state 'processing' - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'succeeded': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'succeeded' >>> bool(payment.stripe_captured) @@ -138,9 +143,12 @@ Refund the payment:: ... ]) >>> cron_refund_create.click('run_once') - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'failed': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'failed' @@ -166,8 +174,11 @@ Cancel payment intent:: >>> _ = stripe.PaymentIntent.cancel(payment.stripe_payment_intent_id) - >>> time.sleep(1) - >>> cron_fetch_events.click('run_once') - >>> payment.reload() + >>> for _ in range(MAX_SLEEP): + ... cron_fetch_events.click('run_once') + ... payment.reload() + ... if payment.state == 'failed': + ... break + ... time.sleep(FETCH_SLEEP) >>> payment.state 'failed'