Commit 0646f9bf by christopher lee

MA-1637 Discussion API now uses the view_auth_classes for permissions

Added missing unit tests.
parent 8e20faae
...@@ -71,6 +71,10 @@ class DiscussionAPIViewTestMixin(CommentsServiceMockMixin, UrlResetMixin): ...@@ -71,6 +71,10 @@ class DiscussionAPIViewTestMixin(CommentsServiceMockMixin, UrlResetMixin):
{"developer_message": "Authentication credentials were not provided."} {"developer_message": "Authentication credentials were not provided."}
) )
def test_inactive(self):
self.user.is_active = False
self.test_basic()
@mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
...@@ -89,7 +93,7 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -89,7 +93,7 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
{"developer_message": "Course not found."} {"developer_message": "Course not found."}
) )
def test_get_success(self): def test_basic(self):
response = self.client.get(self.url) response = self.client.get(self.url)
self.assert_response_correct( self.assert_response_correct(
response, response,
...@@ -150,7 +154,7 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -150,7 +154,7 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
{"developer_message": "Course not found."} {"developer_message": "Course not found."}
) )
def test_get_success(self): def test_basic(self):
response = self.client.get(self.url) response = self.client.get(self.url)
self.assert_response_correct( self.assert_response_correct(
response, response,
......
...@@ -3,9 +3,6 @@ Discussion API views ...@@ -3,9 +3,6 @@ Discussion API views
""" """
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from rest_framework.authentication import SessionAuthentication
from rest_framework_oauth.authentication import OAuth2Authentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet from rest_framework.viewsets import ViewSet
...@@ -28,19 +25,11 @@ from discussion_api.api import ( ...@@ -28,19 +25,11 @@ from discussion_api.api import (
update_thread, update_thread,
) )
from discussion_api.forms import CommentListGetForm, ThreadListGetForm, _PaginationForm from discussion_api.forms import CommentListGetForm, ThreadListGetForm, _PaginationForm
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
class _ViewMixin(object): @view_auth_classes()
""" class CourseView(DeveloperErrorViewMixin, APIView):
Mixin to provide common characteristics and utility functions for Discussion
API views
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
class CourseView(_ViewMixin, DeveloperErrorViewMixin, APIView):
""" """
**Use Cases** **Use Cases**
...@@ -72,7 +61,8 @@ class CourseView(_ViewMixin, DeveloperErrorViewMixin, APIView): ...@@ -72,7 +61,8 @@ class CourseView(_ViewMixin, DeveloperErrorViewMixin, APIView):
return Response(get_course(request, course_key)) return Response(get_course(request, course_key))
class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView): @view_auth_classes()
class CourseTopicsView(DeveloperErrorViewMixin, APIView):
""" """
**Use Cases** **Use Cases**
...@@ -106,7 +96,8 @@ class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView): ...@@ -106,7 +96,8 @@ class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView):
return Response(response) return Response(response)
class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): @view_auth_classes()
class ThreadViewSet(DeveloperErrorViewMixin, ViewSet):
""" """
**Use Cases** **Use Cases**
...@@ -294,7 +285,8 @@ class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): ...@@ -294,7 +285,8 @@ class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet):
return Response(status=204) return Response(status=204)
class CommentViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): @view_auth_classes()
class CommentViewSet(DeveloperErrorViewMixin, ViewSet):
""" """
**Use Cases** **Use Cases**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment