summary refs log tree commit diff
path: root/tests/handlers
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-12-10 21:01:49 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-12-10 21:01:49 +0000
commit1a75ff5c23e4d85714927f995e185ddf2d7eaff8 (patch)
treec50b4ef6d06afa51a96229ebe5195716a64051a5 /tests/handlers
parentStore serial numbers per room for typing event stream purposes (diff)
downloadsynapse-1a75ff5c23e4d85714927f995e185ddf2d7eaff8.tar.xz
Hook up the event stream to typing notifications
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/test_typing.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index 898977ed8d..b858f96323 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -91,6 +91,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
 
         self.handler = hs.get_handlers().typing_notification_handler
 
+        self.event_source = hs.get_event_sources().sources["typing"]
+
         self.datastore = hs.get_datastore()
         self.datastore.get_destination_retry_timings.return_value = (
             defer.succeed(DestinationsTable.EntryType("", 0, 0))
@@ -151,6 +153,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
     def test_started_typing_local(self):
         self.room_members = [self.u_apple, self.u_banana]
 
+        self.assertEquals(self.event_source.get_current_key(), 0)
+
         yield self.handler.started_typing(
             target_user=self.u_apple,
             auth_user=self.u_apple,
@@ -162,6 +166,16 @@ class TypingNotificationsTestCase(unittest.TestCase):
             call(rooms=[self.room_id]),
         ])
 
+        self.assertEquals(self.event_source.get_current_key(), 1)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 0, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "typing": [self.u_apple.to_string()]},
+            ]
+        )
+
     @defer.inlineCallbacks
     def test_started_typing_remote_send(self):
         self.room_members = [self.u_apple, self.u_onion]
@@ -195,6 +209,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
     def test_started_typing_remote_recv(self):
         self.room_members = [self.u_apple, self.u_onion]
 
+        self.assertEquals(self.event_source.get_current_key(), 0)
+
         yield self.mock_federation_resource.trigger("PUT",
             "/_matrix/federation/v1/send/1000000/",
             _make_edu_json("farm", "m.typing",
@@ -210,6 +226,16 @@ class TypingNotificationsTestCase(unittest.TestCase):
             call(rooms=[self.room_id]),
         ])
 
+        self.assertEquals(self.event_source.get_current_key(), 1)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 0, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "typing": [self.u_onion.to_string()]},
+            ]
+        )
+
     @defer.inlineCallbacks
     def test_stopped_typing(self):
         self.room_members = [self.u_apple, self.u_banana, self.u_onion]
@@ -239,6 +265,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
         )
         self.handler._room_typing[self.room_id] = set((self.u_apple,))
 
+        self.assertEquals(self.event_source.get_current_key(), 0)
+
         yield self.handler.stopped_typing(
             target_user=self.u_apple,
             auth_user=self.u_apple,
@@ -251,10 +279,22 @@ class TypingNotificationsTestCase(unittest.TestCase):
 
         yield put_json.await_calls()
 
+        self.assertEquals(self.event_source.get_current_key(), 1)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 0, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "typing": []},
+            ]
+        )
+
     @defer.inlineCallbacks
     def test_typing_timeout(self):
         self.room_members = [self.u_apple, self.u_banana]
 
+        self.assertEquals(self.event_source.get_current_key(), 0)
+
         yield self.handler.started_typing(
             target_user=self.u_apple,
             auth_user=self.u_apple,
@@ -267,8 +307,28 @@ class TypingNotificationsTestCase(unittest.TestCase):
         ])
         self.on_new_user_event.reset_mock()
 
+        self.assertEquals(self.event_source.get_current_key(), 1)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 0, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "typing": [self.u_apple.to_string()]},
+            ]
+        )
+
         self.clock.advance_time(11)
 
         self.on_new_user_event.assert_has_calls([
             call(rooms=[self.room_id]),
         ])
+
+        self.assertEquals(self.event_source.get_current_key(), 2)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 1, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "typing": []},
+            ]
+        )