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.
This commit is contained in:
Rafid Aslam 2016-12-19 22:17:19 +07:00 committed by showell
parent 64f595b061
commit 5cc8838df4
2 changed files with 8 additions and 6 deletions

View File

@ -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]
"""

View File

@ -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')