summary refs log tree commit diff
path: root/tests/api
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-01-29 11:38:06 +0000
committerKegan Dougal <kegan@matrix.org>2015-01-29 11:38:06 +0000
commit777d9914b537d06ebba91948a26d74d3a04b7284 (patch)
tree489b4fce18293030f4647f61316f3320214bcaea /tests/api
parentAdd filtering public API; outline filtering algorithm. (diff)
downloadsynapse-777d9914b537d06ebba91948a26d74d3a04b7284.tar.xz
Implement filter algorithm. Add basic event type unit tests to assert it works.
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/test_filtering.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/api/test_filtering.py b/tests/api/test_filtering.py
index 188fbfb91e..4d40d88b00 100644
--- a/tests/api/test_filtering.py
+++ b/tests/api/test_filtering.py
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
+from collections import namedtuple
 from tests import unittest
 from twisted.internet import defer
 
@@ -27,6 +27,7 @@ from synapse.server import HomeServer
 
 
 user_localpart = "test_user"
+MockEvent = namedtuple("MockEvent", "sender type room_id")
 
 class FilteringTestCase(unittest.TestCase):
 
@@ -55,6 +56,48 @@ class FilteringTestCase(unittest.TestCase):
 
         self.datastore = hs.get_datastore()
 
+    def test_definition_include_literal_types(self):
+        definition = {
+            "types": ["m.room.message", "org.matrix.foo.bar"]
+        }
+        event = MockEvent(
+            sender="@foo:bar",
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+
+        self.assertTrue(
+            self.filtering._passes_definition(definition, event)
+        )
+
+    def test_definition_include_wildcard_types(self):
+        definition = {
+            "types": ["m.*", "org.matrix.foo.bar"]
+        }
+        event = MockEvent(
+            sender="@foo:bar",
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+
+        self.assertTrue(
+            self.filtering._passes_definition(definition, event)
+        )
+
+    def test_definition_exclude_unknown_types(self):
+        definition = {
+            "types": ["m.room.message", "org.matrix.foo.bar"]
+        }
+        event = MockEvent(
+            sender="@foo:bar",
+            type="now.for.something.completely.different",
+            room_id="!foo:bar"
+        )
+
+        self.assertFalse(
+            self.filtering._passes_definition(definition, event)
+        )
+
     @defer.inlineCallbacks
     def test_add_filter(self):
         user_filter = {