diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-11-16 18:22:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 18:22:24 +0000 |
commit | 3dc1871219f845954a4b7d31fc06739831d67d2e (patch) | |
tree | a54654d07bc289d36fea381102c26e6c63d3e0b5 /tests/server.py | |
parent | Move `wait_until_result` into `FakeChannel` (#8758) (diff) | |
parent | fixup test (diff) | |
download | synapse-3dc1871219f845954a4b7d31fc06739831d67d2e.tar.xz |
Merge pull request #8757 from matrix-org/rav/pass_site_to_make_request
Pass a Site into `make_request`
Diffstat (limited to 'tests/server.py')
-rw-r--r-- | tests/server.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/server.py b/tests/server.py index 18cb8b2d72..5a1583a3e7 100644 --- a/tests/server.py +++ b/tests/server.py @@ -21,6 +21,7 @@ from twisted.python.failure import Failure from twisted.test.proto_helpers import AccumulatingProtocol, MemoryReactorClock from twisted.web.http import unquote from twisted.web.http_headers import Headers +from twisted.web.resource import IResource from twisted.web.server import Site from synapse.http.site import SynapseRequest @@ -147,9 +148,21 @@ class FakeSite: site_tag = "test" access_logger = logging.getLogger("synapse.access.http.fake") + def __init__(self, resource: IResource): + """ + + Args: + resource: the resource to be used for rendering all requests + """ + self._resource = resource + + def getResourceFor(self, request): + return self._resource + def make_request( reactor, + site: Site, method, path, content=b"", @@ -167,6 +180,8 @@ def make_request( content, and return the Request and the Channel underneath. Args: + site: The twisted Site to associate with the Channel + method (bytes/unicode): The HTTP request method ("verb"). path (bytes/unicode): The HTTP path, suitably URL encoded (e.g. escaped UTF-8 & spaces and such). @@ -202,10 +217,11 @@ def make_request( if not path.startswith(b"/"): path = b"/" + path + if isinstance(content, dict): + content = json.dumps(content).encode("utf8") if isinstance(content, str): content = content.encode("utf8") - site = FakeSite() channel = FakeChannel(site, reactor) req = request(channel) |