summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-16 11:29:05 +0000
committerErik Johnston <erik@matrix.org>2014-12-16 11:29:05 +0000
commit3c77d13aa5375274e267a0ea898ce6267fb67cdc (patch)
tree28b958507d705a5a92fd167191e1d62d98fe644c /tests
parentAdd fixme to raising of AuthError in federation land (diff)
downloadsynapse-3c77d13aa5375274e267a0ea898ce6267fb67cdc.tar.xz
Kill off synapse.api.events.*
Diffstat (limited to '')
-rw-r--r--tests/events/__init__.py15
-rw-r--r--tests/events/test_events.py217
-rw-r--r--tests/handlers/test_federation.py7
-rw-r--r--tests/handlers/test_room.py25
-rw-r--r--tests/storage/test_redaction.py23
-rw-r--r--tests/storage/test_room.py8
-rw-r--r--tests/storage/test_roommember.py5
-rw-r--r--tests/storage/test_stream.py11
-rw-r--r--tests/utils.py8
9 files changed, 35 insertions, 284 deletions
diff --git a/tests/events/__init__.py b/tests/events/__init__.py
deleted file mode 100644
index 9bff9ec169..0000000000
--- a/tests/events/__init__.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2014 OpenMarket Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
diff --git a/tests/events/test_events.py b/tests/events/test_events.py
deleted file mode 100644
index 91d1d44fee..0000000000
--- a/tests/events/test_events.py
+++ /dev/null
@@ -1,217 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2014 OpenMarket Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from synapse.api.events import SynapseEvent
-from synapse.api.events.validator import EventValidator
-from synapse.api.errors import SynapseError
-
-from tests import unittest
-
-
-class SynapseTemplateCheckTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.validator = EventValidator(None)
-
-    def tearDown(self):
-        pass
-
-    def test_top_level_keys(self):
-        template = {
-            "person": {},
-            "friends": ["string"]
-        }
-
-        content = {
-            "person": {"name": "bob"},
-            "friends": ["jill", "mike"]
-        }
-
-        event = MockSynapseEvent(template)
-        event.content = content
-        self.assertTrue(self.validator.validate(event))
-
-        content = {
-            "person": {"name": "bob"},
-            "friends": ["jill"],
-            "enemies": ["mike"]
-        }
-        event.content = content
-        self.assertTrue(self.validator.validate(event))
-
-        content = {
-            "person": {"name": "bob"},
-            # missing friends
-            "enemies": ["mike", "jill"]
-        }
-        event.content = content
-        self.assertRaises(
-            SynapseError,
-            self.validator.validate,
-            event
-        )
-
-    def test_lists(self):
-        template = {
-            "person": {},
-            "friends": [{"name":"string"}]
-        }
-
-        content = {
-            "person": {"name": "bob"},
-            "friends": ["jill", "mike"]  # should be in objects
-        }
-
-        event = MockSynapseEvent(template)
-        event.content = content
-        self.assertRaises(
-            SynapseError,
-            self.validator.validate,
-            event
-        )
-
-        content = {
-            "person": {"name": "bob"},
-            "friends": [{"name": "jill"}, {"name": "mike"}]
-        }
-        event.content = content
-        self.assertTrue(self.validator.validate(event))
-
-    def test_nested_lists(self):
-        template = {
-            "results": {
-                "families": [
-                     {
-                        "name": "string",
-                        "members": [
-                            {}
-                        ]
-                     }
-                ]
-            }
-        }
-
-        content = {
-            "results": {
-                "families": [
-                     {
-                        "name": "Smith",
-                        "members": [
-                            "Alice", "Bob"  # wrong types
-                        ]
-                     }
-                ]
-            }
-        }
-
-        event = MockSynapseEvent(template)
-        event.content = content
-        self.assertRaises(
-            SynapseError,
-            self.validator.validate,
-            event
-        )
-
-        content = {
-            "results": {
-                "families": [
-                     {
-                        "name": "Smith",
-                        "members": [
-                            {"name": "Alice"}, {"name": "Bob"}
-                        ]
-                     }
-                ]
-            }
-        }
-        event.content = content
-        self.assertTrue(self.validator.validate(event))
-
-    def test_nested_keys(self):
-        template = {
-            "person": {
-                "attributes": {
-                    "hair": "string",
-                    "eye": "string"
-                },
-                "age": 0,
-                "fav_books": ["string"]
-            }
-        }
-        event = MockSynapseEvent(template)
-
-        content = {
-            "person": {
-                "attributes": {
-                    "hair": "brown",
-                    "eye": "green",
-                    "skin": "purple"
-                },
-                "age": 33,
-                "fav_books": ["lotr", "hobbit"],
-                "fav_music": ["abba", "beatles"]
-            }
-        }
-
-        event.content = content
-        self.assertTrue(self.validator.validate(event))
-
-        content = {
-            "person": {
-                "attributes": {
-                    "hair": "brown"
-                    # missing eye
-                },
-                "age": 33,
-                "fav_books": ["lotr", "hobbit"],
-                "fav_music": ["abba", "beatles"]
-            }
-        }
-
-        event.content = content
-        self.assertRaises(
-            SynapseError,
-            self.validator.validate,
-            event
-        )
-
-        content = {
-            "person": {
-                "attributes": {
-                    "hair": "brown",
-                    "eye": "green",
-                    "skin": "purple"
-                },
-                "age": 33,
-                "fav_books": "nothing",  # should be a list
-            }
-        }
-
-        event.content = content
-        self.assertRaises(
-            SynapseError,
-            self.validator.validate,
-            event
-        )
-
-
-class MockSynapseEvent(SynapseEvent):
-
-    def __init__(self, template):
-        self.template = template
-
-    def get_content_template(self):
-        return self.template
-
diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py
index 91f7351087..ed351367cc 100644
--- a/tests/handlers/test_federation.py
+++ b/tests/handlers/test_federation.py
@@ -16,10 +16,7 @@
 from twisted.internet import defer
 from tests import unittest
 
-from synapse.api.events.room import (
-    MessageEvent,
-)
-
+from synapse.api.constants import EventTypes
 from synapse.events import FrozenEvent
 from synapse.handlers.federation import FederationHandler
 from synapse.server import HomeServer
@@ -79,7 +76,7 @@ class FederationTestCase(unittest.TestCase):
     @defer.inlineCallbacks
     def test_msg(self):
         pdu = FrozenEvent({
-            "type": MessageEvent.TYPE,
+            "type": EventTypes.Message,
             "room_id": "foo",
             "content": {"msgtype": u"fooo"},
             "origin_server_ts": 0,
diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py
index 9c63f2a882..83493cae20 100644
--- a/tests/handlers/test_room.py
+++ b/tests/handlers/test_room.py
@@ -17,9 +17,6 @@
 from twisted.internet import defer
 from tests import unittest
 
-from synapse.api.events.room import (
-    RoomMemberEvent,
-)
 from synapse.api.constants import EventTypes, Membership
 from synapse.handlers.room import RoomMemberHandler, RoomCreationHandler
 from synapse.handlers.profile import ProfileHandler
@@ -102,7 +99,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
         content = {"membership": Membership.INVITE}
 
         builder = self.hs.get_event_builder_factory().new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user_id,
             "state_key": target_user_id,
             "room_id": room_id,
@@ -115,11 +112,11 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def annotate(_, ctx):
             ctx.current_state = {
-                (RoomMemberEvent.TYPE, "@alice:green"): self._create_member(
+                (EventTypes.Member, "@alice:green"): self._create_member(
                     user_id="@alice:green",
                     room_id=room_id,
                 ),
-                (RoomMemberEvent.TYPE, "@bob:red"): self._create_member(
+                (EventTypes.Member, "@bob:red"): self._create_member(
                     user_id="@bob:red",
                     room_id=room_id,
                 ),
@@ -131,7 +128,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def add_auth(_, ctx):
             ctx.auth_events = ctx.current_state[
-                (RoomMemberEvent.TYPE, "@bob:red")
+                (EventTypes.Member, "@bob:red")
             ]
 
             return defer.succeed(True)
@@ -181,7 +178,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
         self.distributor.observe("user_joined_room", join_signal_observer)
 
         builder = self.hs.get_event_builder_factory().new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user_id,
             "state_key": user_id,
             "room_id": room_id,
@@ -194,7 +191,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def annotate(_, ctx):
             ctx.current_state = {
-                (RoomMemberEvent.TYPE, "@bob:red"): self._create_member(
+                (EventTypes.Member, "@bob:red"): self._create_member(
                     user_id="@bob:red",
                     room_id=room_id,
                     membership=Membership.INVITE
@@ -207,7 +204,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def add_auth(_, ctx):
             ctx.auth_events = ctx.current_state[
-                (RoomMemberEvent.TYPE, "@bob:red")
+                (EventTypes.Member, "@bob:red")
             ]
 
             return defer.succeed(True)
@@ -238,7 +235,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
     def _create_member(self, user_id, room_id, membership=Membership.JOIN):
         builder = self.hs.get_event_builder_factory().new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user_id,
             "state_key": user_id,
             "room_id": room_id,
@@ -254,7 +251,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
         user = self.hs.parse_userid(user_id)
 
         builder = self.hs.get_event_builder_factory().new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user_id,
             "state_key": user_id,
             "room_id": room_id,
@@ -267,7 +264,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def annotate(_, ctx):
             ctx.current_state = {
-                (RoomMemberEvent.TYPE, "@bob:red"): self._create_member(
+                (EventTypes.Member, "@bob:red"): self._create_member(
                     user_id="@bob:red",
                     room_id=room_id,
                     membership=Membership.JOIN
@@ -280,7 +277,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
 
         def add_auth(_, ctx):
             ctx.auth_events = ctx.current_state[
-                (RoomMemberEvent.TYPE, "@bob:red")
+                (EventTypes.Member, "@bob:red")
             ]
 
             return defer.succeed(True)
diff --git a/tests/storage/test_redaction.py b/tests/storage/test_redaction.py
index f670e154c3..9806fbc69b 100644
--- a/tests/storage/test_redaction.py
+++ b/tests/storage/test_redaction.py
@@ -18,10 +18,7 @@ from tests import unittest
 from twisted.internet import defer
 
 from synapse.server import HomeServer
-from synapse.api.constants import Membership
-from synapse.api.events.room import (
-    RoomMemberEvent, MessageEvent, RoomRedactionEvent,
-)
+from synapse.api.constants import EventTypes, Membership
 
 from tests.utils import SQLiteMemoryDbPool, MockKey
 
@@ -64,7 +61,7 @@ class RedactionTestCase(unittest.TestCase):
         content = {"membership": membership}
         content.update(extra_content)
         builder = self.event_builder_factory.new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
@@ -84,7 +81,7 @@ class RedactionTestCase(unittest.TestCase):
         self.depth += 1
 
         builder = self.event_builder_factory.new({
-            "type": MessageEvent.TYPE,
+            "type": EventTypes.Message,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
@@ -102,7 +99,7 @@ class RedactionTestCase(unittest.TestCase):
     @defer.inlineCallbacks
     def inject_redaction(self, room, event_id, user, reason):
         builder = self.event_builder_factory.new({
-            "type": RoomRedactionEvent.TYPE,
+            "type": EventTypes.Redaction,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
@@ -142,7 +139,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": MessageEvent.TYPE,
+                "type": EventTypes.Message,
                 "user_id": self.u_alice.to_string(),
                 "content": {"body": "t", "msgtype": "message"},
             },
@@ -176,7 +173,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": MessageEvent.TYPE,
+                "type": EventTypes.Message,
                 "user_id": self.u_alice.to_string(),
                 "content": {},
             },
@@ -185,7 +182,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": RoomRedactionEvent.TYPE,
+                "type": EventTypes.Redaction,
                 "user_id": self.u_alice.to_string(),
                 "content": {"reason": reason},
             },
@@ -221,7 +218,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": RoomMemberEvent.TYPE,
+                "type": EventTypes.Member,
                 "user_id": self.u_bob.to_string(),
                 "content": {"membership": Membership.JOIN, "blue": "red"},
             },
@@ -253,7 +250,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": RoomMemberEvent.TYPE,
+                "type": EventTypes.Member,
                 "user_id": self.u_bob.to_string(),
                 "content": {"membership": Membership.JOIN},
             },
@@ -262,7 +259,7 @@ class RedactionTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": RoomRedactionEvent.TYPE,
+                "type": EventTypes.Redaction,
                 "user_id": self.u_alice.to_string(),
                 "content": {"reason": reason},
             },
diff --git a/tests/storage/test_room.py b/tests/storage/test_room.py
index 4ff02c306b..11761fe29a 100644
--- a/tests/storage/test_room.py
+++ b/tests/storage/test_room.py
@@ -18,9 +18,7 @@ from tests import unittest
 from twisted.internet import defer
 
 from synapse.server import HomeServer
-from synapse.api.events.room import (
-    RoomNameEvent, RoomTopicEvent
-)
+from synapse.api.constants import EventTypes
 
 from tests.utils import SQLiteMemoryDbPool
 
@@ -131,7 +129,7 @@ class RoomEventsStoreTestCase(unittest.TestCase):
         name = u"A-Room-Name"
 
         yield self.inject_room_event(
-            etype=RoomNameEvent.TYPE,
+            etype=EventTypes.Name,
             name=name,
             content={"name": name},
             depth=1,
@@ -154,7 +152,7 @@ class RoomEventsStoreTestCase(unittest.TestCase):
         topic = u"A place for things"
 
         yield self.inject_room_event(
-            etype=RoomTopicEvent.TYPE,
+            etype=EventTypes.Topic,
             topic=topic,
             content={"topic": topic},
             depth=1,
diff --git a/tests/storage/test_roommember.py b/tests/storage/test_roommember.py
index 6df09952d1..a23a8189df 100644
--- a/tests/storage/test_roommember.py
+++ b/tests/storage/test_roommember.py
@@ -18,8 +18,7 @@ from tests import unittest
 from twisted.internet import defer
 
 from synapse.server import HomeServer
-from synapse.api.constants import Membership
-from synapse.api.events.room import RoomMemberEvent
+from synapse.api.constants import EventTypes, Membership
 
 from tests.utils import SQLiteMemoryDbPool, MockKey
 
@@ -61,7 +60,7 @@ class RoomMemberStoreTestCase(unittest.TestCase):
     @defer.inlineCallbacks
     def inject_room_member(self, room, user, membership, replaces_state=None):
         builder = self.event_builder_factory.new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
diff --git a/tests/storage/test_stream.py b/tests/storage/test_stream.py
index 4865a5c142..9247fc579e 100644
--- a/tests/storage/test_stream.py
+++ b/tests/storage/test_stream.py
@@ -18,8 +18,7 @@ from tests import unittest
 from twisted.internet import defer
 
 from synapse.server import HomeServer
-from synapse.api.constants import Membership
-from synapse.api.events.room import RoomMemberEvent, MessageEvent
+from synapse.api.constants import EventTypes, Membership
 
 from tests.utils import SQLiteMemoryDbPool, MockKey
 
@@ -62,7 +61,7 @@ class StreamStoreTestCase(unittest.TestCase):
         self.depth += 1
 
         builder = self.event_builder_factory.new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
@@ -82,7 +81,7 @@ class StreamStoreTestCase(unittest.TestCase):
         self.depth += 1
 
         builder = self.event_builder_factory.new({
-            "type": MessageEvent.TYPE,
+            "type": EventTypes.Message,
             "sender": user.to_string(),
             "state_key": user.to_string(),
             "room_id": room.to_string(),
@@ -125,7 +124,7 @@ class StreamStoreTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": MessageEvent.TYPE,
+                "type": EventTypes.Message,
                 "user_id": self.u_alice.to_string(),
                 "content": {"body": "test", "msgtype": "message"},
             },
@@ -162,7 +161,7 @@ class StreamStoreTestCase(unittest.TestCase):
 
         self.assertObjectHasAttributes(
             {
-                "type": MessageEvent.TYPE,
+                "type": EventTypes.Message,
                 "user_id": self.u_alice.to_string(),
                 "content": {"body": "test", "msgtype": "message"},
             },
diff --git a/tests/utils.py b/tests/utils.py
index 70a221550c..731e03f517 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -15,15 +15,11 @@
 
 from synapse.http.server import HttpServer
 from synapse.api.errors import cs_error, CodeMessageException, StoreError
-from synapse.api.constants import Membership
+from synapse.api.constants import EventTypes
 from synapse.storage import prepare_database
 
 from synapse.util.logcontext import LoggingContext
 
-from synapse.api.events.room import (
-    RoomMemberEvent, MessageEvent
-)
-
 from twisted.internet import defer, reactor
 from twisted.enterprise.adbapi import ConnectionPool
 
@@ -276,7 +272,7 @@ class MemoryDataStore(object):
         return defer.succeed([])
 
     def persist_event(self, event):
-        if event.type == RoomMemberEvent.TYPE:
+        if event.type == EventTypes.Member:
             room_id = event.room_id
             user = event.state_key
             membership = event.membership