-
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.
- add endpoint for reporting articles - add endpoint for getting reported articles [#161966626]
- Loading branch information
1 parent
8e2bd92
commit f2f22aa
Showing
6 changed files
with
155 additions
and
7 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,38 @@ | ||
from django.urls import reverse | ||
from authors.apps.authentication.models import User | ||
from .base_test import BaseTestCase | ||
from rest_framework import status | ||
|
||
|
||
class TestReports(BaseTestCase): | ||
def test_report_article_with_valid_data(self): | ||
response = self.create_report(self.valid_report_data) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_report_article_with_invalid_data(self): | ||
response = self.create_report(self.invalid_report_data) | ||
resp = str(response.data.get("errors", {}).get("report", '')) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual('is not a valid choice' in resp, True) | ||
|
||
def test_get_report_as_not_admin(self): | ||
article_url, response, token = self.create_article() | ||
response = self.test_client.post(reverse('articles:report-list'), format='json', | ||
HTTP_AUTHORIZATION=token) | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
def test_get_report_as_admin(self): | ||
User.objects.create_superuser('admin', 'admin@admin.com', 'adminp@ssw0rd') | ||
login_data = {"user": { | ||
"email": "admin@admin.com", | ||
"password": "adminp@ssw0rd" | ||
} | ||
} | ||
admin = self.test_client.post( | ||
self.login_url, | ||
login_data, | ||
format='json') | ||
admin_token = 'Token ' + admin.data['token'] | ||
response = self.test_client.get(reverse('articles:report-list'), format='json', | ||
HTTP_AUTHORIZATION=admin_token) | ||
self.assertEqual(response.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,9 +1,11 @@ | ||
from django.urls import path | ||
|
||
from .views import ArticleAPIView, SpecificArticleAPIView | ||
from .views import ArticleAPIView, SpecificArticleAPIView, ReportListAPIView, ReportArticleAPIView | ||
|
||
|
||
urlpatterns = [ | ||
path('articles/', ArticleAPIView.as_view(), name='articles'), | ||
path('articles/<slug>', SpecificArticleAPIView.as_view(), name='get_article') | ||
path('articles/<slug>', SpecificArticleAPIView.as_view(), name='get_article'), | ||
path('articles/<str:slug>/report/', ReportArticleAPIView.as_view(), name='report'), | ||
path('articles/reports/', ReportListAPIView.as_view(), name='report-list'), | ||
] |
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