mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 12:26:02 -04:00
Merge branch 'master' of github.com:matrix-org/synapse into sql_refactor
Conflicts: tests/rest/test_presence.py tests/rest/test_rooms.py tests/utils.py
This commit is contained in:
commit
347242a5c4
29 changed files with 1258 additions and 393 deletions
|
@ -29,7 +29,8 @@ import json
|
|||
import urlparse
|
||||
|
||||
|
||||
class MockHttpServer(HttpServer):
|
||||
# This is a mock /resource/ not an entire server
|
||||
class MockHttpResource(HttpServer):
|
||||
|
||||
def __init__(self, prefix=""):
|
||||
self.callbacks = [] # 3-tuple of method/pattern/function
|
||||
|
@ -210,3 +211,43 @@ class MemoryDataStore(object):
|
|||
|
||||
def get_room_events_max_id(self):
|
||||
return 0 # TODO (erikj)
|
||||
|
||||
def _format_call(args, kwargs):
|
||||
return ", ".join(
|
||||
["%r" % (a) for a in args] +
|
||||
["%s=%r" % (k, v) for k, v in kwargs.items()]
|
||||
)
|
||||
|
||||
|
||||
class DeferredMockCallable(object):
|
||||
"""A callable instance that stores a set of pending call expectations and
|
||||
return values for them. It allows a unit test to assert that the given set
|
||||
of function calls are eventually made, by awaiting on them to be called.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.expectations = []
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
if not self.expectations:
|
||||
raise ValueError("%r has no pending calls to handle call(%s)" % (
|
||||
self, _format_call(args, kwargs))
|
||||
)
|
||||
|
||||
for (call, result, d) in self.expectations:
|
||||
if args == call[1] and kwargs == call[2]:
|
||||
d.callback(None)
|
||||
return result
|
||||
|
||||
raise AssertionError("Was not expecting call(%s)" %
|
||||
_format_call(args, kwargs)
|
||||
)
|
||||
|
||||
def expect_call_and_return(self, call, result):
|
||||
self.expectations.append((call, result, defer.Deferred()))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def await_calls(self):
|
||||
while self.expectations:
|
||||
(_, _, d) = self.expectations.pop(0)
|
||||
yield d
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue