From 5cc8838df4e775e460bd8d8ea84a367ea99be8b4 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Mon, 19 Dec 2016 22:17:19 +0700 Subject: [PATCH] tests: Add `assert_url_serves_contents_of_file()` to `ZulipTestCase` Add `assert_url_serves_contents_of_file()` in `ZulipTestCase` class and deduplicate some codes. Fixes #1276. --- zerver/lib/test_classes.py | 6 ++++++ zerver/tests/test_upload.py | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index d6092a784a..59c2506ad2 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -273,6 +273,12 @@ class ZulipTestCase(TestCase): return [subscription.user_profile for subscription in subscriptions] + def assert_url_serves_contents_of_file(self, url, result): + # type: (str, bytes) -> None + response = self.client_get(url) + data = b"".join(response.streaming_content) + self.assertEquals(result, data) + def assert_json_success(self, result): # type: (HttpResponse) -> Dict[str, Any] """ diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index 8ca2407f53..c33f30acb2 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -74,9 +74,7 @@ class FileUploadTest(ZulipTestCase): # Files uploaded through the API should be accesible via the web client self.login("hamlet@zulip.com") - response = self.client_get(uri) - data = b"".join(response.streaming_content) - self.assertEqual(b"zulip!", data) + self.assert_url_serves_contents_of_file(uri, b"zulip!") def test_file_too_big_failure(self): # type: () -> None @@ -171,9 +169,7 @@ class FileUploadTest(ZulipTestCase): # In the future, local file requests will follow the same style as S3 # requests; they will be first authenthicated and redirected - response = self.client_get(uri) - data = b"".join(response.streaming_content) - self.assertEqual(b"zulip!", data) + self.assert_url_serves_contents_of_file(uri, b"zulip!") # check if DB has attachment marked as unclaimed entry = Attachment.objects.get(file_name='zulip.txt')