Fix
This commit is contained in:
parent
7a4005ec21
commit
5772558c4b
|
|
@ -5,8 +5,8 @@ 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 location.models import City, Region, Country
|
from location.models import City, Region, Country, Language
|
||||||
|
from account.models import Role, UserRole
|
||||||
|
|
||||||
class BaseTestCase(APITestCase):
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
|
|
@ -20,27 +20,39 @@ class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
# get tokens
|
# get tokens
|
||||||
|
|
||||||
|
# self.user.is_superuser = True
|
||||||
|
# self.user.save()
|
||||||
|
|
||||||
tokkens = User.create_jwt_tokens(self.user)
|
tokkens = User.create_jwt_tokens(self.user)
|
||||||
self.client.cookies = SimpleCookie(
|
self.client.cookies = SimpleCookie(
|
||||||
{'access_token': tokkens.get('access_token'),
|
{'access_token': tokkens.get('access_token'),
|
||||||
'refresh_token': tokkens.get('refresh_token')})
|
'refresh_token': tokkens.get('refresh_token')})
|
||||||
|
|
||||||
|
self.lang = Language.objects.create(
|
||||||
|
title='Russia',
|
||||||
|
locale='ru-RU'
|
||||||
|
)
|
||||||
|
self.lang.save()
|
||||||
|
|
||||||
|
# role = Role.objects.create(role=Role.COUNTRY_ADMIN)
|
||||||
|
|
||||||
|
|
||||||
class CountryTests(BaseTestCase):
|
class CountryTests(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
def test_country_CRUD(self):
|
def test_country_CRUD(self):
|
||||||
response = self.client.get('/api/back/location/countries/', format='json')
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'name': 'Test country',
|
'name': {"ru-RU":"Russia"},
|
||||||
'code': 'test'
|
'code': 'test'
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.post('/api/back/location/countries/', data=data, format='json')
|
response = self.client.post('/api/back/location/countries/', data=data, format='json')
|
||||||
response_data = response.json()
|
response_data = 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/countries/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
response = self.client.get(f'/api/back/location/countries/{response_data["id"]}/', format='json')
|
response = self.client.get(f'/api/back/location/countries/{response_data["id"]}/', format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,15 @@ class RegionRUDView(common.RegionViewMixin, generics.RetrieveUpdateDestroyAPIVie
|
||||||
serializer_class = serializers.RegionSerializer
|
serializer_class = serializers.RegionSerializer
|
||||||
permission_classes = [IsCountryAdmin]
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
|
|
||||||
# Country
|
# Country
|
||||||
class CountryListCreateView(common.CountryViewMixin, generics.ListCreateAPIView):
|
class CountryListCreateView(generics.ListCreateAPIView):
|
||||||
"""List/Create view for model Country."""
|
"""List/Create view for model Country."""
|
||||||
serializer_class = serializers.CountryBackSerializer
|
serializer_class = serializers.CountryBackSerializer
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
permission_classes = [IsCountryAdmin]
|
permission_classes = [IsCountryAdmin]
|
||||||
|
|
||||||
class CountryRUDView(common.CountryViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
class CountryRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""RUD view for model Country."""
|
"""RUD view for model Country."""
|
||||||
serializer_class = serializers.CountryBackSerializer
|
serializer_class = serializers.CountryBackSerializer
|
||||||
permission_classes = [IsCountryAdmin]
|
permission_classes = [IsCountryAdmin]
|
||||||
Loading…
Reference in New Issue
Block a user