diff --git a/common/djangoapps/student/management/commands/bulk_unenroll.py b/common/djangoapps/student/management/commands/bulk_unenroll.py index e9932afe85..1412a0ba63 100644 --- a/common/djangoapps/student/management/commands/bulk_unenroll.py +++ b/common/djangoapps/student/management/commands/bulk_unenroll.py @@ -32,7 +32,7 @@ class Command(BaseCommand): csv_path = options['csv_path'] if csv_path: - with open(csv_path) as csv_file: + with open(csv_path, 'rb') as csv_file: self.unenroll_users(csv_file) else: csv_file = BulkUnenrollConfiguration.current().csv_file diff --git a/common/djangoapps/student/management/tests/test_bulk_unenroll.py b/common/djangoapps/student/management/tests/test_bulk_unenroll.py index 3417b7c1a2..02ecc0da25 100644 --- a/common/djangoapps/student/management/tests/test_bulk_unenroll.py +++ b/common/djangoapps/student/management/tests/test_bulk_unenroll.py @@ -96,7 +96,7 @@ class BulkUnenrollTests(SharedModuleStoreTestCase): lines += str(enrollment.user.id) + "," + enrollment.user.username + "," + \ enrollment.user.email + "," + str(enrollment.course.id) + "\n" - csv_file = SimpleUploadedFile(name='test.csv', content=lines, content_type='text/csv') + csv_file = SimpleUploadedFile(name='test.csv', content=lines.encode('utf-8'), content_type='text/csv') BulkUnenrollConfiguration.objects.create(enabled=True, csv_file=csv_file) call_command("bulk_unenroll") @@ -110,14 +110,14 @@ class BulkUnenrollTests(SharedModuleStoreTestCase): for enrollment in self.enrollments: username = enrollment.user.username if username in users_unenrolled: - users_unenrolled[username].append(str(enrollment.course.id)) + users_unenrolled[username].append(str(enrollment.course.id).encode('utf-8')) else: - users_unenrolled[username] = [str(enrollment.course.id)] + users_unenrolled[username] = [str(enrollment.course.id).encode('utf-8')] lines += str(enrollment.user.id) + "," + username + "," + \ enrollment.user.email + "," + str(enrollment.course.id) + "\n" - csv_file = SimpleUploadedFile(name='test.csv', content=lines, content_type='text/csv') + csv_file = SimpleUploadedFile(name='test.csv', content=lines.encode('utf-8'), content_type='text/csv') BulkUnenrollConfiguration.objects.create(enabled=True, csv_file=csv_file) with LogCapture(LOGGER_NAME) as log: