mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-12 04:52:26 +01:00
Convert RedactionTestCase to modern test style (#5768)
This commit is contained in:
parent
26d742fed6
commit
1cad8d7b6f
2 changed files with 40 additions and 37 deletions
1
changelog.d/5768.misc
Normal file
1
changelog.d/5768.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Convert RedactionTestCase to modern test style.
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2014-2016 OpenMarket Ltd
|
# Copyright 2014-2016 OpenMarket Ltd
|
||||||
|
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -16,23 +17,21 @@
|
||||||
|
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, Membership
|
from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.api.room_versions import RoomVersions
|
from synapse.api.room_versions import RoomVersions
|
||||||
from synapse.types import RoomID, UserID
|
from synapse.types import RoomID, UserID
|
||||||
|
|
||||||
from tests import unittest
|
from tests import unittest
|
||||||
from tests.utils import create_room, setup_test_homeserver
|
from tests.utils import create_room
|
||||||
|
|
||||||
|
|
||||||
class RedactionTestCase(unittest.TestCase):
|
class RedactionTestCase(unittest.HomeserverTestCase):
|
||||||
@defer.inlineCallbacks
|
def make_homeserver(self, reactor, clock):
|
||||||
def setUp(self):
|
return self.setup_test_homeserver(
|
||||||
hs = yield setup_test_homeserver(
|
resource_for_federation=Mock(), http_client=None
|
||||||
self.addCleanup, resource_for_federation=Mock(), http_client=None
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def prepare(self, reactor, clock, hs):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.event_builder_factory = hs.get_event_builder_factory()
|
self.event_builder_factory = hs.get_event_builder_factory()
|
||||||
self.event_creation_handler = hs.get_event_creation_handler()
|
self.event_creation_handler = hs.get_event_creation_handler()
|
||||||
|
@ -42,11 +41,12 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.room1 = RoomID.from_string("!abc123:test")
|
self.room1 = RoomID.from_string("!abc123:test")
|
||||||
|
|
||||||
yield create_room(hs, self.room1.to_string(), self.u_alice.to_string())
|
self.get_success(
|
||||||
|
create_room(hs, self.room1.to_string(), self.u_alice.to_string())
|
||||||
|
)
|
||||||
|
|
||||||
self.depth = 1
|
self.depth = 1
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def inject_room_member(
|
def inject_room_member(
|
||||||
self, room, user, membership, replaces_state=None, extra_content={}
|
self, room, user, membership, replaces_state=None, extra_content={}
|
||||||
):
|
):
|
||||||
|
@ -63,15 +63,14 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
event, context = yield self.event_creation_handler.create_new_client_event(
|
event, context = self.get_success(
|
||||||
builder
|
self.event_creation_handler.create_new_client_event(builder)
|
||||||
)
|
)
|
||||||
|
|
||||||
yield self.store.persist_event(event, context)
|
self.get_success(self.store.persist_event(event, context))
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def inject_message(self, room, user, body):
|
def inject_message(self, room, user, body):
|
||||||
self.depth += 1
|
self.depth += 1
|
||||||
|
|
||||||
|
@ -86,15 +85,14 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
event, context = yield self.event_creation_handler.create_new_client_event(
|
event, context = self.get_success(
|
||||||
builder
|
self.event_creation_handler.create_new_client_event(builder)
|
||||||
)
|
)
|
||||||
|
|
||||||
yield self.store.persist_event(event, context)
|
self.get_success(self.store.persist_event(event, context))
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def inject_redaction(self, room, event_id, user, reason):
|
def inject_redaction(self, room, event_id, user, reason):
|
||||||
builder = self.event_builder_factory.for_room_version(
|
builder = self.event_builder_factory.for_room_version(
|
||||||
RoomVersions.V1,
|
RoomVersions.V1,
|
||||||
|
@ -108,20 +106,21 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
event, context = yield self.event_creation_handler.create_new_client_event(
|
event, context = self.get_success(
|
||||||
builder
|
self.event_creation_handler.create_new_client_event(builder)
|
||||||
)
|
)
|
||||||
|
|
||||||
yield self.store.persist_event(event, context)
|
self.get_success(self.store.persist_event(event, context))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def test_redact(self):
|
def test_redact(self):
|
||||||
yield self.inject_room_member(self.room1, self.u_alice, Membership.JOIN)
|
self.get_success(
|
||||||
|
self.inject_room_member(self.room1, self.u_alice, Membership.JOIN)
|
||||||
|
)
|
||||||
|
|
||||||
msg_event = yield self.inject_message(self.room1, self.u_alice, "t")
|
msg_event = self.get_success(self.inject_message(self.room1, self.u_alice, "t"))
|
||||||
|
|
||||||
# Check event has not been redacted:
|
# Check event has not been redacted:
|
||||||
event = yield self.store.get_event(msg_event.event_id)
|
event = self.get_success(self.store.get_event(msg_event.event_id))
|
||||||
|
|
||||||
self.assertObjectHasAttributes(
|
self.assertObjectHasAttributes(
|
||||||
{
|
{
|
||||||
|
@ -136,11 +135,11 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# Redact event
|
# Redact event
|
||||||
reason = "Because I said so"
|
reason = "Because I said so"
|
||||||
yield self.inject_redaction(
|
self.get_success(
|
||||||
self.room1, msg_event.event_id, self.u_alice, reason
|
self.inject_redaction(self.room1, msg_event.event_id, self.u_alice, reason)
|
||||||
)
|
)
|
||||||
|
|
||||||
event = yield self.store.get_event(msg_event.event_id)
|
event = self.get_success(self.store.get_event(msg_event.event_id))
|
||||||
|
|
||||||
self.assertEqual(msg_event.event_id, event.event_id)
|
self.assertEqual(msg_event.event_id, event.event_id)
|
||||||
|
|
||||||
|
@ -164,15 +163,18 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
event.unsigned["redacted_because"],
|
event.unsigned["redacted_because"],
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def test_redact_join(self):
|
def test_redact_join(self):
|
||||||
yield self.inject_room_member(self.room1, self.u_alice, Membership.JOIN)
|
self.get_success(
|
||||||
|
self.inject_room_member(self.room1, self.u_alice, Membership.JOIN)
|
||||||
msg_event = yield self.inject_room_member(
|
|
||||||
self.room1, self.u_bob, Membership.JOIN, extra_content={"blue": "red"}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
event = yield self.store.get_event(msg_event.event_id)
|
msg_event = self.get_success(
|
||||||
|
self.inject_room_member(
|
||||||
|
self.room1, self.u_bob, Membership.JOIN, extra_content={"blue": "red"}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
event = self.get_success(self.store.get_event(msg_event.event_id))
|
||||||
|
|
||||||
self.assertObjectHasAttributes(
|
self.assertObjectHasAttributes(
|
||||||
{
|
{
|
||||||
|
@ -187,13 +189,13 @@ class RedactionTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# Redact event
|
# Redact event
|
||||||
reason = "Because I said so"
|
reason = "Because I said so"
|
||||||
yield self.inject_redaction(
|
self.get_success(
|
||||||
self.room1, msg_event.event_id, self.u_alice, reason
|
self.inject_redaction(self.room1, msg_event.event_id, self.u_alice, reason)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check redaction
|
# Check redaction
|
||||||
|
|
||||||
event = yield self.store.get_event(msg_event.event_id)
|
event = self.get_success(self.store.get_event(msg_event.event_id))
|
||||||
|
|
||||||
self.assertTrue("redacted_because" in event.unsigned)
|
self.assertTrue("redacted_because" in event.unsigned)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue