Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
test: WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Feb 9, 2024
1 parent 6a80cc7 commit 438ba64
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ecommerce/extensions/payment/tests/views/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def test_payment_flow(
data={
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': basket.lines.first().stockrecord.partner_sku,
'dynamic_payment_methods_enabled': False,
},
)
assert mock_retrieve.call_count == 1
Expand Down Expand Up @@ -380,6 +381,7 @@ def test_payment_error_no_basket(self):
data={
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': '',
'dynamic_payment_methods_enabled': False,
},
)
assert response.status_code == 302
Expand All @@ -397,6 +399,7 @@ def test_payment_error_sku_mismatch(self):
{
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': 'totally_the_wrong_sku',
'dynamic_payment_methods_enabled': False,
},
)
assert response.json() == {'sku_error': True}
Expand All @@ -423,11 +426,44 @@ def test_payment_check_sdn_returns_hits(self):
{
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': basket.lines.first().stockrecord.partner_sku,
'dynamic_payment_methods_enabled': False,
},
)
assert response.status_code == 400
assert response.json() == {'sdn_check_failure': {'hit_count': 1}}

def test_payment_handle_payment_intent_in_progress(self):
"""
Verify the POST endpoint handles a Payment Intent that is not succeeded yet.
"""
basket = self.create_basket(product_class=SEAT_PRODUCT_CLASS_NAME)

with mock.patch('stripe.PaymentIntent.confirm') as mock_confirm:
mock_confirm.return_value = {
'id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'client_secret': 'pi_3LsftNIadiFyUl1x2TWxaADZ_secret_VxRx7Y1skyp0jKtq7Gdu80Xnh',
'status': 'requires_action'
}
with mock.patch('stripe.PaymentIntent.modify') as mock_modify:
mock_modify.return_value = {
'id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'client_secret': 'pi_3LsftNIadiFyUl1x2TWxaADZ_secret_VxRx7Y1skyp0jKtq7Gdu80Xnh',

}
response = self.client.post(
self.stripe_checkout_url,
data={
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': basket.lines.first().stockrecord.partner_sku,
'dynamic_payment_methods_enabled': True,
},
)
assert response.status_code == 200
assert response.json() == {
'status': 'requires_action',
'transaction_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
}

def test_handle_payment_fails_with_carderror(self):
"""
Verify handle payment failing with CardError returns correct error JSON.
Expand All @@ -439,6 +475,7 @@ def test_handle_payment_fails_with_carderror(self):
{
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': basket.lines.first().stockrecord.partner_sku,
'dynamic_payment_methods_enabled': False,
},
confirm_side_effect=stripe.error.CardError('Oops!', {}, 'card_declined'),
)
Expand All @@ -459,6 +496,7 @@ def test_handle_payment_fails_with_unexpected_error(self):
{
'payment_intent_id': 'pi_3LsftNIadiFyUl1x2TWxaADZ',
'skus': basket.lines.first().stockrecord.partner_sku,
'dynamic_payment_methods_enabled': False,
},
)
assert response.status_code == 400
Expand Down

0 comments on commit 438ba64

Please sign in to comment.