summary refs log tree commit diff
path: root/tests/handlers/test_room.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/handlers/test_room.py')
-rw-r--r--tests/handlers/test_room.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py
index 0279ab703a..3a71ed0aed 100644
--- a/tests/handlers/test_room.py
+++ b/tests/handlers/test_room.py
@@ -222,14 +222,52 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
             user=user, room_id=room_id
         )
 
-    def _create_member(self, user_id, room_id):
+    @defer.inlineCallbacks
+    def test_simple_leave(self):
+        room_id = "!foo:red"
+        user_id = "@bob:red"
+        user = self.hs.parse_userid(user_id)
+
+        event = self._create_member(
+            user_id=user_id,
+            room_id=room_id,
+            membership=Membership.LEAVE,
+        )
+
+        prev_state = NonCallableMock()
+        prev_state.membership = Membership.JOIN
+        prev_state.sender = user_id
+        self.datastore.get_room_member.return_value = defer.succeed(prev_state)
+
+        event.state_events = {
+            (RoomMemberEvent.TYPE, user_id): event,
+        }
+
+        event.old_state_events = {
+            (RoomMemberEvent.TYPE, user_id): self._create_member(
+                user_id=user_id,
+                room_id=room_id,
+            ),
+        }
+
+        leave_signal_observer = Mock()
+        self.distributor.observe("user_left_room", leave_signal_observer)
+
+        # Actual invocation
+        yield self.room_member_handler.change_membership(event)
+
+        leave_signal_observer.assert_called_with(
+            user=user, room_id=room_id
+        )
+
+    def _create_member(self, user_id, room_id, membership=Membership.JOIN):
         return self.hs.get_event_factory().create_event(
             etype=RoomMemberEvent.TYPE,
             user_id=user_id,
             state_key=user_id,
             room_id=room_id,
-            membership=Membership.JOIN,
-            content={"membership": Membership.JOIN},
+            membership=membership,
+            content={"membership": membership},
         )