summary refs log tree commit diff
path: root/tests/events/test_events.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2014-12-16 13:53:43 +0000
committerMark Haines <mjark@negativecurvature.net>2014-12-16 13:53:43 +0000
commit2af40cfa14ba579c156349ae3457a55bc93f8548 (patch)
tree2b94b53c72d51fc170549213ed8cb88556c2b501 /tests/events/test_events.py
parentAdd a script for talking matrix federation adding X-Matrix Authorization (diff)
parentFix pyflakes (diff)
downloadsynapse-2af40cfa14ba579c156349ae3457a55bc93f8548.tar.xz
Merge pull request #25 from matrix-org/events_refactor
Event refactor
Diffstat (limited to 'tests/events/test_events.py')
-rw-r--r--tests/events/test_events.py217
1 files changed, 0 insertions, 217 deletions
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
-