Add list read test
Add detail read test
This commit is contained in:
parent
2c43a37108
commit
466c0f80d7
|
|
@ -1,3 +1,94 @@
|
||||||
from django.test import TestCase
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
from account.models import User
|
||||||
|
from rest_framework import status
|
||||||
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
|
from collection.models import Collection
|
||||||
|
from location.models import Country
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
|
def setUpT(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 tokkens
|
||||||
|
tokkens = User.create_jwt_tokens(self.user)
|
||||||
|
self.client.cookies = SimpleCookie(
|
||||||
|
{'access_token': tokkens.get('access_token'),
|
||||||
|
'refresh_token': tokkens.get('refresh_token')})
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionListTests(BaseTestCase):
|
||||||
|
def test_collection_list_Read(self):
|
||||||
|
response = self.client.get('/api/web/collections/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionDetailTests(BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
country = Country.objects.first()
|
||||||
|
if not country:
|
||||||
|
country = Country.objects.create(
|
||||||
|
name=json.dumps({"en-GB": "Test country"}),
|
||||||
|
code="test"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.collection = Collection.objects.create(
|
||||||
|
name='Test collection',
|
||||||
|
is_publish=True,
|
||||||
|
start=datetime.now(),
|
||||||
|
end=datetime.now(),
|
||||||
|
country=country
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_collection_detail_Read(self):
|
||||||
|
response = self.client.get(f'/api/web/collections/{self.collection.id}/', format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# data = {
|
||||||
|
# 'name': 'Test collection',
|
||||||
|
#
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# 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 ChildTestCase(BaseTestCase):
|
||||||
|
# def setUp(self):
|
||||||
|
# super().setUp()
|
||||||
|
# self.establishment = Establishment.objects.create(
|
||||||
|
# name="Test establishment",
|
||||||
|
# establishment_type_id=self.establishment_type.id,
|
||||||
|
# is_publish=True
|
||||||
|
# )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user