From d62cee341cddc5195f8aa97c43cbd254c942dde7 Mon Sep 17 00:00:00 2001 From: littlewolf Date: Tue, 24 Sep 2019 21:03:50 +0300 Subject: [PATCH] Add address tests --- apps/location/tests.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/location/tests.py b/apps/location/tests.py index cab871a0..a3213e69 100644 --- a/apps/location/tests.py +++ b/apps/location/tests.py @@ -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)