Skip to content

Commit

Permalink
Merge 25e3095 into 350ddf7
Browse files Browse the repository at this point in the history
  • Loading branch information
gwako94 committed Dec 21, 2018
2 parents 350ddf7 + 25e3095 commit ab3155b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion authors/apps/ratings/tests/test_ratings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework.reverse import reverse
from rest_framework import status
import logging
import json

# local imports
from .test_base import TestBase
Expand All @@ -20,6 +21,10 @@ def test_post_rating(self):
data=self.rating,
format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['message'],
"Rating added successfully")

def test_post_bad_rating(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.rater_token)
Expand All @@ -31,6 +36,10 @@ def test_post_bad_rating(self):
data=self.bad_rating,
format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['errors']['rating'],
['"10" is not a valid choice.'])

def test_article_author_cannot_rate(self):
self.client.credentials(
Expand All @@ -44,6 +53,10 @@ def test_article_author_cannot_rate(self):
data=self.rating,
format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['message'],
"You cannot rate your own article")

def test_get_average_rating(self):
self.client.credentials(
Expand All @@ -56,8 +69,11 @@ def test_get_average_rating(self):
"slug": self.slug
}),
format='json')
logger.error(response.content)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['rating'],
5.0)

def test_delete_rating(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.rater_token)
Expand All @@ -69,7 +85,12 @@ def test_delete_rating(self):
"id": self.id
}),
format='json')
logger.error(response.content)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['message'],
"Rating removed successfully")

def test_article_not_found_rate(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.rater_token)
Expand All @@ -80,7 +101,12 @@ def test_article_not_found_rate(self):
"slug": "not-found"}),
data=self.rating,
format='json')

self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['detail'],
"Article Not found")

def test_delete_rating_not_found(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.rater_token)
Expand All @@ -92,4 +118,9 @@ def test_delete_rating_not_found(self):
"id": 12
}),
format='json')
logger.error(response.content)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
json.loads(
response.content.decode('utf-8'))['detail'],
"Rating Not found")

0 comments on commit ab3155b

Please sign in to comment.