-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
266 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .models import ReportedArticle | ||
from django.contrib import admin | ||
|
||
|
||
admin.site.register(ReportedArticle) |
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
44 changes: 44 additions & 0 deletions
44
authors/apps/articles/migrations/0002_auto_20190320_1150.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,44 @@ | ||
# Generated by Django 2.1.5 on 2019-03-20 11:50 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('profiles', '0001_initial'), | ||
('articles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='rating', | ||
name='rated_by', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='scores', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='articlelikesdislikes', | ||
name='article', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article'), | ||
), | ||
migrations.AddField( | ||
model_name='articlelikesdislikes', | ||
name='user', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile'), | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='author', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='author_articles', to='profiles.Profile'), | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='favorites', | ||
field=models.ManyToManyField(blank=True, related_name='favorited_articles', to='profiles.Profile'), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -15,3 +15,7 @@ | |
"tagList": ["test", "apps"] | ||
} | ||
} | ||
|
||
valid_reported_article={ | ||
"reason":"The post is copied from test.com" | ||
} |
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,52 @@ | ||
from rest_framework import status | ||
from authors.apps.articles.tests.base_class import ArticlesBaseTest | ||
from .test_data import valid_reported_article | ||
from authors.apps.articles.models import Article | ||
from django.urls import reverse | ||
|
||
|
||
class TestReportArticle(ArticlesBaseTest): | ||
def test_can_not_report_own_article(self): | ||
""" | ||
Tests method tests a user who is authenticated can report his/her own article | ||
""" | ||
|
||
self.add_article() | ||
|
||
article = Article.objects.all().first() | ||
response = self.client.post( | ||
reverse('articles:report-article', | ||
kwargs={'slug': article.slug}), | ||
data=valid_reported_article, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
self.assertEqual(response.data['message'], | ||
'You cannot report your own article') | ||
|
||
def test_can_report_some_article(self): | ||
""" | ||
Tests if a user who is authenticated can report some article | ||
""" | ||
|
||
self.add_article() | ||
self.register_and_login_new_user() | ||
|
||
article = Article.objects.all().first() | ||
response = self.client.post( | ||
reverse('articles:report-article', | ||
kwargs={'slug': article.slug}), | ||
data=valid_reported_article, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_can_report_some_article_not_logged_in(self): | ||
""" | ||
Tests if a user who is authenticated can report some article | ||
""" | ||
self.add_article() | ||
article = Article.objects.all().first() | ||
self.client.credentials(HTTP_AUTHORIZATION='') | ||
response = self.client.post( | ||
reverse('articles:report-article', | ||
kwargs={'slug': article.slug}), | ||
data=valid_reported_article, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
self.assertEqual(response.data['detail'], 'Authentication credentials were not provided.') |
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
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
Oops, something went wrong.