Ticket #19036: 19036-test.diff

File 19036-test.diff, 1.5 KB (added by Claude Paroz, 12 years ago)

Test case as a patch

  • tests/regressiontests/file_uploads/tests.py

    diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
    index 2a1ec7d..4ee7c18 100644
    a b class FileUploadTests(TestCase):  
    6060
    6161        self.assertEqual(response.status_code, 200)
    6262
    63     def test_base64_upload(self):
    64         test_string = "This data will be transmitted base64-encoded."
     63    def _test_base64_upload(self, content):
    6564        payload = "\r\n".join([
    6665            '--' + client.BOUNDARY,
    6766            'Content-Disposition: form-data; name="file"; filename="test.txt"',
    6867            'Content-Type: application/octet-stream',
    6968            'Content-Transfer-Encoding: base64',
    7069            '',
    71             base64.b64encode(force_bytes(test_string)).decode('ascii'),
     70            base64.b64encode(force_bytes(content)).decode('ascii'),
    7271            '--' + client.BOUNDARY + '--',
    7372            '',
    7473        ]).encode('utf-8')
    class FileUploadTests(TestCase):  
    8281        response = self.client.request(**r)
    8382        received = json.loads(response.content.decode('utf-8'))
    8483
    85         self.assertEqual(received['file'], test_string)
     84        self.assertEqual(received['file'], content)
     85
     86    def test_base64_upload(self):
     87        self._test_base64_upload("This data will be transmitted base64-encoded.")
     88
     89    def test_big_base64_upload(self):
     90        self._test_base64_upload("Big data" * 68000)  # > 512Kb
    8691
    8792    def test_unicode_file_name(self):
    8893        tdir = tempfile.gettempdir()
Back to Top