fix(payments): keep callback redirect resilient to Redis
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
import json
|
||||
import redis
|
||||
from datetime import timedelta
|
||||
from kombu.exceptions import OperationalError
|
||||
from django.utils import timezone
|
||||
from core.authentication import create_jwt_token
|
||||
from apps.events.models import Event, Registration
|
||||
@@ -171,6 +173,40 @@ class TestPaymentsAPIIntegrationTests:
|
||||
assert f'/events/{self.event.slug}/registration?payment_id={payment.id}' in response.url
|
||||
assert 'status=' not in response.url
|
||||
|
||||
def test_callback_redirects_if_payment_notification_redis_is_unavailable(self, mocker):
|
||||
mock_post = mocker.patch('apps.payments.api.views.requests.post')
|
||||
self.user.is_mobile_verified = True
|
||||
self.user.save(update_fields=['is_mobile_verified'])
|
||||
payment = Payment.objects.create(
|
||||
user=self.user,
|
||||
event=self.event,
|
||||
base_amount=self.event.price,
|
||||
amount=self.event.price,
|
||||
status=Payment.OrderStatusChoices.PENDING,
|
||||
authority='AUTH-REDIS-DOWN',
|
||||
)
|
||||
mock_post.return_value.json.return_value = {
|
||||
'data': {'code': 100, 'ref_id': 'REF-REDIS-DOWN'}
|
||||
}
|
||||
mocker.patch(
|
||||
'apps.payments.api.views.notify_user',
|
||||
side_effect=redis.exceptions.ConnectionError('Redis unavailable'),
|
||||
)
|
||||
mocker.patch(
|
||||
'apps.payments.api.views.send_critical_sms.delay',
|
||||
side_effect=OperationalError('Celery broker unavailable'),
|
||||
)
|
||||
|
||||
response = self.client.get(
|
||||
'/api/payments/callback',
|
||||
{'Authority': payment.authority, 'Status': 'OK'},
|
||||
)
|
||||
|
||||
payment.refresh_from_db()
|
||||
assert response.status_code == 302
|
||||
assert f'/events/{self.event.slug}/registration?payment_id={payment.id}' in response.url
|
||||
assert payment.status == Payment.OrderStatusChoices.PAID
|
||||
|
||||
def test_callback_failure_redirects_failed(self, mocker):
|
||||
mock_post = mocker.patch('apps.payments.api.views.requests.post')
|
||||
payment = Payment.objects.create(user=self.user, event=self.event, base_amount=self.event.price, amount=self.event.price, status=Payment.OrderStatusChoices.PENDING, authority='AUTH456')
|
||||
|
||||
Reference in New Issue
Block a user