forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support files with a unicode signature in the Instructor Dashboa…
…rd API Without this, files with BOM (byte order mark; generated e.g., by Microsoft Excel) cannot be read properly. (cherry picked from commit 7d8a502)
- Loading branch information
1 parent
c410212
commit 75aa91d
Showing
2 changed files
with
11 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,6 +590,7 @@ def test_instructor_level(self): | |
|
||
|
||
@patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': True}) | ||
@ddt.ddt | ||
class TestInstructorAPIBulkAccountCreationAndEnrollment(SharedModuleStoreTestCase, LoginEnrollmentTestCase): | ||
""" | ||
Test Bulk account creation and enrollment from csv file | ||
|
@@ -641,32 +642,15 @@ def setUp(self): | |
) | ||
|
||
@patch('lms.djangoapps.instructor.views.api.log.info') | ||
def test_account_creation_and_enrollment_with_csv(self, info_log): | ||
""" | ||
Happy path test to create a single new user | ||
""" | ||
csv_content = b"[email protected],test_student_1,tester1,USA" | ||
uploaded_file = SimpleUploadedFile("temp.csv", csv_content) | ||
response = self.client.post(self.url, {'students_list': uploaded_file, 'email-students': True}) | ||
assert response.status_code == 200 | ||
data = json.loads(response.content.decode('utf-8')) | ||
assert len(data['row_errors']) == 0 | ||
assert len(data['warnings']) == 0 | ||
assert len(data['general_errors']) == 0 | ||
|
||
manual_enrollments = ManualEnrollmentAudit.objects.all() | ||
assert manual_enrollments.count() == 1 | ||
assert manual_enrollments[0].state_transition == UNENROLLED_TO_ENROLLED | ||
|
||
# test the log for email that's send to new created user. | ||
info_log.assert_called_with('email sent to new created user at %s', '[email protected]') | ||
|
||
@patch('lms.djangoapps.instructor.views.api.log.info') | ||
def test_account_creation_and_enrollment_with_csv_with_blank_lines(self, info_log): | ||
@ddt.data( | ||
b"[email protected],test_student_1,tester1,USA", # Typical use case. | ||
b"\n[email protected],test_student_1,tester1,USA\n\n", # Blank lines. | ||
b"\xef\xbb\xbf[email protected],test_student_1,tester1,USA", # Unicode signature (BOM). | ||
) | ||
def test_account_creation_and_enrollment_with_csv(self, csv_content, info_log): | ||
""" | ||
Happy path test to create a single new user | ||
""" | ||
csv_content = b"\n[email protected],test_student_1,tester1,USA\n\n" | ||
uploaded_file = SimpleUploadedFile("temp.csv", csv_content) | ||
response = self.client.post(self.url, {'students_list': uploaded_file, 'email-students': True}) | ||
assert response.status_code == 200 | ||
|
@@ -4385,7 +4369,7 @@ def call_add_users_to_cohorts(self, csv_data, suffix='.csv'): | |
""" | ||
# this temporary file will be removed in `self.tearDown()` | ||
__, file_name = tempfile.mkstemp(suffix=suffix, dir=self.tempdir) | ||
with open(file_name, 'w') as file_pointer: | ||
with open(file_name, 'w', encoding='utf-8-sig') as file_pointer: | ||
file_pointer.write(csv_data) | ||
with open(file_name) as file_pointer: | ||
url = reverse('add_users_to_cohorts', kwargs={'course_id': str(self.course.id)}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters