mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 02:54:52 -04:00
Remove some boilerplate in tests (#4156)
This commit is contained in:
parent
0f5e51f726
commit
e62f7f17b3
11 changed files with 163 additions and 217 deletions
|
@ -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""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue