|
20 | 20 | import time
|
21 | 21 | import uuid
|
22 | 22 | import warnings
|
23 |
| -from inspect import getcallargs |
24 | 23 | from typing import Type
|
25 | 24 | from urllib import parse as urlparse
|
26 | 25 |
|
27 | 26 | from mock import Mock, patch
|
28 | 27 |
|
29 |
| -from twisted.internet import defer, reactor |
| 28 | +from twisted.internet import defer |
30 | 29 |
|
31 | 30 | from synapse.api.constants import EventTypes
|
32 | 31 | from synapse.api.errors import CodeMessageException, cs_error
|
33 | 32 | from synapse.api.room_versions import RoomVersions
|
34 | 33 | from synapse.config.database import DatabaseConnectionConfig
|
35 | 34 | from synapse.config.homeserver import HomeServerConfig
|
36 | 35 | from synapse.config.server import DEFAULT_ROOM_VERSION
|
37 |
| -from synapse.federation.transport import server as federation_server |
38 | 36 | from synapse.http.server import HttpServer
|
39 | 37 | from synapse.logging.context import current_context, set_current_context
|
40 | 38 | from synapse.server import HomeServer
|
41 | 39 | from synapse.storage import DataStore
|
42 | 40 | from synapse.storage.database import LoggingDatabaseConnection
|
43 | 41 | from synapse.storage.engines import PostgresEngine, create_engine
|
44 | 42 | from synapse.storage.prepare_database import prepare_database
|
45 |
| -from synapse.util.ratelimitutils import FederationRateLimiter |
46 | 43 |
|
47 | 44 | # set this to True to run the tests against postgres instead of sqlite.
|
48 | 45 | #
|
@@ -342,32 +339,9 @@ async def validate_hash(p, h):
|
342 | 339 |
|
343 | 340 | hs.get_auth_handler().validate_hash = validate_hash
|
344 | 341 |
|
345 |
| - fed = kwargs.get("resource_for_federation", None) |
346 |
| - if fed: |
347 |
| - register_federation_servlets(hs, fed) |
348 |
| - |
349 | 342 | return hs
|
350 | 343 |
|
351 | 344 |
|
352 |
| -def register_federation_servlets(hs, resource): |
353 |
| - federation_server.register_servlets( |
354 |
| - hs, |
355 |
| - resource=resource, |
356 |
| - authenticator=federation_server.Authenticator(hs), |
357 |
| - ratelimiter=FederationRateLimiter( |
358 |
| - hs.get_clock(), config=hs.config.rc_federation |
359 |
| - ), |
360 |
| - ) |
361 |
| - |
362 |
| - |
363 |
| -def get_mock_call_args(pattern_func, mock_func): |
364 |
| - """ Return the arguments the mock function was called with interpreted |
365 |
| - by the pattern functions argument list. |
366 |
| - """ |
367 |
| - invoked_args, invoked_kargs = mock_func.call_args |
368 |
| - return getcallargs(pattern_func, *invoked_args, **invoked_kargs) |
369 |
| - |
370 |
| - |
371 | 345 | def mock_getRawHeaders(headers=None):
|
372 | 346 | headers = headers if headers is not None else {}
|
373 | 347 |
|
@@ -553,86 +527,6 @@ def time_bound_deferred(self, d, *args, **kwargs):
|
553 | 527 | return d
|
554 | 528 |
|
555 | 529 |
|
556 |
| -def _format_call(args, kwargs): |
557 |
| - return ", ".join( |
558 |
| - ["%r" % (a) for a in args] + ["%s=%r" % (k, v) for k, v in kwargs.items()] |
559 |
| - ) |
560 |
| - |
561 |
| - |
562 |
| -class DeferredMockCallable: |
563 |
| - """A callable instance that stores a set of pending call expectations and |
564 |
| - return values for them. It allows a unit test to assert that the given set |
565 |
| - of function calls are eventually made, by awaiting on them to be called. |
566 |
| - """ |
567 |
| - |
568 |
| - def __init__(self): |
569 |
| - self.expectations = [] |
570 |
| - self.calls = [] |
571 |
| - |
572 |
| - def __call__(self, *args, **kwargs): |
573 |
| - self.calls.append((args, kwargs)) |
574 |
| - |
575 |
| - if not self.expectations: |
576 |
| - raise ValueError( |
577 |
| - "%r has no pending calls to handle call(%s)" |
578 |
| - % (self, _format_call(args, kwargs)) |
579 |
| - ) |
580 |
| - |
581 |
| - for (call, result, d) in self.expectations: |
582 |
| - if args == call[1] and kwargs == call[2]: |
583 |
| - d.callback(None) |
584 |
| - return result |
585 |
| - |
586 |
| - failure = AssertionError( |
587 |
| - "Was not expecting call(%s)" % (_format_call(args, kwargs)) |
588 |
| - ) |
589 |
| - |
590 |
| - for _, _, d in self.expectations: |
591 |
| - try: |
592 |
| - d.errback(failure) |
593 |
| - except Exception: |
594 |
| - pass |
595 |
| - |
596 |
| - raise failure |
597 |
| - |
598 |
| - def expect_call_and_return(self, call, result): |
599 |
| - self.expectations.append((call, result, defer.Deferred())) |
600 |
| - |
601 |
| - @defer.inlineCallbacks |
602 |
| - def await_calls(self, timeout=1000): |
603 |
| - deferred = defer.DeferredList( |
604 |
| - [d for _, _, d in self.expectations], fireOnOneErrback=True |
605 |
| - ) |
606 |
| - |
607 |
| - timer = reactor.callLater( |
608 |
| - timeout / 1000, |
609 |
| - deferred.errback, |
610 |
| - AssertionError( |
611 |
| - "%d pending calls left: %s" |
612 |
| - % ( |
613 |
| - len([e for e in self.expectations if not e[2].called]), |
614 |
| - [e for e in self.expectations if not e[2].called], |
615 |
| - ) |
616 |
| - ), |
617 |
| - ) |
618 |
| - |
619 |
| - yield deferred |
620 |
| - |
621 |
| - timer.cancel() |
622 |
| - |
623 |
| - self.calls = [] |
624 |
| - |
625 |
| - def assert_had_no_calls(self): |
626 |
| - if self.calls: |
627 |
| - calls = self.calls |
628 |
| - self.calls = [] |
629 |
| - |
630 |
| - raise AssertionError( |
631 |
| - "Expected not to received any calls, got:\n" |
632 |
| - + "\n".join(["call(%s)" % _format_call(c[0], c[1]) for c in calls]) |
633 |
| - ) |
634 |
| - |
635 |
| - |
636 | 530 | async def create_room(hs, room_id: str, creator_id: str):
|
637 | 531 | """Creates and persist a creation event for the given room
|
638 | 532 | """
|
|
0 commit comments