fix: Create a bad unicode file differently.

In Python 3.11 CSV files are allowed to have null characters so the test
data is no longer a valid. We update it to not have a valid unicode
character to still test this code path correctly.

I'm not concerned about the fact that the files with null will get past
this test beacause there are other checks on the content of the file
that catch if it doesn't have enough or the right fields so this should
be a safe change to make to the tests.

Relevant Change in Python: https://github.com/python/cpython/issues/71767
This commit is contained in:
Feanil Patel
2024-03-15 15:16:18 -04:00
parent 87b9c759f0
commit 08b3f0bf32
2 changed files with 2 additions and 2 deletions

View File

@@ -713,7 +713,7 @@ class TestInstructorAPIBulkAccountCreationAndEnrollment(SharedModuleStoreTestCas
"""
Try uploading some non-CSV file and verify that it is rejected
"""
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \x00\x01").read())
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \xC3\x01").read())
response = self.client.post(self.url, {'students_list': uploaded_file})
assert response.status_code == 200
data = json.loads(response.content.decode('utf-8'))

View File

@@ -888,7 +888,7 @@ class TestCertificatesInstructorApiBulkAllowlist(SharedModuleStoreTestCase):
"""
Try uploading CSV file with invalid binary data and verify that it is rejected
"""
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \x00\x01").read())
uploaded_file = SimpleUploadedFile("temp.csv", io.BytesIO(b"some initial binary data: \xC3\x01").read())
response = self.client.post(self.url, {'students_list': uploaded_file})
assert response.status_code == 200
data = json.loads(response.content.decode('utf-8'))