From 8ee3dd4959c95e198371b0475d4a029f6fd334c1 Mon Sep 17 00:00:00 2001 From: amitvadhel Date: Wed, 4 Sep 2019 00:06:39 +0300 Subject: [PATCH 1/3] [Fix] BulkEnrollmentTest (make zip_longest compatible with Python2 and 3) --- lms/djangoapps/bulk_enroll/tests/test_views.py | 10 +++++----- lms/djangoapps/bulk_enroll/views.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/bulk_enroll/tests/test_views.py b/lms/djangoapps/bulk_enroll/tests/test_views.py index 5e54d42124..177f6ccdd0 100644 --- a/lms/djangoapps/bulk_enroll/tests/test_views.py +++ b/lms/djangoapps/bulk_enroll/tests/test_views.py @@ -350,7 +350,7 @@ 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 +366,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 +381,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 +525,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 +621,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) diff --git a/lms/djangoapps/bulk_enroll/views.py b/lms/djangoapps/bulk_enroll/views.py index 562e3267b4..3cbac49176 100644 --- a/lms/djangoapps/bulk_enroll/views.py +++ b/lms/djangoapps/bulk_enroll/views.py @@ -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,7 +87,7 @@ class BulkEnrollView(APIView): 'action': serializer.data.get('action'), 'courses': {} } - for course_id, cohort_name in itertools.izip_longest(serializer.data.get('courses'), + 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')) From 6075d18af8dfba5542730da4a8a41f94e1542d23 Mon Sep 17 00:00:00 2001 From: amitvadhel Date: Thu, 5 Sep 2019 10:13:10 +0300 Subject: [PATCH 2/3] Fix for continuation line over-indented for visual indent (PEP 8 violations) --- lms/djangoapps/bulk_enroll/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/bulk_enroll/views.py b/lms/djangoapps/bulk_enroll/views.py index 3cbac49176..e5c492f69f 100644 --- a/lms/djangoapps/bulk_enroll/views.py +++ b/lms/djangoapps/bulk_enroll/views.py @@ -88,7 +88,7 @@ class BulkEnrollView(APIView): 'courses': {} } for course_id, cohort_name in zip_longest(serializer.data.get('courses'), - serializer.data.get('cohorts', [])): + serializer.data.get('cohorts', [])): response = students_update_enrollment(self.request, course_id=course_id) response_content = json.loads(response.content.decode('utf-8')) From 56a8b440aff28ff216fa4f2f12d3aff5510aec4e Mon Sep 17 00:00:00 2001 From: amitvadhel Date: Thu, 5 Sep 2019 14:35:51 +0300 Subject: [PATCH 3/3] Line too long fix --- lms/djangoapps/bulk_enroll/tests/test_views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/bulk_enroll/tests/test_views.py b/lms/djangoapps/bulk_enroll/tests/test_views.py index 177f6ccdd0..3b9ee7ee1b 100644 --- a/lms/djangoapps/bulk_enroll/tests/test_views.py +++ b/lms/djangoapps/bulk_enroll/tests/test_views.py @@ -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.decode('utf-8')) + 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): """