diff options
author | Kegan Dougal <kegan@matrix.org> | 2015-01-29 11:38:06 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2015-01-29 11:38:06 +0000 |
commit | 777d9914b537d06ebba91948a26d74d3a04b7284 (patch) | |
tree | 489b4fce18293030f4647f61316f3320214bcaea /tests/api | |
parent | Add filtering public API; outline filtering algorithm. (diff) | |
download | synapse-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.py | 45 |
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 = { |