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 9409652dd7..9b954f80af 100644 --- a/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst +++ b/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst @@ -18,7 +18,7 @@ Imports:: >>> today = dt.date.today() - >>> FETCH_SLEEP = 1 + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 Activate modules:: @@ -121,9 +121,12 @@ Process the payment:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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) @@ -226,9 +229,12 @@ Make payment with customer:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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' @@ -300,9 +306,12 @@ Capture lower amount:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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) @@ -320,10 +329,13 @@ Refund some amount:: ... ('method', '=', 'account.payment.stripe.refund|stripe_create'), ... ]) >>> cron_refund_create.click('run_once') - >>> time.sleep(FETCH_SLEEP) - >>> 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 @@ -340,10 +352,13 @@ Simulate charge.refunded event with full amount:: >>> refund.click('submit') >>> refund.click('approve') >>> cron_refund_create.click('run_once') - >>> time.sleep(FETCH_SLEEP) - >>> 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 @@ -360,8 +375,12 @@ Try to refund more:: >>> refund.click('submit') >>> refund.click('approve') >>> cron_refund_create.click('run_once') - >>> time.sleep(FETCH_SLEEP) - >>> 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 7138ce53fe..4803b36d2b 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 @@ -18,7 +18,7 @@ Imports:: >>> today = dt.date.today() - >>> FETCH_SLEEP = 1 + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 Activate modules:: @@ -104,9 +104,12 @@ Create fully disputed payment:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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 +198,12 @@ Create partial disputed payment:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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) @@ -264,9 +270,12 @@ Create won disputed payment:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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) @@ -278,9 +287,12 @@ Simulate charge.dispute.closed event:: >>> dispute = stripe.Dispute.modify(charge.dispute, ... evidence={'uncategorized_text': 'winning_evidence'}) - >>> time.sleep(FETCH_SLEEP) - >>> 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 596b268726..345fc69a99 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 @@ -18,7 +18,7 @@ Imports:: >>> today = dt.date.today() - >>> FETCH_SLEEP = 1 + >>> FETCH_SLEEP, MAX_SLEEP = 1, 10 Activate modules:: @@ -121,9 +121,12 @@ Process off-session the payment:: >>> payment.state 'processing' - >>> time.sleep(FETCH_SLEEP) - >>> 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) @@ -142,9 +145,12 @@ Refund the payment:: ... ]) >>> cron_refund_create.click('run_once') - >>> time.sleep(FETCH_SLEEP) - >>> 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' @@ -169,8 +175,11 @@ Cancel payment intent:: >>> _ = stripe.PaymentIntent.cancel(payment.stripe_payment_intent_id) - >>> time.sleep(FETCH_SLEEP) - >>> 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'