-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(favorite an article): favorite articles
- add tests for favoriting an article - add a favorites field to the article model - add a method in the serializer for favoriting an article - add a view for favoriting an article [Delivers #161966617]
- Loading branch information
salma-nyagaka
committed
Dec 13, 2018
1 parent
d007f82
commit 730abfb
Showing
6 changed files
with
116 additions
and
2 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
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,31 @@ | ||
from rest_framework import status | ||
from .base_test import BaseTestCase | ||
from django.urls import reverse | ||
|
||
|
||
class TestArticles(BaseTestCase): | ||
"class to test making an article a favorite" | ||
|
||
def test_favorite(self): | ||
"""test for favoriting an article""" | ||
self.user_signup() | ||
token = self.user_login() | ||
response = self.client.put(self.favorite_article(), format='json', HTTP_AUTHORIZATION='Token ' + token) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {'You have favorited this article'}) | ||
|
||
def unfavorite_article(self): | ||
"""test for favoriting an article that does not exist""" | ||
self.user_signup() | ||
token = self.user_login() | ||
response = self.client.put(self.unfavorite_article(), format='json', HTTP_AUTHORIZATION='Token ' + token) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {'You have removed this article from your favorites'}) | ||
|
||
def non_existing_article(self): | ||
"""test for favoriting an article that does not exist""" | ||
self.user_signup() | ||
token = self.user_login() | ||
response = self.client.put(self.favoritearticle_url, format='json', HTTP_AUTHORIZATION='Token ' + token) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {'You have removed this article from your favorites'}) |
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