Code

Ticket #19036: 19036-test.diff

File 19036-test.diff, 1.5 KB (added by claudep, 19 months ago)

Test case as a patch

Line 
1diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
2index 2a1ec7d..4ee7c18 100644
3--- a/tests/regressiontests/file_uploads/tests.py
4+++ b/tests/regressiontests/file_uploads/tests.py
5@@ -60,15 +60,14 @@ class FileUploadTests(TestCase):
6 
7         self.assertEqual(response.status_code, 200)
8 
9-    def test_base64_upload(self):
10-        test_string = "This data will be transmitted base64-encoded."
11+    def _test_base64_upload(self, content):
12         payload = "\r\n".join([
13             '--' + client.BOUNDARY,
14             'Content-Disposition: form-data; name="file"; filename="test.txt"',
15             'Content-Type: application/octet-stream',
16             'Content-Transfer-Encoding: base64',
17             '',
18-            base64.b64encode(force_bytes(test_string)).decode('ascii'),
19+            base64.b64encode(force_bytes(content)).decode('ascii'),
20             '--' + client.BOUNDARY + '--',
21             '',
22         ]).encode('utf-8')
23@@ -82,7 +81,13 @@ class FileUploadTests(TestCase):
24         response = self.client.request(**r)
25         received = json.loads(response.content.decode('utf-8'))
26 
27-        self.assertEqual(received['file'], test_string)
28+        self.assertEqual(received['file'], content)
29+
30+    def test_base64_upload(self):
31+        self._test_base64_upload("This data will be transmitted base64-encoded.")
32+
33+    def test_big_base64_upload(self):
34+        self._test_base64_upload("Big data" * 68000)  # > 512Kb
35 
36     def test_unicode_file_name(self):
37         tdir = tempfile.gettempdir()