More unit-testing of REST errors
This commit is contained in:
parent
54e513b4e6
commit
0c14a699bb
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue