summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-01-27 18:07:21 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-01-27 18:07:21 +0000
commit0c14a699bb4e103a1845b0808821138cfea99552 (patch)
tree20af16670173aea4dac826737818c7ed143dfdcd /tests
parentMove storage of user filters into real datastore layer; now have to mock it o... (diff)
downloadsynapse-0c14a699bb4e103a1845b0808821138cfea99552.tar.xz
More unit-testing of REST errors
Diffstat (limited to 'tests')
-rw-r--r--tests/rest/client/v2_alpha/test_filter.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/rest/client/v2_alpha/test_filter.py b/tests/rest/client/v2_alpha/test_filter.py
index 1add727e6b..80ddabf818 100644
--- a/tests/rest/client/v2_alpha/test_filter.py
+++ b/tests/rest/client/v2_alpha/test_filter.py
@@ -21,6 +21,8 @@ from . import V2AlphaRestTestCase
 
 from synapse.rest.client.v2_alpha import filter
 
+from synapse.api.errors import StoreError
+
 
 class FilterTestCase(V2AlphaRestTestCase):
     USER_ID = "@apple:test"
@@ -39,14 +41,18 @@ class FilterTestCase(V2AlphaRestTestCase):
         datastore.add_user_filter = add_user_filter
 
         def get_user_filter(user_localpart, filter_id):
+            if user_localpart not in self._user_filters:
+                raise StoreError(404, "No user")
             filters = self._user_filters[user_localpart]
+            if filter_id >= len(filters):
+                raise StoreError(404, "No filter")
             return defer.succeed(filters[filter_id])
         datastore.get_user_filter = get_user_filter
 
         return datastore
 
     @defer.inlineCallbacks
-    def test_filter(self):
+    def test_add_filter(self):
         (code, response) = yield self.mock_resource.trigger("POST",
             "/user/%s/filter" % (self.USER_ID),
             '{"type": ["m.*"]}'
@@ -54,8 +60,36 @@ class FilterTestCase(V2AlphaRestTestCase):
         self.assertEquals(200, code)
         self.assertEquals({"filter_id": "0"}, response)
 
+        self.assertIn("apple", self._user_filters)
+        self.assertEquals(len(self._user_filters["apple"]), 1)
+        self.assertEquals({"type": ["m.*"]}, self._user_filters["apple"][0])
+
+    @defer.inlineCallbacks
+    def test_get_filter(self):
+        self._user_filters["apple"] = [
+            {"type": ["m.*"]}
+        ]
+
         (code, response) = yield self.mock_resource.trigger("GET",
             "/user/%s/filter/0" % (self.USER_ID), None
         )
         self.assertEquals(200, code)
         self.assertEquals({"type": ["m.*"]}, response)
+
+    @defer.inlineCallbacks
+    def test_get_filter_no_id(self):
+        self._user_filters["apple"] = [
+            {"type": ["m.*"]}
+        ]
+
+        (code, response) = yield self.mock_resource.trigger("GET",
+            "/user/%s/filter/2" % (self.USER_ID), None
+        )
+        self.assertEquals(404, code)
+
+    @defer.inlineCallbacks
+    def test_get_filter_no_user(self):
+        (code, response) = yield self.mock_resource.trigger("GET",
+            "/user/%s/filter/0" % (self.USER_ID), None
+        )
+        self.assertEquals(404, code)