encoding str and opening file in rb mode
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user