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 rest_framework.test import APITestCase
|
||||||
from account.models import User
|
from account.models import User
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
|
from django.contrib.gis.db.models import PointField
|
||||||
from location.models import City, Region, Country
|
from location.models import City, Region, Country
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,19 +31,18 @@ class AddressTests(BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
self.country = Country.objects.create(
|
||||||
self.country = Country(
|
name=json.dumps({"en-GB": "Test country"}),
|
||||||
name="Test country",
|
code="test"
|
||||||
code="+7"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.region = Region(
|
self.region = Region.objects.create(
|
||||||
name="Test region",
|
name="Test region",
|
||||||
code="812",
|
code="812",
|
||||||
country=self.country
|
country=self.country
|
||||||
)
|
)
|
||||||
|
|
||||||
self.city = City(
|
self.city = City.objects.create(
|
||||||
name="Test region",
|
name="Test region",
|
||||||
code="812",
|
code="812",
|
||||||
region=self.region,
|
region=self.region,
|
||||||
|
|
@ -52,18 +54,25 @@ class AddressTests(BaseTestCase):
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'user': self.user.id,
|
'city_id': self.city.id,
|
||||||
'name': 'Test name'
|
'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)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
response = self.client.get('/api/back/location/addresses/1/', format='json')
|
response = self.client.get('/api/back/location/addresses/1/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
update_data = {
|
update_data = {
|
||||||
'name': 'Test new name'
|
'number': '+79999991'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.patch('/api/back/location/addresses/1/', data=update_data)
|
response = self.client.patch('/api/back/location/addresses/1/', data=update_data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user