|
|
|
|
@ -6,14 +6,14 @@ import pytest |
|
|
|
|
from django.urls import reverse |
|
|
|
|
|
|
|
|
|
from rest_framework import status |
|
|
|
|
from rest_framework.response import Response |
|
|
|
|
from yandex_money.models import Payment |
|
|
|
|
|
|
|
|
|
from finance import models |
|
|
|
|
from progress.models import Progress, ProgressLesson |
|
|
|
|
|
|
|
|
|
PRICE = 1000.00 |
|
|
|
|
METHOD_CASH = 'C' |
|
|
|
|
STATUS_WAIT = 'W' |
|
|
|
|
STATUS_PAID = 'F' |
|
|
|
|
from tests.fixtures.finance import PRICE, METHOD_CASH, STATUS_WAIT, STATUS_PAID |
|
|
|
|
|
|
|
|
|
DUMMY_COMMENT = 'test comment' |
|
|
|
|
DUMMY_DESCRIPTION = 'test description' |
|
|
|
|
|
|
|
|
|
@ -134,3 +134,65 @@ def test_confirm_pay_manager(mocked_email, manager_client, bill_cash, student): |
|
|
|
|
assert Progress.objects.filter(user=bill_cash.user).exists() is True |
|
|
|
|
assert ProgressLesson.objects.filter(progress=progress).exists() is True |
|
|
|
|
assert mocked_email.call_count == 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fake_post_success(view, request): |
|
|
|
|
pay = Payment.objects.get(order_number=request.data['orderNumber']) |
|
|
|
|
pay.status = Payment.STATUS.SUCCESS |
|
|
|
|
pay.save() |
|
|
|
|
return Response('ok', status=status.HTTP_200_OK) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
@mock.patch('django.core.mail.EmailMessage.send') |
|
|
|
|
@mock.patch('finance.views.YandexAvisoView.post', fake_post_success) |
|
|
|
|
def test_confirm_pay_auto_success(mocked_email, api_client, bill_yandex, student): |
|
|
|
|
assert Progress.objects.count() is 0 |
|
|
|
|
assert ProgressLesson.objects.count() is 0 |
|
|
|
|
invoice = bill_yandex.invoice_set.first() |
|
|
|
|
payment = invoice.yandex_pay |
|
|
|
|
data = { |
|
|
|
|
'orderNumber': payment.order_number, |
|
|
|
|
'shopSumAmount': str(payment.shop_amount) |
|
|
|
|
} |
|
|
|
|
api_client.post( |
|
|
|
|
reverse('yandex_money_notice'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_200_OK |
|
|
|
|
) |
|
|
|
|
assert Progress.objects.count() is 1 |
|
|
|
|
assert ProgressLesson.objects.count() is 1 |
|
|
|
|
progress = Progress.objects.filter(user=bill_yandex.user).first() |
|
|
|
|
assert Progress.objects.filter(user=bill_yandex.user).exists() is True |
|
|
|
|
assert ProgressLesson.objects.filter(progress=progress).exists() is True |
|
|
|
|
assert mocked_email.call_count == 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fake_post_fail(view, request): |
|
|
|
|
pay = Payment.objects.get(order_number=request.data['orderNumber']) |
|
|
|
|
pay.status = Payment.STATUS.FAIL |
|
|
|
|
pay.save() |
|
|
|
|
return Response('fail', status=status.HTTP_200_OK) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
@mock.patch('django.core.mail.EmailMessage.send') |
|
|
|
|
@mock.patch('finance.views.YandexAvisoView.post', fake_post_fail) |
|
|
|
|
def test_confirm_pay_auto_fail(mocked_email, api_client, bill_yandex, student): |
|
|
|
|
assert Progress.objects.count() is 0 |
|
|
|
|
assert ProgressLesson.objects.count() is 0 |
|
|
|
|
invoice = bill_yandex.invoice_set.first() |
|
|
|
|
payment = invoice.yandex_pay |
|
|
|
|
data = { |
|
|
|
|
'orderNumber': payment.order_number, |
|
|
|
|
'shopSumAmount': str(payment.shop_amount) |
|
|
|
|
} |
|
|
|
|
api_client.post( |
|
|
|
|
reverse('yandex_money_notice'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_200_OK |
|
|
|
|
) |
|
|
|
|
assert Progress.objects.count() is 0 |
|
|
|
|
assert ProgressLesson.objects.count() is 0 |
|
|
|
|
assert Progress.objects.filter(user=bill_yandex.user).exists() is False |
|
|
|
|
assert mocked_email.call_count == 1 |
|
|
|
|
|