gault-millau/apps/news/tests.py
2019-09-27 19:03:30 +03:00

53 lines
2.2 KiB
Python

from http.cookies import SimpleCookie
from rest_framework.test import APITestCase
from rest_framework import status
from datetime import datetime, timedelta
from news.models import NewsType, News
from account.models import User
# Create your tests here.
class BaseTestCase(APITestCase):
def setUp(self):
self.username = 'sedragurda'
self.password = 'sedragurdaredips19'
self.email = 'sedragurda@desoz.com'
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')})
self.test_news_type = NewsType.objects.create(name="Test news type")
self.test_news = News.objects.create(created_by=self.user, modified_by=self.user, title={"en-GB": "Test news"},
news_type=self.test_news_type, description={"en-GB": "Description test news"},
playlist=1, start=datetime.now() + timedelta(hours=-2),
end=datetime.now() + timedelta(hours=2),
state=News.PUBLISHED, slug='test-news-slug',)
class NewsTestCase(BaseTestCase):
def test_news_list(self):
response = self.client.get("/api/web/news/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_news_web_detail(self):
response = self.client.get(f"/api/web/news/slug/{self.test_news.slug}/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_news_back_detail(self):
response = self.client.get(f"/api/back/news/{self.test_news.id}/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_news_list_back(self):
response = self.client.get("/api/back/news/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_news_type_list(self):
response = self.client.get("/api/web/news/types/")
self.assertEqual(response.status_code, status.HTTP_200_OK)