Add address CRUD tests
This commit is contained in:
parent
a9f13ac283
commit
2f61df2c65
|
|
@ -1,3 +1,73 @@
|
||||||
from django.test import TestCase
|
from rest_framework.test import APITestCase
|
||||||
|
from account.models import User
|
||||||
|
from rest_framework import status
|
||||||
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
# Create your tests here.
|
from location.models import City, Region, Country
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.username = 'sedragurda'
|
||||||
|
self.password = 'sedragurdaredips19'
|
||||||
|
self.email = 'sedragurda@desoz.com'
|
||||||
|
self.newsletter = True
|
||||||
|
self.user = User.objects.create_user(
|
||||||
|
username=self.username, email=self.email, password=self.password)
|
||||||
|
|
||||||
|
# get tokens
|
||||||
|
|
||||||
|
tokkens = User.create_jwt_tokens(self.user)
|
||||||
|
self.client.cookies = SimpleCookie(
|
||||||
|
{'access_token': tokkens.get('access_token'),
|
||||||
|
'refresh_token': tokkens.get('refresh_token')})
|
||||||
|
|
||||||
|
|
||||||
|
class AddressTests(BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self.country = Country(
|
||||||
|
name="Test country",
|
||||||
|
code="+7"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.region = Region(
|
||||||
|
name="Test region",
|
||||||
|
code="812",
|
||||||
|
country=self.country
|
||||||
|
)
|
||||||
|
|
||||||
|
self.city = City(
|
||||||
|
name="Test region",
|
||||||
|
code="812",
|
||||||
|
region=self.region,
|
||||||
|
country=self.country
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_address_CRUD(self):
|
||||||
|
response = self.client.get('/api/back/location/addresses/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'user': self.user.id,
|
||||||
|
'name': 'Test name'
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post('/api/back/location/addresses/', data=data)
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.patch('/api/back/location/addresses/1/', data=update_data)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
response = self.client.delete('/api/back/location/addresses/1/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user