summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-08-28 15:32:30 +0100
committerMark Haines <mark.haines@matrix.org>2014-08-28 15:32:38 +0100
commit7b079a26a5bca2c4e22e34f3792d1cdd2230a95e (patch)
treefd6b595106c66d4e81d5e14226276163b7b41032
parentuse @wraps to set the __name__ __module__ and __doc__ correctly for logged fu... (diff)
downloadsynapse-7b079a26a5bca2c4e22e34f3792d1cdd2230a95e.tar.xz
Remove get_state_for_room function from federation handler
-rw-r--r--synapse/handlers/federation.py26
-rw-r--r--tests/handlers/test_federation.py10
-rw-r--r--tests/utils.py10
3 files changed, 29 insertions, 17 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 606e1f1817..1cc820fb5b 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -85,12 +85,6 @@ class FederationHandler(BaseHandler):
         yield self.replication_layer.send_pdu(pdu)
 
     @log_function
-    def get_state_for_room(self, destination, room_id):
-        return self.replication_layer.get_state_for_context(
-            destination, room_id
-        )
-
-    @log_function
     @defer.inlineCallbacks
     def on_receive_pdu(self, pdu, backfilled):
         """ Called by the ReplicationLayer when we have a new pdu. We need to
@@ -139,7 +133,7 @@ class FederationHandler(BaseHandler):
 
             yield self.hs.get_handlers().room_member_handler.change_membership(
                 new_event,
-                True
+                do_auth=True
             )
 
         else:
@@ -151,8 +145,8 @@ class FederationHandler(BaseHandler):
             if not room:
                 # Huh, let's try and get the current state
                 try:
-                    yield self.get_state_for_room(
-                        event.origin, event.room_id
+                    yield self.replication_layer.get_state_for_context(
+                        origin, event.room_id
                     )
 
                     hosts = yield self.store.get_joined_hosts_for_room(
@@ -161,9 +155,9 @@ class FederationHandler(BaseHandler):
                     if self.hs.hostname in hosts:
                         try:
                             yield self.store.store_room(
-                                event.room_id,
-                                "",
-                                is_public=False
+                                room_id=event.room_id,
+                                room_creator_user_id="",
+                                is_public=False,
                             )
                         except:
                             pass
@@ -209,7 +203,9 @@ class FederationHandler(BaseHandler):
 
         # First get current state to see if we are already joined.
         try:
-            yield self.get_state_for_room(target_host, room_id)
+            yield self.replication_layer.get_state_for_context(
+                target_host, room_id
+            )
 
             hosts = yield self.store.get_joined_hosts_for_room(room_id)
             if self.hs.hostname in hosts:
@@ -239,8 +235,8 @@ class FederationHandler(BaseHandler):
 
         try:
             yield self.store.store_room(
-                room_id,
-                "",
+                room_id=room_id,
+                room_creator_user_id="",
                 is_public=False
             )
         except:
diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py
index bc260c8aab..fd19442645 100644
--- a/tests/handlers/test_federation.py
+++ b/tests/handlers/test_federation.py
@@ -28,6 +28,8 @@ from mock import NonCallableMock, ANY
 
 import logging
 
+from ..utils import get_mock_call_args
+
 logging.getLogger().addHandler(logging.NullHandler())
 
 
@@ -99,9 +101,13 @@ class FederationTestCase(unittest.TestCase):
 
         mem_handler = self.handlers.room_member_handler
         self.assertEquals(1, mem_handler.change_membership.call_count)
-        self.assertEquals(True, mem_handler.change_membership.call_args[0][1])
+        call_args = get_mock_call_args(
+            lambda event, do_auth: None,
+            mem_handler.change_membership
+        )
+        self.assertEquals(True, call_args["do_auth"])
 
-        new_event = mem_handler.change_membership.call_args[0][0]
+        new_event = call_args["event"]
         self.assertEquals(RoomMemberEvent.TYPE, new_event.type)
         self.assertEquals(room_id, new_event.room_id)
         self.assertEquals(user_id, new_event.state_key)
diff --git a/tests/utils.py b/tests/utils.py
index 6666b06931..b32d5ef356 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -28,6 +28,16 @@ from mock import patch, Mock
 import json
 import urlparse
 
+from inspect import getcallargs
+
+
+def get_mock_call_args(pattern_func, mock_func):
+    """ Return the arguments the mock function was called with interpreted
+    by the pattern functions argument list.
+    """
+    invoked_args, invoked_kargs = mock_func.call_args
+    return getcallargs(pattern_func, *invoked_args, **invoked_kargs)
+
 
 # This is a mock /resource/ not an entire server
 class MockHttpResource(HttpServer):