-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
165305760-Feature(Rating): Users are able to rate an article
- User can rate an article - fix codeclimate issues - Return average ratings - Added a standard response message starts #165305760
- Loading branch information
Showing
14 changed files
with
324 additions
and
124 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
43 changes: 43 additions & 0 deletions
43
authors/apps/articles/migrations/0002_auto_20190510_0825.py
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,43 @@ | ||
# Generated by Django 2.2 on 2019-05-10 08:25 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('articles', '0001_initial'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ratingmodel', | ||
name='rated_by', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rated_by', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='favorite', | ||
name='article', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article'), | ||
), | ||
migrations.AddField( | ||
model_name='favorite', | ||
name='user', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='author', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='tags', | ||
field=models.ManyToManyField(to='articles.Tag'), | ||
), | ||
] |
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,49 @@ | ||
import json | ||
|
||
from rest_framework.views import status | ||
from .basetests import BaseTest | ||
|
||
|
||
class RatingArticlesTest(BaseTest): | ||
""" | ||
Test cases for article ratings | ||
""" | ||
unauthorized = "Authentication credentials were not provided." | ||
|
||
def test_rate_an_article_with_authorized_user(self): | ||
""" | ||
Test if an article is rated when no data is passed | ||
""" | ||
rating = self.rate_article() | ||
self.assertEqual(rating.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_update_ratings_on_an_article_with_authorized_user(self): | ||
""" | ||
Test if an article is rated when no data is passed | ||
""" | ||
rating = self.update_rate_article() | ||
self.assertEqual(rating.status_code, status.HTTP_201_CREATED) | ||
|
||
|
||
def test_rate_an_article_with_greater_than_five(self): | ||
""" | ||
Test if an article is rated when the rate is more that 5 | ||
""" | ||
rating = self.rate_article_more_than_five() | ||
self.assertEqual(rating.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
def test_rate_an_article_with_less_than_one(self): | ||
""" | ||
Test if an article is rated when that rate is less than 1 | ||
""" | ||
rating = self.rate_article_less_than_one() | ||
self.assertEqual(rating.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
def test_rate_a_non_existing_article(self): | ||
""" | ||
Test if an article is rated when article doesn't exist | ||
""" | ||
|
||
rating = self.rate_non_existing_article() | ||
self.assertEqual(rating.status_code, status.HTTP_404_NOT_FOUND) |
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.