summary refs log tree commit diff
path: root/tests/handlers/test_room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-15 14:45:59 +0000
committerErik Johnston <erik@matrix.org>2014-12-15 14:45:59 +0000
commit57e0e619f3ddc68673a0d7b345203b1a52ff1fa1 (patch)
treed7c45715bc9313f7602243b1cd614d95d1a24858 /tests/handlers/test_room.py
parentAdd beginnings of upgrade script (diff)
parentStill send typing notifications to myself if I'm the only one in the room (it... (diff)
downloadsynapse-57e0e619f3ddc68673a0d7b345203b1a52ff1fa1.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into events_refactor
Conflicts:
	tests/handlers/test_room.py
Diffstat (limited to 'tests/handlers/test_room.py')
-rw-r--r--tests/handlers/test_room.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py
index 15b2c265b6..21853fdc50 100644
--- a/tests/handlers/test_room.py
+++ b/tests/handlers/test_room.py
@@ -247,6 +247,60 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         return builder.build()
 
+    @defer.inlineCallbacks
+    def test_simple_leave(self):
+        room_id = "!foo:red"
+        user_id = "@bob:red"
+        user = self.hs.parse_userid(user_id)
+
+        builder = self.hs.get_event_builder_factory().new({
+            "type": RoomMemberEvent.TYPE,
+            "sender": user_id,
+            "state_key": user_id,
+            "room_id": room_id,
+            "content": {"membership": Membership.LEAVE},
+        })
+
+        self.datastore.get_latest_events_in_room.return_value = (
+            defer.succeed([])
+        )
+
+        def annotate(_, ctx):
+            ctx.current_state = {
+                (RoomMemberEvent.TYPE, "@bob:red"): self._create_member(
+                    user_id="@bob:red",
+                    room_id=room_id,
+                    membership=Membership.INVITE
+                ),
+            }
+
+            return defer.succeed(True)
+
+        self.state_handler.annotate_context_with_state.side_effect = annotate
+
+        def add_auth(_, ctx):
+            ctx.auth_events = ctx.current_state[
+                (RoomMemberEvent.TYPE, "@bob:red")
+            ]
+
+            return defer.succeed(True)
+        self.auth.add_auth_events.side_effect = add_auth
+
+        room_handler = self.room_member_handler
+        event, context = yield room_handler._create_new_client_event(
+            builder
+        )
+
+        leave_signal_observer = Mock()
+        self.distributor.observe("user_left_room", leave_signal_observer)
+
+        # Actual invocation
+        yield room_handler.change_membership(event, context)
+
+        leave_signal_observer.assert_called_with(
+            user=user, room_id=room_id
+        )
+
 
 class RoomCreationTest(unittest.TestCase):