fix focus on ticket new, sitebranding, customer edit error

This commit is contained in:
javad committed 2026-09-16 12:44:43 +03:30
1 parent d72381f0ac
commit 6b841dc5fa
11 files changed
+139 -10

No files matched your search

+64
View File
@@ -405,6 +405,70 @@ def test_staff_can_visually_add_and_remove_contact_group_memberships(client):
assert set(contact.customer_profile.groups.values_list("pk", flat=True)) == {second.pk}
@pytest.mark.django_db
def test_staff_can_classify_and_edit_ticket_customer_without_an_existing_group(client):
unit = OrganizationalUnit.objects.create(name="واحد مشتری خودکار", slug="ungrouped-customer-editor")
unit.permissions.add(*Permission.objects.filter(
content_type__app_label="customers",
codename__in=("view_customerprofile", "change_customerprofile"),
))
staff = make_staff("ungrouped-customer-agent", unit)
contact = make_contact("ungrouped-ticket-customer", "09120000515")
category = TicketCategory.objects.create(unit=unit, title="درخواست مشتری خودکار", slug="ungrouped-customer-ticket")
create_ticket(customer=contact, created_by=staff, unit=unit, category=category, subject="نیازمند دسته‌بندی", body="شرح")
group = ContactGroup.objects.create(name="گروه انتخاب‌شده", unit=unit)
client.force_login(staff)
url = reverse("staff_tickets:contact_edit", args=[contact.public_id])
page = client.get(url)
assert page.status_code == 200
assert f'value="{group.pk}"' in page.content.decode()
missing_group = client.post(url, {
"mobile": contact.local_mobile,
"first_name": "مشتری",
"last_name": "خودکار",
"organization_name": "",
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
"groups": [],
"province": "",
"city": "",
})
assert missing_group.status_code == 200
assert missing_group.context["form"]["groups"].errors
saved = client.post(url, {
"mobile": contact.local_mobile,
"first_name": "مشتری",
"last_name": "دسته‌بندی‌شده",
"organization_name": "",
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
"groups": [group.pk],
"province": "",
"city": "",
})
assert saved.status_code == 302
assert contact.customer_profile.groups.filter(pk=group.pk).exists()
@pytest.mark.django_db
def test_staff_cannot_edit_ungrouped_customer_from_an_unrelated_ticket_unit(client):
ticket_unit = OrganizationalUnit.objects.create(name="واحد مالک مشتری", slug="ungrouped-owner-unit")
unrelated_unit = OrganizationalUnit.objects.create(name="واحد نامرتبط مشتری", slug="ungrouped-unrelated-unit")
unrelated_unit.permissions.add(*Permission.objects.filter(
content_type__app_label="customers",
codename__in=("view_customerprofile", "change_customerprofile"),
))
owner = make_staff("ungrouped-owner-agent", ticket_unit)
outsider = make_staff("ungrouped-outsider-agent", unrelated_unit)
contact = make_contact("private-ungrouped-customer", "09120000516")
category = TicketCategory.objects.create(unit=ticket_unit, title="درخواست محرمانه", slug="private-ungrouped-ticket")
create_ticket(customer=contact, created_by=owner, unit=ticket_unit, category=category, subject="محرمانه", body="شرح")
client.force_login(outsider)
assert client.get(reverse("staff_tickets:contact_edit", args=[contact.public_id])).status_code == 404
@pytest.mark.django_db
def test_staff_ticket_create_supports_multiple_previewable_attachments(client, monkeypatch, settings, tmp_path):
settings.MEDIA_ROOT = tmp_path