summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-25 10:19:11 +0100
committerErik Johnston <erik@matrix.org>2014-09-25 10:19:16 +0100
commit24e4c484681b7e1538a3812b91b949430b898b26 (patch)
tree9f400198328edfb0a701abafccb91f7c42310152 /tests
parentAdd test for redactions (diff)
downloadsynapse-24e4c484681b7e1538a3812b91b949430b898b26.tar.xz
More tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/storage/test_redaction.py83
1 files changed, 82 insertions, 1 deletions
diff --git a/tests/storage/test_redaction.py b/tests/storage/test_redaction.py
index 2406597c3f..966deb365c 100644
--- a/tests/storage/test_redaction.py
+++ b/tests/storage/test_redaction.py
@@ -42,13 +42,15 @@ class StreamStoreTestCase(unittest.TestCase):
         self.event_factory = hs.get_event_factory()
 
         self.u_alice = hs.parse_userid("@alice:test")
+        self.u_bob = hs.parse_userid("@bob:test")
 
         self.room1 = hs.parse_roomid("!abc123:test")
 
         self.depth = 1
 
     @defer.inlineCallbacks
-    def inject_room_member(self, room, user, membership, prev_state=None):
+    def inject_room_member(self, room, user, membership, prev_state=None,
+                           extra_content={}):
         self.depth += 1
 
         event = self.event_factory.create_event(
@@ -61,6 +63,8 @@ class StreamStoreTestCase(unittest.TestCase):
             depth=self.depth,
         )
 
+        event.content.update(extra_content)
+
         if prev_state:
             event.prev_state = prev_state
 
@@ -179,3 +183,80 @@ class StreamStoreTestCase(unittest.TestCase):
             },
             event.redacted_because,
         )
+
+    @defer.inlineCallbacks
+    def test_redact_join(self):
+        yield self.inject_room_member(
+            self.room1, self.u_alice, Membership.JOIN
+        )
+
+        start = yield self.store.get_room_events_max_id()
+
+        msg_event = yield self.inject_room_member(
+            self.room1, self.u_bob, Membership.JOIN,
+            extra_content={"blue": "red"},
+        )
+
+        end = yield self.store.get_room_events_max_id()
+
+        results, _ = yield self.store.get_room_events_stream(
+            self.u_alice.to_string(),
+            start,
+            end,
+            None,  # Is currently ignored
+        )
+
+        self.assertEqual(1, len(results))
+
+        # Check event has not been redacted:
+        event = results[0]
+
+        self.assertObjectHasAttributes(
+            {
+                "type": RoomMemberEvent.TYPE,
+                "user_id": self.u_bob.to_string(),
+                "content": {"membership": Membership.JOIN, "blue": "red"},
+            },
+            event,
+        )
+
+        self.assertFalse(hasattr(event, "redacted_because"))
+
+        # Redact event
+        reason = "Because I said so"
+        yield self.inject_redaction(
+            self.room1, msg_event.event_id, self.u_alice, reason
+        )
+
+        results, _ = yield self.store.get_room_events_stream(
+            self.u_alice.to_string(),
+            start,
+            end,
+            None,  # Is currently ignored
+        )
+
+        self.assertEqual(1, len(results))
+
+        # Check redaction
+
+        event = results[0]
+
+        self.assertObjectHasAttributes(
+            {
+                "type": RoomMemberEvent.TYPE,
+                "user_id": self.u_bob.to_string(),
+                "content": {"membership": Membership.JOIN},
+            },
+            event,
+        )
+
+        self.assertTrue(hasattr(event, "redacted_because"))
+
+        self.assertObjectHasAttributes(
+            {
+                "type": RoomRedactionEvent.TYPE,
+                "user_id": self.u_alice.to_string(),
+                "content": {"reason": reason},
+            },
+            event.redacted_because,
+        )