Files
customerTicket/tests/e2e/test_staff_payment_sms_e2e.py

77 lines
4.4 KiB
Python

import uuid
from urllib.parse import parse_qs, urlsplit
import jdatetime
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from django.utils import timezone
from apps.notifications.models import NotificationJob
from apps.payments import services
from apps.payments.models import PaymentNotification, PaymentNotificationAttempt
from tests.e2e.pages.auth import AuthenticationPage
from tests.e2e.pages.staff_payments import StaffPaymentsPage
from tests.e2e.test_payments_e2e import payment_case, PASSWORD, PNG
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
@pytest.mark.parametrize('notices', [False, True])
def test_staff_default_action_tab_and_pagination(live_server, browser_page, payment_case, client, notices):
customer, account, reviewers = payment_case
if notices:
for index in range(26):
services.issue_notice(reviewers[0], {'customer': customer, 'account': account, 'subject': f'اعلامیه صفحه بندی {index}', 'amount': 12345})
else:
client.force_login(customer)
today = jdatetime.date.fromgregorian(date=timezone.localdate())
for _ in range(26):
response = client.post(reverse('payments:receipt_new'), {'depositor_name': 'مشتری آزمایشی', 'receipt_mode': 'independent',
'paid_amount': '12345', 'destination_account': account.pk, 'submission_key': str(uuid.uuid4()),
'paid_day': str(today.day), 'paid_month': str(today.month), 'paid_year': str(today.year),
'receipt_image': SimpleUploadedFile('receipt.png', PNG, content_type='image/png')})
assert response.status_code == 302
with browser_page() as page:
page.set_viewport_size({'width': 320, 'height': 900})
AuthenticationPage(page, live_server.url).login_staff(reviewers[0], PASSWORD)
view = StaffPaymentsPage(page, live_server.url)
view.open_desk()
view.assert_action_tab()
if notices:
page.get_by_role('link', name='اعلامیه‌های واریز', exact=True).click()
view.search(customer.username)
view.next_page()
query = parse_qs(urlsplit(page.url).query)
assert query['q'] == [customer.username]
assert query['tab'] == ['notices' if notices else 'receipts']
if not notices:
assert query['mine'] == ['1']
view.assert_action_tab()
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
@pytest.mark.parametrize('width', [320, 1440])
def test_staff_sms_history_and_resend(live_server, browser_page, payment_case, width):
customer, account, reviewers = payment_case
notice = services.issue_notice(reviewers[0], {'customer': customer, 'account': account, 'subject': 'اعلامیه با سوابق پیامک', 'amount': 12345})
first = PaymentNotification.objects.get(notice=notice)
NotificationJob.objects.filter(pk=first.job_id).update(status='FAILED', attempts=1, last_error='اعتبار پنل کافی نیست')
PaymentNotificationAttempt.objects.create(notification=first, finished_at=timezone.now(), success=False,
provider_code='-19', error='اعتبار پنل کافی نیست')
delivered = services.resend_notice_sms(reviewers[0], notice, str(uuid.uuid4()))
NotificationJob.objects.filter(pk=delivered.pk).update(status='SENT', provider_message_id='old-delivered-id',
sent_at=timezone.now(), delivery_status='DELIVERED', delivery_is_final=True, delivery_checked_at=timezone.now())
PaymentNotificationAttempt.objects.create(notification=delivered.payment_notification, finished_at=timezone.now(),
success=True, provider_code='2', provider_id='old-delivered-id')
with browser_page() as page:
page.set_viewport_size({'width': width, 'height': 900})
AuthenticationPage(page, live_server.url).login_staff(reviewers[0], PASSWORD)
view = StaffPaymentsPage(page, live_server.url)
view.open_notice(notice.public_id)
view.inspect_history()
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
view.resend_sms()
assert PaymentNotification.objects.filter(notice=notice).count() == 3
assert PaymentNotification.objects.filter(notice=notice, job__status='PENDING').count() == 1