-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug(articles): Fix users unable to see likes and dislikes in articles:
- add likes and dislikes fields in ArticleSerializer [Finishes #162163173]
- Loading branch information
Eric Ebulu
authored and
Eric Ebulu
committed
Dec 18, 2018
1 parent
52ce0d0
commit d524cef
Showing
7 changed files
with
300 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from rest_framework.test import APIClient | ||
from .base_test import BaseTest | ||
from rest_framework import status | ||
|
||
|
||
class Test_Impression(BaseTest): | ||
|
||
def test_add_like_impression(self): | ||
created_article = self.client.post( | ||
'/api/articles/', data=self.new_article, format='json') | ||
slug = self.get_slug(created_article) | ||
|
||
reponse = self.client.post( | ||
'/api/articles/like/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
self.assertEqual(reponse.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_add_dislike_impression(self): | ||
created_article = self.client.post( | ||
'/api/articles/', data=self.new_article, format='json') | ||
slug = self.get_slug(created_article) | ||
|
||
reponse = self.client.post( | ||
'/api/articles/dislike/{}'.format(slug), | ||
data=self.article_without_title, | ||
format='json') | ||
self.assertEqual(reponse.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_user_is_neutral_after_liking_twice(self): | ||
created_article = self.client.post( | ||
'/api/articles/', data=self.new_article, format='json') | ||
slug = self.get_slug(created_article) | ||
|
||
self.client.post( | ||
'/api/articles/like/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
self.client.post( | ||
'/api/articles/like/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
reponse = self.client.get('/api/articles/', format='json') | ||
self.assertEqual(reponse.status_code, status.HTTP_200_OK) | ||
|
||
|
||
def test_user_can_not_dislike_and_like_an_article(self): | ||
created_article = self.client.post( | ||
'/api/articles/', data=self.new_article, format='json') | ||
slug = self.get_slug(created_article) | ||
|
||
self.client.post( | ||
'/api/articles/dislike/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
self.client.post( | ||
'/api/articles/like/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
reponse = self.client.get('/api/articles/', format='json') | ||
self.assertEqual(reponse.status_code, status.HTTP_200_OK) | ||
|
||
|
||
def test_user_can_not_like_and_dislike_an_article(self): | ||
created_article = self.client.post( | ||
'/api/articles/', data=self.new_article, format='json') | ||
slug = self.get_slug(created_article) | ||
|
||
self.client.post( | ||
'/api/articles/like/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
self.client.post( | ||
'/api/articles/dislike/{}'.format(slug), | ||
data=self.new_article, | ||
format='json') | ||
reponse = self.client.get('/api/articles/', format='json') | ||
self.assertEqual(reponse.status_code, status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
from django.urls import include, path | ||
from rest_framework.routers import DefaultRouter | ||
from .views import ArticleViewSet, ArticleRetrieve, RatingsView | ||
from .views import ( | ||
ArticleViewSet, ArticleRetrieve, | ||
LikeArticle, DislikeArticle, RatingsView) | ||
|
||
|
||
urlpatterns = [ | ||
path('articles/', ArticleViewSet.as_view()), | ||
path('articles/<slug>', ArticleRetrieve.as_view()), | ||
path('articles/<slug>/ratings/', RatingsView.as_view()), | ||
path('articles/like/<slug>', LikeArticle.as_view()), | ||
path('articles/dislike/<slug>', DislikeArticle.as_view()) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.