mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
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:
@@ -273,6 +273,12 @@ class ZulipTestCase(TestCase):
|
|||||||
|
|
||||||
return [subscription.user_profile for subscription in subscriptions]
|
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):
|
def assert_json_success(self, result):
|
||||||
# type: (HttpResponse) -> Dict[str, Any]
|
# type: (HttpResponse) -> Dict[str, Any]
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -74,9 +74,7 @@ class FileUploadTest(ZulipTestCase):
|
|||||||
|
|
||||||
# Files uploaded through the API should be accesible via the web client
|
# Files uploaded through the API should be accesible via the web client
|
||||||
self.login("hamlet@zulip.com")
|
self.login("hamlet@zulip.com")
|
||||||
response = self.client_get(uri)
|
self.assert_url_serves_contents_of_file(uri, b"zulip!")
|
||||||
data = b"".join(response.streaming_content)
|
|
||||||
self.assertEqual(b"zulip!", data)
|
|
||||||
|
|
||||||
def test_file_too_big_failure(self):
|
def test_file_too_big_failure(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -171,9 +169,7 @@ class FileUploadTest(ZulipTestCase):
|
|||||||
|
|
||||||
# In the future, local file requests will follow the same style as S3
|
# In the future, local file requests will follow the same style as S3
|
||||||
# requests; they will be first authenthicated and redirected
|
# requests; they will be first authenthicated and redirected
|
||||||
response = self.client_get(uri)
|
self.assert_url_serves_contents_of_file(uri, b"zulip!")
|
||||||
data = b"".join(response.streaming_content)
|
|
||||||
self.assertEqual(b"zulip!", data)
|
|
||||||
|
|
||||||
# check if DB has attachment marked as unclaimed
|
# check if DB has attachment marked as unclaimed
|
||||||
entry = Attachment.objects.get(file_name='zulip.txt')
|
entry = Attachment.objects.get(file_name='zulip.txt')
|
||||||
|
|||||||
Reference in New Issue
Block a user