Add news tests
This commit is contained in:
parent
1e1b09660d
commit
7729ab5653
|
|
@ -1,3 +1,44 @@
|
|||
from http.cookies import SimpleCookie
|
||||
|
||||
from django.test import TestCase
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
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="2020-12-03 12:00:00", end="2020-12-13 12:00:00",
|
||||
is_publish=True)
|
||||
|
||||
|
||||
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_detail(self):
|
||||
response = self.client.get(f"/api/web/news/{self.test_news.id}/")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_news_type_list(self):
|
||||
response = self.client.get("/api/web/news/type/")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user