From 136e7f9b16bb991be4e9b41e248069c8ad97791f Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Fri, 27 Jan 2017 13:14:45 -0500 Subject: [PATCH] Remove program certification view from the support app This functionality hasn't been used since it was introduced. It is superseded by the backpopulate_program_credentials management command. This is another commit in a series removing use of the old programs service from edx-platform. ECOM-4422 --- lms/djangoapps/support/tests/test_programs.py | 61 ------------------- lms/djangoapps/support/urls.py | 1 - lms/djangoapps/support/views/__init__.py | 1 - lms/djangoapps/support/views/programs.py | 50 --------------- 4 files changed, 113 deletions(-) delete mode 100644 lms/djangoapps/support/tests/test_programs.py delete mode 100644 lms/djangoapps/support/views/programs.py diff --git a/lms/djangoapps/support/tests/test_programs.py b/lms/djangoapps/support/tests/test_programs.py deleted file mode 100644 index c75760e5f8..0000000000 --- a/lms/djangoapps/support/tests/test_programs.py +++ /dev/null @@ -1,61 +0,0 @@ -# pylint: disable=missing-docstring -from django.core.urlresolvers import reverse -from django.test import TestCase -import mock -from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory - -from student.tests.factories import UserFactory - - -class IssueProgramCertificatesViewTests(TestCase): - password = 'password' - - def setUp(self): - super(IssueProgramCertificatesViewTests, self).setUp() - - self.path = reverse('support:programs-certify') - self.user = UserFactory(password=self.password, is_staff=True) - self.data = {'username': self.user.username} - self.headers = {} - - self.client.login(username=self.user.username, password=self.password) - - def _verify_response(self, status_code): - """Verify that the endpoint returns the provided status code and enqueues the task if appropriate.""" - with mock.patch('lms.djangoapps.support.views.programs.award_program_certificates.delay') as mock_task: - response = self.client.post(self.path, self.data, **self.headers) - - self.assertEqual(response.status_code, status_code) - self.assertEqual(status_code == 200, mock_task.called) - - def test_authentication_required(self): - """Verify that the endpoint requires authentication.""" - self.client.logout() - - self._verify_response(403) - - def test_session_auth(self): - """Verify that the endpoint supports session auth.""" - self._verify_response(200) - - def test_oauth(self): - """Verify that the endpoint supports OAuth 2.0.""" - access_token = AccessTokenFactory(user=self.user, client=ClientFactory()).token # pylint: disable=no-member - self.headers['HTTP_AUTHORIZATION'] = 'Bearer ' + access_token - - self.client.logout() - - self._verify_response(200) - - def test_staff_permissions_required(self): - """Verify that staff permissions are required to access the endpoint.""" - self.user.is_staff = False - self.user.save() # pylint: disable=no-member - - self._verify_response(403) - - def test_username_required(self): - """Verify that the endpoint returns a 400 when a username isn't provided.""" - self.data.pop('username') - - self._verify_response(400) diff --git a/lms/djangoapps/support/urls.py b/lms/djangoapps/support/urls.py index e0e0c9aad8..50ebe6021c 100644 --- a/lms/djangoapps/support/urls.py +++ b/lms/djangoapps/support/urls.py @@ -16,5 +16,4 @@ urlpatterns = patterns( views.EnrollmentSupportListView.as_view(), name="enrollment_list" ), - url(r'^programs/certify/$', views.IssueProgramCertificatesView.as_view(), name='programs-certify'), ) diff --git a/lms/djangoapps/support/views/__init__.py b/lms/djangoapps/support/views/__init__.py index 2c0ce8e9f7..fa1d3c46a9 100644 --- a/lms/djangoapps/support/views/__init__.py +++ b/lms/djangoapps/support/views/__init__.py @@ -6,4 +6,3 @@ from .index import * from .certificate import * from .enrollments import * from .refund import * -from .programs import IssueProgramCertificatesView diff --git a/lms/djangoapps/support/views/programs.py b/lms/djangoapps/support/views/programs.py deleted file mode 100644 index bd7aef710c..0000000000 --- a/lms/djangoapps/support/views/programs.py +++ /dev/null @@ -1,50 +0,0 @@ -# pylint: disable=missing-docstring -import logging - -from rest_framework import permissions, status, views -from rest_framework.authentication import SessionAuthentication -from rest_framework.response import Response -from rest_framework_oauth.authentication import OAuth2Authentication - -from openedx.core.djangoapps.programs.tasks.v1.tasks import award_program_certificates - - -log = logging.getLogger(__name__) - - -class IssueProgramCertificatesView(views.APIView): - """ - **Use Cases** - - Trigger the task responsible for awarding program certificates on behalf - of the user with the provided username. - - **Example Requests** - - POST /support/programs/certify/ - { - 'username': 'foo' - } - - **Returns** - - * 200 on success. - * 400 if program certification is disabled or a username is not provided. - * 401 if the request is not authenticated. - * 403 if the authenticated user does not have staff permissions. - """ - authentication_classes = (SessionAuthentication, OAuth2Authentication) - permission_classes = (permissions.IsAuthenticated, permissions.IsAdminUser,) - - def post(self, request): - username = request.data.get('username') - if username: - log.info('Enqueuing program certification task for user [%s]', username) - award_program_certificates.delay(username) - - return Response() - else: - return Response( - {'error': 'A username is required in order to issue program certificates.'}, - status=status.HTTP_400_BAD_REQUEST - )