From 0777d925038fe6898e7a5e8dbf25808931886a1a Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 15 Mar 2024 15:16:18 -0400 Subject: [PATCH] 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 --- lms/djangoapps/instructor/tests/test_api.py | 2 +- lms/djangoapps/instructor/tests/test_certificates.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index 0158ce0ec8c6..0cb7e009454e 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -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')) diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py index 9921ae6d6831..ce3433f312d8 100644 --- a/lms/djangoapps/instructor/tests/test_certificates.py +++ b/lms/djangoapps/instructor/tests/test_certificates.py @@ -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'))