Merge pull request #21544 from amitvadhel/BOM-127

BOM-127
This commit is contained in:
Feanil Patel
2019-09-05 11:30:22 -04:00
committed by GitHub
2 changed files with 11 additions and 8 deletions

View File

@@ -350,7 +350,10 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
'cohorts': "cohort1,cohort2"
})
self.assertEqual(response.status_code, 400)
self.assertIn('If provided, the cohorts and courses should have equal number of items.', response.content)
self.assertIn(
'If provided, the cohorts and courses should have equal number of items.',
response.content.decode('utf-8')
)
def test_fail_on_missing_cohorts(self):
"""
@@ -366,7 +369,7 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
self.assertEqual(response.status_code, 400)
self.assertIn(u'cohort {cohort_name} not found in course {course_id}.'.format(
cohort_name='cohort1', course_id=self.course_key
), response.content)
), response.content.decode('utf-8'))
def test_allow_cohorts_when_enrolling(self):
"""
@@ -381,7 +384,7 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
'courses': self.course_key
})
self.assertEqual(response.status_code, 400)
self.assertIn('Cohorts can only be used for enrollments.', response.content)
self.assertIn('Cohorts can only be used for enrollments.', response.content.decode('utf-8'))
def test_add_to_valid_cohort(self):
config_course_cohorts(self.course, is_cohorted=True, manual_cohorts=["cohort1", "cohort2"])
@@ -525,7 +528,7 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
}
}
}
res2_json = json.loads(response2.content)
res2_json = json.loads(response2.content.decode('utf-8'))
self.assertIsNotNone(get_cohort_id(self.notenrolled_student, CourseKey.from_string(self.course_key)))
self.assertEqual(res2_json, expected2)
@@ -621,6 +624,6 @@ class BulkEnrollmentTest(ModuleStoreTestCase, LoginEnrollmentTestCase, APITestCa
}
}
}
res2_json = json.loads(response2.content)
res2_json = json.loads(response2.content.decode('utf-8'))
self.assertIsNotNone(get_cohort_id(self.notenrolled_student, CourseKey.from_string(self.course_key)))
self.assertEqual(res2_json, expected2)

View File

@@ -3,7 +3,6 @@ API views for Bulk Enrollment
"""
from __future__ import absolute_import
import itertools
import json
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
@@ -12,6 +11,7 @@ from opaque_keys.edx.keys import CourseKey
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from six.moves import zip_longest
from bulk_enroll.serializers import BulkEnrollmentSerializer
from lms.djangoapps.instructor.views.api import students_update_enrollment
@@ -87,8 +87,8 @@ class BulkEnrollView(APIView):
'action': serializer.data.get('action'),
'courses': {}
}
for course_id, cohort_name in itertools.izip_longest(serializer.data.get('courses'),
serializer.data.get('cohorts', [])):
for course_id, cohort_name in zip_longest(serializer.data.get('courses'),
serializer.data.get('cohorts', [])):
response = students_update_enrollment(self.request, course_id=course_id)
response_content = json.loads(response.content.decode('utf-8'))