import pytest from django.urls import reverse from apps.accounts.models import 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 @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 "ورود سفارشی" in content assert "سامانه ارتباطات آزمایشی" in content # page header is database-backed assert '
سامانه ارتباطات آزمایشی' not in content assert "ارتباط مستقیم آزمایشی" in content assert "عنوان سطر اول
عنوان سطر دوم" 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 = '★ توسعه نمونه' 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 '★ توسعه نمونه' in rendered @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 '
امضای مستقل sidebar آزمایشی
' in content assert '' 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 "کار بهتر
پاسخ سریع‌تر" 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 "مسیر تازه
برای پاسخ" 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()