diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2020-01-13 18:10:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-13 18:10:43 +0000 |
commit | 1177d3f3a33bd3ae1eef46fba360d319598359ad (patch) | |
tree | e7da27c7d951e4d902b38c1dcb8beb661b33b839 /tests/rest/client | |
parent | Document more supported endpoints for workers (#6698) (diff) | |
download | synapse-1177d3f3a33bd3ae1eef46fba360d319598359ad.tar.xz |
Quarantine media by ID or user ID (#6681)
Diffstat (limited to 'tests/rest/client')
-rw-r--r-- | tests/rest/client/v1/utils.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/rest/client/v1/utils.py b/tests/rest/client/v1/utils.py index e7417b3d14..873d5ef99c 100644 --- a/tests/rest/client/v1/utils.py +++ b/tests/rest/client/v1/utils.py @@ -21,6 +21,8 @@ import time import attr +from twisted.web.resource import Resource + from synapse.api.constants import Membership from tests.server import make_request, render @@ -160,3 +162,38 @@ class RestHelper(object): ) return channel.json_body + + def upload_media( + self, + resource: Resource, + image_data: bytes, + tok: str, + filename: str = "test.png", + expect_code: int = 200, + ) -> dict: + """Upload a piece of test media to the media repo + Args: + resource: The resource that will handle the upload request + image_data: The image data to upload + tok: The user token to use during the upload + filename: The filename of the media to be uploaded + expect_code: The return code to expect from attempting to upload the media + """ + image_length = len(image_data) + path = "/_matrix/media/r0/upload?filename=%s" % (filename,) + request, channel = make_request( + self.hs.get_reactor(), "POST", path, content=image_data, access_token=tok + ) + request.requestHeaders.addRawHeader( + b"Content-Length", str(image_length).encode("UTF-8") + ) + request.render(resource) + self.hs.get_reactor().pump([100]) + + assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % ( + expect_code, + int(channel.result["code"]), + channel.result["body"], + ) + + return channel.json_body |