From 2cca5dc79fd248f93c1a0e4ad3d1c93918432c73 Mon Sep 17 00:00:00 2001 From: RobbieClarken Date: Mon, 14 May 2018 13:07:38 -0400 Subject: [PATCH] zerver/tests: Test upload when mimetype is supplied as a query param. --- zerver/tests/test_upload.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index 4a92ba41b6..7aff370295 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -115,6 +115,21 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): data = b"".join(response.streaming_content) self.assertEqual(b"zulip!", data) + def test_upload_file_with_supplied_mimetype(self) -> None: + """ + When files are copied into the system clipboard and pasted for upload + the filename may not be supplied so the extension is determined from a + query string parameter. + """ + fp = StringIO("zulip!") + fp.name = "pasted_file" + result = self.api_post(self.example_email("hamlet"), + "/api/v1/user_uploads?mimetype=image/png", + {"file": fp}) + self.assertEqual(result.status_code, 200) + uri = result.json()["uri"] + self.assertTrue(uri.endswith("pasted_file.png")) + def test_filename_encoding(self) -> None: """ In Python 2, we need to encode unicode filenames (which converts them to