194 lines
10 KiB
Python
194 lines
10 KiB
Python
import pytest
|
|
from django.urls import reverse
|
|
|
|
from apps.accounts.models import TicketMagicLink, User
|
|
from apps.core.models import PageTitle, SiteBranding
|
|
from apps.customers.models import ContactGroup
|
|
from apps.notifications.models import SMSTemplate
|
|
from apps.staff.models import OrganizationalUnit
|
|
from apps.tickets.models import GroupDispatch, TicketCategory
|
|
from apps.tickets.services import create_ticket
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_login_uses_database_title_and_brand_without_login_card_copy(client):
|
|
branding = SiteBranding.load()
|
|
branding.header_title = "سامانه ارتباطات آزمایشی"
|
|
branding.header_subtitle = "پیگیری یکپارچه"
|
|
branding.login_intro_icon = "●"
|
|
branding.login_intro_eyebrow = "ارتباط مستقیم آزمایشی"
|
|
branding.login_intro_heading = "عنوان سطر اول\nعنوان سطر دوم"
|
|
branding.login_intro_body = "توضیح قابل مدیریت از دیتابیس"
|
|
branding.developer_credit_text = "توسعه: تیم آزمایشی | ۰۹۱۲۰۰۰۰۰۰۰"
|
|
branding.save()
|
|
PageTitle.objects.update_or_create(route_name="accounts:login", defaults={"title": "ورود سفارشی", "is_active": True})
|
|
|
|
response = client.get(reverse("accounts:login"))
|
|
content = response.content.decode()
|
|
assert "<title>ورود سفارشی</title>" in content
|
|
assert "سامانه ارتباطات آزمایشی" in content # page header is database-backed
|
|
assert '<div class="auth-brand"' in content
|
|
assert '<div><strong>سامانه ارتباطات آزمایشی</strong>' not in content
|
|
assert "ارتباط مستقیم آزمایشی" in content
|
|
assert "عنوان سطر اول<br>عنوان سطر دوم" in content
|
|
assert "توضیح قابل مدیریت از دیتابیس" in content
|
|
assert "توسعه: تیم آزمایشی | ۰۹۱۲۰۰۰۰۰۰۰" in content
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_developer_credit_html_requires_explicit_trusted_html_switch(client):
|
|
branding = SiteBranding.load()
|
|
branding.developer_credit_html = '<a href="https://example.com" style="color:red"><span>★</span> توسعه نمونه</a>'
|
|
branding.use_developer_credit_html = False
|
|
branding.save()
|
|
escaped = client.get(reverse("accounts:login")).content.decode()
|
|
assert "https://example.com" not in escaped
|
|
|
|
branding.use_developer_credit_html = True
|
|
branding.save()
|
|
rendered = client.get(reverse("accounts:login")).content.decode()
|
|
assert '<a href="https://example.com" style="color:red"><span>★</span> توسعه نمونه</a>' in rendered
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_customer_new_renders_developer_credit_once_directly_below_wizard(client):
|
|
customer = User.objects.create_user(
|
|
username="wizard-credit-customer", mobile="09120000404", account_type=User.AccountType.CUSTOMER
|
|
)
|
|
branding = SiteBranding.load()
|
|
branding.developer_credit_text = "برنامه نویسی و توسعه: محمد جواد فصاحت | 09202202129"
|
|
branding.save()
|
|
client.force_login(customer)
|
|
|
|
content = client.get(reverse("tickets:new")).content.decode()
|
|
assert content.count(branding.developer_credit_text) == 1
|
|
assert '<footer class="ticket-wizard-credit">' in content
|
|
assert content.index('</form>') < content.index('<footer class="ticket-wizard-credit">')
|
|
assert '<footer class="site-footer">' not in content
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_magic_ticket_renders_database_developer_credit_once_inside_workspace(client):
|
|
branding = SiteBranding.load()
|
|
branding.developer_credit_text = "برنامه نویسی و توسعه: محمد جواد فصاحت | 09202202129"
|
|
branding.save()
|
|
customer = User.objects.create_user(
|
|
username="magic-credit-customer", mobile="09120000414", account_type=User.AccountType.CUSTOMER
|
|
)
|
|
category = TicketCategory.objects.create(title="پیگیری لینک امضا", slug="magic-credit-category")
|
|
ticket = create_ticket(customer=customer, category=category, subject="نمایش امضا", body="شرح")
|
|
token = TicketMagicLink.issue(ticket)
|
|
destination = client.get(reverse("accounts:magic", args=[token])).url
|
|
|
|
content = client.get(destination).content.decode()
|
|
assert content.count(branding.developer_credit_text) == 1
|
|
assert '<footer class="ticket-detail-credit">' in content
|
|
assert content.index('class="workspace-grid customer-grid"') < content.index('<footer class="ticket-detail-credit">')
|
|
assert '<footer class="site-footer">' not in content
|
|
|
|
branding.developer_credit_html = '<strong data-developer-signature>امضای HTML سفارشی</strong>'
|
|
branding.use_developer_credit_html = True
|
|
branding.save()
|
|
html_content = client.get(destination).content.decode()
|
|
assert '<strong data-developer-signature>امضای HTML سفارشی</strong>' in html_content
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_staff_sidebar_brand_is_database_backed(client):
|
|
user = User.objects.create_superuser(username="brand-admin", password="safe-password", account_type=User.AccountType.STAFF)
|
|
branding = SiteBranding.load()
|
|
branding.staff_brand_title = "مرکز ارتباطات سازمانی"
|
|
branding.staff_brand_subtitle = "میز خدمت یکپارچه"
|
|
branding.staff_panel_label = "فضای کارشناسان"
|
|
branding.developer_credit_text = "امضای عمومی آزمایشی"
|
|
branding.staff_sidebar_credit_text = "امضای مستقل sidebar آزمایشی"
|
|
branding.save()
|
|
client.force_login(user)
|
|
|
|
content = client.get(reverse("staff_tickets:list")).content.decode()
|
|
assert "مرکز ارتباطات سازمانی" in content
|
|
assert "میز خدمت یکپارچه" in content
|
|
assert "فضای کارشناسان" in content
|
|
assert '<div class="staff-developer-credit">امضای مستقل sidebar آزمایشی</div>' in content
|
|
assert '<footer class="site-footer">امضای عمومی آزمایشی</footer>' in content
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_staff_login_and_customer_ticket_hero_are_database_backed(client):
|
|
branding = SiteBranding.load()
|
|
branding.staff_login_intro_eyebrow = "ورود سازمانی سفارشی"
|
|
branding.staff_login_intro_heading = "کار بهتر\nپاسخ سریعتر"
|
|
branding.staff_login_intro_body = "متن معرفی کارشناسان از دیتابیس"
|
|
branding.customer_tickets_hero_eyebrow = "مرکز ارتباط سفارشی"
|
|
branding.customer_tickets_hero_heading = "مسیر تازه\nبرای پاسخ"
|
|
branding.customer_tickets_hero_body = "متن صفحه تیکت از دیتابیس"
|
|
branding.save()
|
|
staff_login = client.get(reverse("accounts:staff_login")).content.decode()
|
|
assert "ورود سازمانی سفارشی" in staff_login and "کار بهتر<br>پاسخ سریعتر" in staff_login
|
|
customer = User.objects.create_user(username="hero-customer", mobile="09121112222", account_type=User.AccountType.CUSTOMER)
|
|
client.force_login(customer)
|
|
tickets = client.get(reverse("tickets:list")).content.decode()
|
|
assert "مرکز ارتباط سفارشی" in tickets and "مسیر تازه<br>برای پاسخ" in tickets
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_logo_and_pwa_manifest_use_database_values_with_static_fallback(client):
|
|
branding = SiteBranding.load()
|
|
branding.company_logo.name = "branding/logo/custom-logo.png"
|
|
branding.favicon.name = "branding/favicon/custom.ico"
|
|
branding.pwa_icon.name = "branding/pwa/custom-pwa.png"
|
|
branding.pwa_name = "سامانه جامع سفارشی"
|
|
branding.pwa_title = "سامانه سفارشی"
|
|
branding.pwa_description = "توضیح PWA از دیتابیس"
|
|
branding.save()
|
|
login = client.get(reverse("accounts:login")).content.decode()
|
|
assert "/media/branding/logo/custom-logo.png?v=" in login
|
|
assert "/media/branding/favicon/custom.ico?v=" in login
|
|
manifest = client.get(reverse("web_manifest")).json()
|
|
assert manifest["name"] == "سامانه جامع سفارشی"
|
|
assert manifest["short_name"] == "سامانه سفارشی"
|
|
assert manifest["description"] == "توضیح PWA از دیتابیس"
|
|
assert manifest["icons"][0]["src"] == "/media/branding/pwa/custom-pwa.png"
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_sms_template_page_includes_global_database_templates(client):
|
|
user = User.objects.create_superuser(username="sms-admin", password="safe-password", account_type=User.AccountType.STAFF)
|
|
SMSTemplate.objects.update_or_create(
|
|
unit=None,
|
|
event_type=SMSTemplate.Event.STAFF_REPLY,
|
|
defaults={"title": "الگوی عمومی تست", "body": "پیگیری {ticket_number}: {magic_link}"},
|
|
)
|
|
client.force_login(user)
|
|
|
|
response = client.get(reverse("staff_tickets:sms_templates"))
|
|
assert response.status_code == 200
|
|
assert "الگوی عمومی تست" in response.content.decode()
|
|
assert "الگوی عمومی سیستم" in response.content.decode()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_dispatch_history_supports_search_status_and_pagination(client):
|
|
user = User.objects.create_superuser(username="dispatch-admin", password="safe-password", account_type=User.AccountType.STAFF)
|
|
unit = OrganizationalUnit.objects.create(name="لوجستیک تست", slug="dispatch-filter-test")
|
|
group = ContactGroup.objects.create(unit=unit, name="باربریهای تست")
|
|
category = TicketCategory.objects.create(title="استعلام تست", slug="dispatch-filter-test")
|
|
for index in range(13):
|
|
GroupDispatch.objects.create(
|
|
unit=unit, contact_group=group, created_by=user, category=category,
|
|
subject=f"استعلام کرایه {index}", body="متن تست", status=GroupDispatch.Status.SENT,
|
|
)
|
|
GroupDispatch.objects.create(
|
|
unit=unit, contact_group=group, created_by=user, category=category,
|
|
subject="عملیات متفاوت", body="متن تست", status=GroupDispatch.Status.QUEUED,
|
|
)
|
|
client.force_login(user)
|
|
|
|
first = client.get(reverse("staff_tickets:dispatch_create"))
|
|
assert first.status_code == 200
|
|
assert first.context["page"].paginator.num_pages == 2
|
|
filtered = client.get(reverse("staff_tickets:dispatch_create"), {"q": "متفاوت", "status": GroupDispatch.Status.QUEUED})
|
|
assert filtered.context["page"].paginator.count == 1
|
|
assert "عملیات متفاوت" in filtered.content.decode()
|
|
assert "استعلام کرایه" not in filtered.content.decode()
|