summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-10 18:00:57 +0000
committerErik Johnston <erik@matrix.org>2014-12-10 18:00:57 +0000
commit4d6af0dde3c8489928312060b7d2c69181a8dc41 (patch)
treef7f9e50810988f1342a1d120b465a538617facc9
parent.from_string() no longer takes a HS (diff)
downloadsynapse-4d6af0dde3c8489928312060b7d2c69181a8dc41.tar.xz
Fix some tests
-rw-r--r--tests/handlers/test_typing.py2
-rw-r--r--tests/storage/test_redaction.py108
-rw-r--r--tests/storage/test_roommember.py49
-rw-r--r--tests/storage/test_stream.py73
-rw-r--r--tests/test_types.py18
5 files changed, 120 insertions, 130 deletions
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index 7e6ed9a42f..af466c474f 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -131,7 +131,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
                 if ignore_user is not None and member == ignore_user:
                     continue
 
-                if member.is_mine:
+                if hs.is_mine(member):
                     if localusers is not None:
                         localusers.add(member)
                 else:
diff --git a/tests/storage/test_redaction.py b/tests/storage/test_redaction.py
index adfe64a980..e8671ae3a2 100644
--- a/tests/storage/test_redaction.py
+++ b/tests/storage/test_redaction.py
@@ -23,7 +23,9 @@ from synapse.api.events.room import (
     RoomMemberEvent, MessageEvent, RoomRedactionEvent,
 )
 
-from tests.utils import SQLiteMemoryDbPool
+from tests.utils import SQLiteMemoryDbPool, MockKey
+
+from mock import Mock
 
 
 class RedactionTestCase(unittest.TestCase):
@@ -33,13 +35,21 @@ class RedactionTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer(
             "test",
             db_pool=db_pool,
+            config=self.mock_config,
+            resource_for_federation=Mock(),
+            http_client=None,
         )
 
         self.store = hs.get_datastore()
-        self.event_factory = hs.get_event_factory()
+        self.event_builder_factory = hs.get_event_builder_factory()
+        self.handlers = hs.get_handlers()
+        self.message_handler = self.handlers.message_handler
 
         self.u_alice = hs.parse_userid("@alice:test")
         self.u_bob = hs.parse_userid("@bob:test")
@@ -49,35 +59,23 @@ class RedactionTestCase(unittest.TestCase):
         self.depth = 1
 
     @defer.inlineCallbacks
-    def inject_room_member(self, room, user, membership, prev_state=None,
+    def inject_room_member(self, room, user, membership, replaces_state=None,
                            extra_content={}):
-        self.depth += 1
-
-        event = self.event_factory.create_event(
-            etype=RoomMemberEvent.TYPE,
-            user_id=user.to_string(),
-            state_key=user.to_string(),
-            room_id=room.to_string(),
-            membership=membership,
-            content={"membership": membership},
-            depth=self.depth,
-            prev_events=[],
+        content = {"membership": membership}
+        content.update(extra_content)
+        builder = self.event_builder_factory.new({
+            "type": RoomMemberEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": content,
+        })
+
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
-        event.content.update(extra_content)
-
-        if prev_state:
-            event.prev_state = prev_state
-
-        event.state_events = None
-        event.hashes = {}
-        event.prev_state = []
-        event.auth_events = []
-
-        # Have to create a join event using the eventfactory
-        yield self.store.persist_event(
-            event
-        )
+        yield self.store.persist_event(event, context)
 
         defer.returnValue(event)
 
@@ -85,46 +83,38 @@ class RedactionTestCase(unittest.TestCase):
     def inject_message(self, room, user, body):
         self.depth += 1
 
-        event = self.event_factory.create_event(
-            etype=MessageEvent.TYPE,
-            user_id=user.to_string(),
-            room_id=room.to_string(),
-            content={"body": body, "msgtype": u"message"},
-            depth=self.depth,
-            prev_events=[],
-        )
-
-        event.state_events = None
-        event.hashes = {}
-        event.auth_events = []
+        builder = self.event_builder_factory.new({
+            "type": MessageEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": {"body": body, "msgtype": u"message"},
+        })
 
-        yield self.store.persist_event(
-            event
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
+        yield self.store.persist_event(event, context)
+
         defer.returnValue(event)
 
     @defer.inlineCallbacks
     def inject_redaction(self, room, event_id, user, reason):
-        event = self.event_factory.create_event(
-            etype=RoomRedactionEvent.TYPE,
-            user_id=user.to_string(),
-            room_id=room.to_string(),
-            content={"reason": reason},
-            depth=self.depth,
-            redacts=event_id,
-            prev_events=[],
+        builder = self.event_builder_factory.new({
+            "type": MessageEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": {"reason": reason},
+            "redacts": event_id,
+        })
+
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
-        event.state_events = None
-        event.hashes = {}
-        event.auth_events = []
-
-        yield self.store.persist_event(
-            event
-        )
-
-        defer.returnValue(event)
+        yield self.store.persist_event(event, context)
 
     @defer.inlineCallbacks
     def test_redact(self):
diff --git a/tests/storage/test_roommember.py b/tests/storage/test_roommember.py
index 8614e5ca9d..6df09952d1 100644
--- a/tests/storage/test_roommember.py
+++ b/tests/storage/test_roommember.py
@@ -21,7 +21,9 @@ from synapse.server import HomeServer
 from synapse.api.constants import Membership
 from synapse.api.events.room import RoomMemberEvent
 
-from tests.utils import SQLiteMemoryDbPool
+from tests.utils import SQLiteMemoryDbPool, MockKey
+
+from mock import Mock
 
 
 class RoomMemberStoreTestCase(unittest.TestCase):
@@ -31,14 +33,22 @@ class RoomMemberStoreTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
-        hs = HomeServer("test",
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
+
+        hs = HomeServer(
+            "test",
             db_pool=db_pool,
+            config=self.mock_config,
+            resource_for_federation=Mock(),
+            http_client=None,
         )
-
         # We can't test the RoomMemberStore on its own without the other event
         # storage logic
         self.store = hs.get_datastore()
-        self.event_factory = hs.get_event_factory()
+        self.event_builder_factory = hs.get_event_builder_factory()
+        self.handlers = hs.get_handlers()
+        self.message_handler = self.handlers.message_handler
 
         self.u_alice = hs.parse_userid("@alice:test")
         self.u_bob = hs.parse_userid("@bob:test")
@@ -49,27 +59,22 @@ class RoomMemberStoreTestCase(unittest.TestCase):
         self.room = hs.parse_roomid("!abc123:test")
 
     @defer.inlineCallbacks
-    def inject_room_member(self, room, user, membership):
-        # Have to create a join event using the eventfactory
-        event = self.event_factory.create_event(
-            etype=RoomMemberEvent.TYPE,
-            user_id=user.to_string(),
-            state_key=user.to_string(),
-            room_id=room.to_string(),
-            membership=membership,
-            content={"membership": membership},
-            depth=1,
-            prev_events=[],
+    def inject_room_member(self, room, user, membership, replaces_state=None):
+        builder = self.event_builder_factory.new({
+            "type": RoomMemberEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": {"membership": membership},
+        })
+
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
-        event.state_events = None
-        event.hashes = {}
-        event.prev_state = {}
-        event.auth_events = {}
+        yield self.store.persist_event(event, context)
 
-        yield self.store.persist_event(
-            event
-        )
+        defer.returnValue(event)
 
     @defer.inlineCallbacks
     def test_one_member(self):
diff --git a/tests/storage/test_stream.py b/tests/storage/test_stream.py
index 5038546aee..cba65bb9f0 100644
--- a/tests/storage/test_stream.py
+++ b/tests/storage/test_stream.py
@@ -21,7 +21,9 @@ from synapse.server import HomeServer
 from synapse.api.constants import Membership
 from synapse.api.events.room import RoomMemberEvent, MessageEvent
 
-from tests.utils import SQLiteMemoryDbPool
+from tests.utils import SQLiteMemoryDbPool, MockKey
+
+from mock import Mock
 
 
 class StreamStoreTestCase(unittest.TestCase):
@@ -31,13 +33,21 @@ class StreamStoreTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer(
             "test",
             db_pool=db_pool,
+            config=self.mock_config,
+            resource_for_federation=Mock(),
+            http_client=None,
         )
 
         self.store = hs.get_datastore()
-        self.event_factory = hs.get_event_factory()
+        self.event_builder_factory = hs.get_event_builder_factory()
+        self.handlers = hs.get_handlers()
+        self.message_handler = self.handlers.message_handler
 
         self.u_alice = hs.parse_userid("@alice:test")
         self.u_bob = hs.parse_userid("@bob:test")
@@ -51,55 +61,40 @@ class StreamStoreTestCase(unittest.TestCase):
     def inject_room_member(self, room, user, membership, replaces_state=None):
         self.depth += 1
 
-        event = self.event_factory.create_event(
-            etype=RoomMemberEvent.TYPE,
-            user_id=user.to_string(),
-            state_key=user.to_string(),
-            room_id=room.to_string(),
-            membership=membership,
-            content={"membership": membership},
-            depth=self.depth,
-            prev_events=[],
-        )
-
-        event.state_events = None
-        event.hashes = {}
-        event.prev_state = []
-        event.auth_events = []
-
-        if replaces_state:
-            event.prev_state = [(replaces_state, "hash")]
-            event.replaces_state = replaces_state
+        builder = self.event_builder_factory.new({
+            "type": RoomMemberEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": {"membership": membership},
+        })
 
-        # Have to create a join event using the eventfactory
-        yield self.store.persist_event(
-            event
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
+        yield self.store.persist_event(event, context)
+
         defer.returnValue(event)
 
     @defer.inlineCallbacks
     def inject_message(self, room, user, body):
         self.depth += 1
 
-        event = self.event_factory.create_event(
-            etype=MessageEvent.TYPE,
-            user_id=user.to_string(),
-            room_id=room.to_string(),
-            content={"body": body, "msgtype": u"message"},
-            depth=self.depth,
-            prev_events=[],
-        )
-
-        event.state_events = None
-        event.hashes = {}
-        event.auth_events = []
+        builder = self.event_builder_factory.new({
+            "type": MessageEvent.TYPE,
+            "sender": user.to_string(),
+            "state_key": user.to_string(),
+            "room_id": room.to_string(),
+            "content": {"body": body, "msgtype": u"message"},
+        })
 
-        # Have to create a join event using the eventfactory
-        yield self.store.persist_event(
-            event
+        event, context = yield self.message_handler._create_new_client_event(
+            builder
         )
 
+        yield self.store.persist_event(event, context)
+
     @defer.inlineCallbacks
     def test_event_stream_get_other(self):
         # Both bob and alice joins the room
diff --git a/tests/test_types.py b/tests/test_types.py
index 276ecc91fd..bfb9e6f548 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -23,21 +23,21 @@ mock_homeserver = BaseHomeServer(hostname="my.domain")
 class UserIDTestCase(unittest.TestCase):
 
     def test_parse(self):
-        user = UserID.from_string("@1234abcd:my.domain", hs=mock_homeserver)
+        user = UserID.from_string("@1234abcd:my.domain")
 
         self.assertEquals("1234abcd", user.localpart)
         self.assertEquals("my.domain", user.domain)
-        self.assertEquals(True, user.is_mine)
+        self.assertEquals(True, mock_homeserver.is_mine(user))
 
     def test_build(self):
-        user = UserID("5678efgh", "my.domain", True)
+        user = UserID("5678efgh", "my.domain")
 
         self.assertEquals(user.to_string(), "@5678efgh:my.domain")
 
     def test_compare(self):
-        userA = UserID.from_string("@userA:my.domain", hs=mock_homeserver)
-        userAagain = UserID.from_string("@userA:my.domain", hs=mock_homeserver)
-        userB = UserID.from_string("@userB:my.domain", hs=mock_homeserver)
+        userA = UserID.from_string("@userA:my.domain")
+        userAagain = UserID.from_string("@userA:my.domain")
+        userB = UserID.from_string("@userB:my.domain")
 
         self.assertTrue(userA == userAagain)
         self.assertTrue(userA != userB)
@@ -52,14 +52,14 @@ class UserIDTestCase(unittest.TestCase):
 class RoomAliasTestCase(unittest.TestCase):
 
     def test_parse(self):
-        room = RoomAlias.from_string("#channel:my.domain", hs=mock_homeserver)
+        room = RoomAlias.from_string("#channel:my.domain")
 
         self.assertEquals("channel", room.localpart)
         self.assertEquals("my.domain", room.domain)
-        self.assertEquals(True, room.is_mine)
+        self.assertEquals(True, mock_homeserver.is_mine(room))
 
     def test_build(self):
-        room = RoomAlias("channel", "my.domain", True)
+        room = RoomAlias("channel", "my.domain")
 
         self.assertEquals(room.to_string(), "#channel:my.domain")