Add Store.latitude/Store.longitude properties derived from the location PointField, and expose them read-only on StoreListSerializer (inherited by StoreDetailSerializer). Also make them readable on SellerStoreSerializer, which previously only accepted them as write-only input. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
import uuid
|
|
|
|
from apps.locations.models import City
|
|
from apps.stores.models import Store, StoreCategory
|
|
from apps.users.models import User
|
|
|
|
from apps.orders.tests.base import OrdersTestCase
|
|
|
|
|
|
class SellerStoreTests(OrdersTestCase):
|
|
def setUp(self):
|
|
self.new_seller = User.objects.create_user(pk=uuid.uuid4(), username='new_seller')
|
|
self.category = StoreCategory.objects.create(name='کافه')
|
|
|
|
def test_seller_can_create_their_store(self):
|
|
self.client.force_authenticate(user=self.new_seller)
|
|
response = self.client.post('/api/v1/seller/store/', {
|
|
'name': 'کافه من',
|
|
'category_uuid': str(self.category.uuid),
|
|
'city_uuid': str(self.city.uuid),
|
|
'address': 'خیابان ولیعصر',
|
|
'latitude': 35.75,
|
|
'longitude': 51.4,
|
|
})
|
|
self.assertEqual(response.status_code, 201, response.data)
|
|
self.assertTrue(Store.objects.filter(owner=self.new_seller).exists())
|
|
self.assertAlmostEqual(response.data['latitude'], 35.75)
|
|
self.assertAlmostEqual(response.data['longitude'], 51.4)
|
|
|
|
def test_seller_cannot_create_a_second_store(self):
|
|
self.client.force_authenticate(user=self.seller1)
|
|
response = self.client.post('/api/v1/seller/store/', {
|
|
'name': 'فروشگاه دوم',
|
|
'category_uuid': str(self.category.uuid),
|
|
'city_uuid': str(self.city.uuid),
|
|
'address': 'خیابان دیگر',
|
|
})
|
|
self.assertEqual(response.status_code, 409)
|
|
|
|
def test_non_seller_cannot_access_seller_endpoints(self):
|
|
self.client.force_authenticate(user=self.customer)
|
|
response = self.client.get('/api/v1/seller/store/')
|
|
self.assertEqual(response.status_code, 404) # no store yet -> get_object_or_404
|