Commit 4860837e by Will Daly

Merge pull request #7418 from edx/sanchez/revert_201_status_for_enrollments

Reverting the change to add a 201_CREATED status to the enrollment API.
parents 6ac1b82b 4acfbbdf
...@@ -298,11 +298,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase): ...@@ -298,11 +298,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
) )
for attempt in xrange(self.rate_limit + 10): for attempt in xrange(self.rate_limit + 10):
expected_status = status.HTTP_200_OK expected_status = status.HTTP_429_TOO_MANY_REQUESTS if attempt >= self.rate_limit else status.HTTP_200_OK
if attempt == 0:
expected_status = status.HTTP_201_CREATED
elif attempt >= self.rate_limit:
expected_status = status.HTTP_429_TOO_MANY_REQUESTS
self._create_enrollment(expected_status=expected_status) self._create_enrollment(expected_status=expected_status)
def test_enrollment_throttle_for_service(self): def test_enrollment_throttle_for_service(self):
...@@ -316,8 +312,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase): ...@@ -316,8 +312,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
) )
for attempt in xrange(self.rate_limit + 10): for attempt in xrange(self.rate_limit + 10):
expected_status = status.HTTP_201_CREATED if attempt == 0 else status.HTTP_200_OK self._create_enrollment(as_server=True)
self._create_enrollment(as_server=True, expected_status=expected_status)
def test_create_enrollment_with_mode(self): def test_create_enrollment_with_mode(self):
"""With the right API key, create a new enrollment with a mode set other than the default.""" """With the right API key, create a new enrollment with a mode set other than the default."""
...@@ -415,7 +410,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase): ...@@ -415,7 +410,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
self, self,
course_id=None, course_id=None,
username=None, username=None,
expected_status=status.HTTP_201_CREATED, expected_status=status.HTTP_200_OK,
email_opt_in=None, email_opt_in=None,
as_server=False, as_server=False,
mode=CourseMode.HONOR, mode=CourseMode.HONOR,
...@@ -440,7 +435,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase): ...@@ -440,7 +435,7 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
self.assertEqual(resp.status_code, expected_status) self.assertEqual(resp.status_code, expected_status)
if expected_status in [status.HTTP_201_CREATED, status.HTTP_200_OK]: if expected_status in [status.HTTP_200_OK, status.HTTP_200_OK]:
data = json.loads(resp.content) data = json.loads(resp.content)
self.assertEqual(course_id, data['course_details']['course_id']) self.assertEqual(course_id, data['course_details']['course_id'])
self.assertEqual(mode, data['mode']) self.assertEqual(mode, data['mode'])
...@@ -499,7 +494,7 @@ class EnrollmentEmbargoTest(UrlResetMixin, ModuleStoreTestCase): ...@@ -499,7 +494,7 @@ class EnrollmentEmbargoTest(UrlResetMixin, ModuleStoreTestCase):
}) })
response = self.client.post(url, data, content_type='application/json') response = self.client.post(url, data, content_type='application/json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.status_code, status.HTTP_200_OK)
# Verify that we were enrolled # Verify that we were enrolled
self.assertEqual(len(self._get_enrollments()), 1) self.assertEqual(len(self._get_enrollments()), 1)
......
...@@ -381,15 +381,13 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn): ...@@ -381,15 +381,13 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
enrollment = api.get_enrollment(user, unicode(course_id)) enrollment = api.get_enrollment(user, unicode(course_id))
if has_api_key_permissions and enrollment and enrollment['mode'] != mode: if has_api_key_permissions and enrollment and enrollment['mode'] != mode:
response = api.update_enrollment(user, unicode(course_id), mode=mode) response = api.update_enrollment(user, unicode(course_id), mode=mode)
http_success_status = status.HTTP_200_OK
else: else:
response = api.add_enrollment(user, unicode(course_id), mode=mode) response = api.add_enrollment(user, unicode(course_id), mode=mode)
http_success_status = status.HTTP_201_CREATED
email_opt_in = request.DATA.get('email_opt_in', None) email_opt_in = request.DATA.get('email_opt_in', None)
if email_opt_in is not None: if email_opt_in is not None:
org = course_id.org org = course_id.org
update_email_opt_in(request.user, org, email_opt_in) update_email_opt_in(request.user, org, email_opt_in)
return Response(response, status=http_success_status) return Response(response)
except CourseModeNotFoundError as error: except CourseModeNotFoundError as error:
return Response( return Response(
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
......
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