This commit is contained in:
javad committed 2026-10-10 14:21:04 +03:30
1 parent 250cdbab7f
commit 5c6069c3ef
87 files changed
+29209 -3697

No files matched your search

+47 -3
View File
@@ -6,14 +6,13 @@ from django.urls import reverse
from admin_panel.models import Article, Customer, PhoneNumber
from .factories import make_customer, make_user
from .factories import login_superuser, make_customer, make_user
class CustomerCrudTests(TestCase):
def setUp(self):
self.user = make_user('csUser', superuser=True)
self.client.force_login(self.user)
self.user = login_superuser(self.client, 'csUser')
def test_add_customer_creates_phones(self):
url = reverse('admin_panel:customersAdd')
@@ -56,6 +55,51 @@ class CustomerCrudTests(TestCase):
self.assertEqual(phones[0].phone_number, '09120009999')
class InactiveCustomerHiddenTests(TestCase):
"""مشتری غیرفعال (is_active=False) در فهرست و در جستجو دیده نمی‌شود."""
def setUp(self):
self.user = login_superuser(self.client, 'hideUser')
self.active = make_customer('خطیبی فعال', phones=['09120000041'])
self.inactive = make_customer('خطیبی غیرفعال', is_active=False,
phones=['09120000042'])
# جستجوی تلفن از ستون phone1 می‌خواند (فیلد قدیمی مشتری).
Customer.objects.filter(pk=self.active.pk).update(phone1='09120000041')
Customer.objects.filter(pk=self.inactive.pk).update(phone1='09120000042')
def test_inactive_absent_from_default_listing(self):
html = self.client.get(reverse('admin_panel:customers')).content.decode('utf-8')
self.assertIn('خطیبی فعال', html)
self.assertNotIn('خطیبی غیرفعال', html)
def test_inactive_absent_from_search_by_name(self):
html = self.client.get(
reverse('admin_panel:customers'),
{'searchVal': 'خطیبی', 'searchOn': 'name'},
).content.decode('utf-8')
self.assertIn('خطیبی فعال', html)
self.assertNotIn('خطیبی غیرفعال', html)
def test_inactive_absent_from_search_by_phone(self):
html = self.client.get(
reverse('admin_panel:customers'),
{'searchVal': '0912000004', 'searchOn': 'phone'},
).content.decode('utf-8')
self.assertIn('09120000041', html)
self.assertNotIn('09120000042', html)
def test_inactive_absent_from_path_search_view(self):
# مسیر <slug:> فقط نویسه‌های لاتین می‌پذیرد.
make_customer('khatibi-active')
make_customer('khatibi-inactive', is_active=False)
html = self.client.get(
reverse('admin_panel:customersSearch',
kwargs={'searchVal': 'khatibi', 'searchOn': 'name'}),
).content.decode('utf-8')
self.assertIn('khatibi-active', html)
self.assertNotIn('khatibi-inactive', html)
class CustomerDeleteGuardTests(TestCase):
def setUp(self):