Add address tests
This commit is contained in:
parent
2f61df2c65
commit
d62cee341c
|
|
@ -1,8 +1,11 @@
|
|||
import json
|
||||
|
||||
from rest_framework.test import APITestCase
|
||||
from account.models import User
|
||||
from rest_framework import status
|
||||
from http.cookies import SimpleCookie
|
||||
|
||||
from django.contrib.gis.db.models import PointField
|
||||
from location.models import City, Region, Country
|
||||
|
||||
|
||||
|
|
@ -28,19 +31,18 @@ class AddressTests(BaseTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.country = Country(
|
||||
name="Test country",
|
||||
code="+7"
|
||||
self.country = Country.objects.create(
|
||||
name=json.dumps({"en-GB": "Test country"}),
|
||||
code="test"
|
||||
)
|
||||
|
||||
self.region = Region(
|
||||
self.region = Region.objects.create(
|
||||
name="Test region",
|
||||
code="812",
|
||||
country=self.country
|
||||
)
|
||||
|
||||
self.city = City(
|
||||
self.city = City.objects.create(
|
||||
name="Test region",
|
||||
code="812",
|
||||
region=self.region,
|
||||
|
|
@ -52,18 +54,25 @@ class AddressTests(BaseTestCase):
|
|||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
data = {
|
||||
'user': self.user.id,
|
||||
'name': 'Test name'
|
||||
'city_id': self.city.id,
|
||||
'number': '+79999999',
|
||||
"coordinates": {
|
||||
"latitude": 37.0625,
|
||||
"longitude": -95.677068
|
||||
},
|
||||
"geo_lon": -95.677068,
|
||||
"geo_lat": 37.0625
|
||||
}
|
||||
|
||||
response = self.client.post('/api/back/location/addresses/', data=data)
|
||||
response = self.client.post('/api/back/location/addresses/', data=data, format='json')
|
||||
print(f"=========RESPONSE: {response.json()}")
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
response = self.client.get('/api/back/location/addresses/1/', format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
update_data = {
|
||||
'name': 'Test new name'
|
||||
'number': '+79999991'
|
||||
}
|
||||
|
||||
response = self.client.patch('/api/back/location/addresses/1/', data=update_data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user