summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2016-11-21 17:58:22 +0000
committerKegan Dougal <kegan@matrix.org>2016-11-21 17:58:22 +0000
commit53b27bbf06f3fc23343d510da70ef1edc7f182d8 (patch)
tree24d43be9e6cc8617f041884561ca4497d07104ff /tests
parentStart adding some tests (diff)
downloadsynapse-53b27bbf06f3fc23343d510da70ef1edc7f182d8.tar.xz
Add remaining tests
Diffstat (limited to 'tests')
-rw-r--r--tests/events/test_utils.py74
1 files changed, 70 insertions, 4 deletions
diff --git a/tests/events/test_utils.py b/tests/events/test_utils.py
index 7136cca7c2..d415e4cb3b 100644
--- a/tests/events/test_utils.py
+++ b/tests/events/test_utils.py
@@ -159,13 +159,79 @@ class SerializeEventTestCase(unittest.TestCase):
         )
 
     def test_event_fields_works_with_dot_keys(self):
-        pass
+        self.assertEquals(
+            self.serialize(
+                MockEvent(
+                    sender="@alice:localhost",
+                    room_id="!foo:bar",
+                    content={
+                        "key.with.dots": {},
+                    },
+                ),
+                ["content.key\.with\.dots"]
+            ),
+            {
+                "content": {
+                    "key.with.dots": {},
+                }
+            }
+        )
 
     def test_event_fields_works_with_nested_dot_keys(self):
-        pass
+        self.assertEquals(
+            self.serialize(
+                MockEvent(
+                    sender="@alice:localhost",
+                    room_id="!foo:bar",
+                    content={
+                        "not_me": 1,
+                        "nested.dot.key": {
+                            "leaf.key": 42,
+                            "not_me_either": 1,
+                        },
+                    },
+                ),
+                ["content.nested\.dot\.key.leaf\.key"]
+            ),
+            {
+                "content": {
+                    "nested.dot.key": {
+                        "leaf.key": 42,
+                    },
+                }
+            }
+        )
 
     def test_event_fields_nops_with_unknown_keys(self):
-        pass
+        self.assertEquals(
+            self.serialize(
+                MockEvent(
+                    sender="@alice:localhost",
+                    room_id="!foo:bar",
+                    content={
+                        "foo": "bar",
+                    },
+                ),
+                ["content.foo", "content.notexists"]
+            ),
+            {
+                "content": {
+                    "foo": "bar",
+                }
+            }
+        )
 
     def test_event_fields_nops_with_non_dict_keys(self):
-        pass
+        self.assertEquals(
+            self.serialize(
+                MockEvent(
+                    sender="@alice:localhost",
+                    room_id="!foo:bar",
+                    content={
+                        "foo": ["I", "am", "an", "array"],
+                    },
+                ),
+                ["content.foo.am"]
+            ),
+            {}
+        )