Skip to content

Commit

Permalink
fix: Create a bad unicode file differently.
Browse files Browse the repository at this point in the history
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: python/cpython#71767
  • Loading branch information
feanil committed Apr 3, 2024
1 parent 70eed66 commit 0777d92
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def test_bad_file_upload_type(self):
"""
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'))
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def test_bad_file_upload_type(self):
"""
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'))
Expand Down

0 comments on commit 0777d92

Please sign in to comment.