Remove some boilerplate in tests (#4156)

This commit is contained in:
Amber Brown 2018-11-07 03:00:00 +11:00 committed by GitHub
parent 0f5e51f726
commit e62f7f17b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 163 additions and 217 deletions

View file

@ -34,6 +34,7 @@ class FakeChannel(object):
wire).
"""
_reactor = attr.ib()
result = attr.ib(default=attr.Factory(dict))
_producer = None
@ -63,6 +64,15 @@ class FakeChannel(object):
def registerProducer(self, producer, streaming):
self._producer = producer
self.producerStreaming = streaming
def _produce():
if self._producer:
self._producer.resumeProducing()
self._reactor.callLater(0.1, _produce)
if not streaming:
self._reactor.callLater(0.0, _produce)
def unregisterProducer(self):
if self._producer is None:
@ -105,7 +115,13 @@ class FakeSite:
def make_request(
method, path, content=b"", access_token=None, request=SynapseRequest, shorthand=True
reactor,
method,
path,
content=b"",
access_token=None,
request=SynapseRequest,
shorthand=True,
):
"""
Make a web request using the given method and path, feed it the
@ -138,7 +154,7 @@ def make_request(
content = content.encode('utf8')
site = FakeSite()
channel = FakeChannel()
channel = FakeChannel(reactor)
req = request(site, channel)
req.process = lambda: b""