From b75ac46c882dc86bb4160ebe9f60c68335c6b177 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 23 Sep 2019 18:38:39 +0500 Subject: [PATCH] Add favorites tests --- apps/favorites/tests.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/apps/favorites/tests.py b/apps/favorites/tests.py index a39b155a..bc3313ae 100644 --- a/apps/favorites/tests.py +++ b/apps/favorites/tests.py @@ -1 +1,55 @@ # Create your tests here. +from http.cookies import SimpleCookie +from django.contrib.contenttypes.models import ContentType + +from rest_framework.test import APITestCase +from rest_framework import status + +from account.models import User +from favorites.models import Favorites +from establishment.models import Establishment, EstablishmentType, EstablishmentSubType +from news.models import NewsType, News + + +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) + 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) + + self.test_content_type = ContentType.objects.get(app_label="news", model="news") + + self.test_favorites = Favorites.objects.create(user=self.user, content_type=self.test_content_type, + object_id=self.test_news.id) + + self.test_establishment_type = EstablishmentType.objects.create(name={"en-GB": "test establishment type"}, + use_subtypes=False) + + self.test_establishment = Establishment.objects.create(name="test establishment", + name_transliterated="test-establishment", + description={"en-GB": "description of test establishment"}, + establishment_type=self.test_establishment_type, + is_publish=True) + # value for GenericRelation(reverse side) field must be iterable + # value for GenericRelation(reverse side) field must be assigned through "set" method of field + self.test_establishment.favorites.set([self.test_favorites]) + + +class FavoritesTestCase(BaseTestCase): + + def test_func(self): + response = self.client.get("/api/web/favorites/establishments/") + print(response.json()) + self.assertEqual(response.status_code, status.HTTP_200_OK) \ No newline at end of file