21 |
21 |
from combo.apps.lingo.models import (Regie, BasketItem, Transaction,
|
22 |
22 |
TransactionOperation, RemoteItem, EXPIRED, LingoBasketCell)
|
23 |
23 |
from combo.apps.lingo.management.commands.update_transactions import Command as UpdateTransactionsCommand
|
|
24 |
from combo.apps.lingo.management.commands.notify_payments import Command as NotifyPaymentsCommand
|
24 |
25 |
from combo.utils import sign_url
|
25 |
26 |
|
26 |
27 |
pytestmark = pytest.mark.django_db
|
... | ... | |
573 |
574 |
resp = client.get(callback_url, data)
|
574 |
575 |
assert resp.status_code == 200
|
575 |
576 |
assert Transaction.objects.get(order_id=transaction_id).status == 3
|
|
577 |
|
|
578 |
def test_payment_callback_error(regie, user):
|
|
579 |
item = BasketItem.objects.create(user=user, regie=regie,
|
|
580 |
subject='test_item', amount='10.5',
|
|
581 |
source_url='http://example.org/testitem/')
|
|
582 |
login()
|
|
583 |
resp = client.post(reverse('lingo-pay'), {'regie': regie.pk})
|
|
584 |
assert resp.status_code == 302
|
|
585 |
location = resp.get('location')
|
|
586 |
parsed = urlparse.urlparse(location)
|
|
587 |
qs = urlparse.parse_qs(parsed.query)
|
|
588 |
transaction_id = qs['transaction_id'][0]
|
|
589 |
data = {'transaction_id': transaction_id, 'signed': True,
|
|
590 |
'amount': qs['amount'][0], 'ok': True}
|
|
591 |
assert data['amount'] == '10.50'
|
|
592 |
|
|
593 |
# call callback with GET
|
|
594 |
callback_url = reverse('lingo-callback', kwargs={'regie_pk': regie.id})
|
|
595 |
with mock.patch('combo.utils.RequestsSession.request') as request:
|
|
596 |
mock_response = mock.Mock()
|
|
597 |
def kaboom():
|
|
598 |
raise Exception('kaboom')
|
|
599 |
mock_response.status_code = 500
|
|
600 |
mock_response.raise_for_status = kaboom
|
|
601 |
request.return_value = mock_response
|
|
602 |
get_resp = client.get(callback_url, data)
|
|
603 |
url = request.call_args[0][1]
|
|
604 |
assert url.startswith('http://example.org/testitem/jump/trigger/paid')
|
|
605 |
assert get_resp.status_code == 200
|
|
606 |
assert Transaction.objects.get(order_id=transaction_id).status == 3
|
|
607 |
assert BasketItem.objects.get(id=item.id).payment_date
|
|
608 |
assert not BasketItem.objects.get(id=item.id).notification_date
|
|
609 |
|
|
610 |
# too soon
|
|
611 |
NotifyPaymentsCommand().handle()
|
|
612 |
assert BasketItem.objects.get(id=item.id).payment_date
|
|
613 |
assert not BasketItem.objects.get(id=item.id).notification_date
|
|
614 |
|
|
615 |
# fake delay
|
|
616 |
basket_item = BasketItem.objects.get(id=item.id)
|
|
617 |
basket_item.payment_date = timezone.now() - timedelta(hours=1)
|
|
618 |
basket_item.save()
|
|
619 |
|
|
620 |
with mock.patch('combo.utils.RequestsSession.request') as request:
|
|
621 |
mock_response = mock.Mock()
|
|
622 |
mock_response.status_code = 200
|
|
623 |
request.return_value = mock_response
|
|
624 |
NotifyPaymentsCommand().handle()
|
|
625 |
url = request.call_args[0][1]
|
|
626 |
assert url.startswith('http://example.org/testitem/jump/trigger/paid')
|
|
627 |
assert BasketItem.objects.get(id=item.id).payment_date
|
|
628 |
assert BasketItem.objects.get(id=item.id).notification_date
|
576 |
|
-
|