Neighborhood filtering was UUID-only; add name-based search on both GET /api/v1/cities/ and GET /api/v1/neighborhoods/ (the latter also matching by city name), and document all params for drf-spectacular. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
from rest_framework.test import APITestCase
|
|
|
|
from apps.locations.models import City, Neighborhood
|
|
|
|
|
|
class LocationListFilterTests(APITestCase):
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
cls.tehran = City.objects.create(name='تهران', slug='tehran')
|
|
cls.mashhad = City.objects.create(name='مشهد', slug='mashhad')
|
|
|
|
cls.vanak = Neighborhood.objects.create(city=cls.tehran, name='ونک', slug='vanak')
|
|
cls.tajrish = Neighborhood.objects.create(city=cls.tehran, name='تجریش', slug='tajrish')
|
|
cls.mashhad_hood = Neighborhood.objects.create(city=cls.mashhad, name='احمدآباد', slug='ahmadabad')
|
|
|
|
def test_search_city_by_name(self):
|
|
response = self.client.get('/api/v1/cities/', {'search': 'مشهد'})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
uuids = {city['uuid'] for city in response.data['results']}
|
|
self.assertEqual(uuids, {str(self.mashhad.uuid)})
|
|
|
|
def test_filter_neighborhood_by_city(self):
|
|
response = self.client.get('/api/v1/neighborhoods/', {'city': str(self.tehran.uuid)})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
uuids = {n['uuid'] for n in response.data['results']}
|
|
self.assertEqual(uuids, {str(self.vanak.uuid), str(self.tajrish.uuid)})
|
|
|
|
def test_search_neighborhood_by_name(self):
|
|
response = self.client.get('/api/v1/neighborhoods/', {'search': 'ونک'})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
uuids = {n['uuid'] for n in response.data['results']}
|
|
self.assertEqual(uuids, {str(self.vanak.uuid)})
|
|
|
|
def test_search_neighborhood_by_city_name(self):
|
|
response = self.client.get('/api/v1/neighborhoods/', {'search': 'مشهد'})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
uuids = {n['uuid'] for n in response.data['results']}
|
|
self.assertEqual(uuids, {str(self.mashhad_hood.uuid)})
|