Add tests to guide
This commit is contained in:
parent
aedcd795a9
commit
b4a2893fcd
|
|
@ -1,11 +1,11 @@
|
||||||
import json
|
import json, pytz
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
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 collection.models import Collection
|
from collection.models import Collection, Guide
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
@ -13,7 +13,7 @@ from location.models import Country
|
||||||
|
|
||||||
class BaseTestCase(APITestCase):
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
def setUpT(self):
|
def setUp(self):
|
||||||
self.username = 'sedragurda'
|
self.username = 'sedragurda'
|
||||||
self.password = 'sedragurdaredips19'
|
self.password = 'sedragurdaredips19'
|
||||||
self.email = 'sedragurda@desoz.com'
|
self.email = 'sedragurda@desoz.com'
|
||||||
|
|
@ -24,7 +24,8 @@ class BaseTestCase(APITestCase):
|
||||||
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'),
|
||||||
|
'country_code': 'en'})
|
||||||
|
|
||||||
|
|
||||||
class CollectionListTests(BaseTestCase):
|
class CollectionListTests(BaseTestCase):
|
||||||
|
|
@ -42,53 +43,40 @@ class CollectionDetailTests(BaseTestCase):
|
||||||
if not country:
|
if not country:
|
||||||
country = Country.objects.create(
|
country = Country.objects.create(
|
||||||
name=json.dumps({"en-GB": "Test country"}),
|
name=json.dumps({"en-GB": "Test country"}),
|
||||||
code="test"
|
code="en"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.collection = Collection.objects.create(
|
self.collection = Collection.objects.create(
|
||||||
name='Test collection',
|
name='Test collection',
|
||||||
is_publish=True,
|
is_publish=True,
|
||||||
start=datetime.now(),
|
start=datetime.now(pytz.utc),
|
||||||
end=datetime.now(),
|
end=datetime.now(pytz.utc),
|
||||||
country=country
|
country=country
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_collection_detail_Read(self):
|
def test_collection_detail_Read(self):
|
||||||
response = self.client.get(f'/api/web/collections/{self.collection.id}/', format='json')
|
response = self.client.get(f'/api/web/collections/{self.collection.id}/establishments/?country_code=en',
|
||||||
|
format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionGuideTests(CollectionDetailTests):
|
||||||
|
|
||||||
# data = {
|
def test_guide_list_Read(self):
|
||||||
# 'name': 'Test collection',
|
response = self.client.get('/api/web/collections/guides/', format='json')
|
||||||
#
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
# }
|
|
||||||
#
|
|
||||||
# response = self.client.post('/api/web/collections/', data=data, format='json')
|
|
||||||
# self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
||||||
#
|
|
||||||
# establishment = response.json()
|
|
||||||
#
|
|
||||||
# response = self.client.get(f'/api/back/establishments/{establishment["id"]}/', format='json')
|
|
||||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
#
|
|
||||||
# update_data = {
|
|
||||||
# 'name': 'Test new establishment'
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# response = self.client.patch(f'/api/back/establishments/{establishment["id"]}/', data=update_data)
|
|
||||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
||||||
#
|
|
||||||
# response = self.client.delete(f'/api/back/establishments/{establishment["id"]}/', format='json')
|
|
||||||
# self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
# Class to test childs
|
class CollectionGuideDetailTests(CollectionDetailTests):
|
||||||
# class ChildTestCase(BaseTestCase):
|
|
||||||
# def setUp(self):
|
def setUp(self):
|
||||||
# super().setUp()
|
super().setUp()
|
||||||
# self.establishment = Establishment.objects.create(
|
self.guide = Guide.objects.create(
|
||||||
# name="Test establishment",
|
collection=self.collection,
|
||||||
# establishment_type_id=self.establishment_type.id,
|
start=datetime.now(pytz.utc),
|
||||||
# is_publish=True
|
end=datetime.now(pytz.utc)
|
||||||
# )
|
)
|
||||||
|
|
||||||
|
def test_guide_detail_Read(self):
|
||||||
|
response = self.client.get(f'/api/web/collections/guides/{self.guide.id}/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user