diff options
author | Zara Gebru <zgebru@thoughtworks.com> | 2016-04-08 15:42:09 +0200 |
---|---|---|
committer | Zara Gebru <zgebru@thoughtworks.com> | 2016-04-08 16:24:30 +0200 |
commit | 1bdad5bcf1742b279ba0a2840aec526e4f6175a7 (patch) | |
tree | eb7eeef42d6f2cd7ac78b0a03d45db26b991ef8f /service/test | |
parent | 22a48f48963053e8e00777e305a42d5ec012874f (diff) |
Issue #431: extractes the generic handling for error callbacks in init and handles login, logout, mail and tags resources
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/unit/resources/test_logout_resources.py | 3 | ||||
-rw-r--r-- | service/test/unit/resources/test_tags_resource.py | 36 |
2 files changed, 37 insertions, 2 deletions
diff --git a/service/test/unit/resources/test_logout_resources.py b/service/test/unit/resources/test_logout_resources.py index e8b88171..49866057 100644 --- a/service/test/unit/resources/test_logout_resources.py +++ b/service/test/unit/resources/test_logout_resources.py @@ -50,7 +50,7 @@ class TestLogoutResource(unittest.TestCase): request.method = 'POST' session = self.resource.get_session(request) - exception = Exception('haha') + exception = Exception('') session.expire = MagicMock(side_effect=exception) d = self.web.get(request) @@ -61,4 +61,3 @@ class TestLogoutResource(unittest.TestCase): d.addCallback(assert_500_when_exception_is_thrown) return d - diff --git a/service/test/unit/resources/test_tags_resource.py b/service/test/unit/resources/test_tags_resource.py new file mode 100644 index 00000000..684e95f2 --- /dev/null +++ b/service/test/unit/resources/test_tags_resource.py @@ -0,0 +1,36 @@ +import logging + +from mock import MagicMock +from twisted.trial import unittest +from twisted.web.test.requesthelper import DummyRequest +from pixelated.resources.tags_resource import TagsResource +from test.unit.resources import DummySite + +logging.getLogger('pixelated.resources').addHandler(logging.NullHandler()) + + +class TestTagsResource(unittest.TestCase): + def setUp(self): + self.services_factory = MagicMock() + self.resource = TagsResource(self.services_factory) + + def test_errback_is_called(self): + exception = Exception('') + mock_search_engine = MagicMock() + mock_search_engine.tags = MagicMock(side_effect=exception) + mock_service = MagicMock() + mock_service.search_engine = mock_search_engine + self.services_factory.services.return_value = mock_service + self.web = DummySite(self.resource) + + request = DummyRequest(['/tags']) + request.method = 'GET' + + d = self.web.get(request) + + def assert_500_when_exception_is_thrown(_): + self.assertEqual(500, request.responseCode) + self.assertEqual('Something went wrong!', request.written[0]) + + d.addCallback(assert_500_when_exception_is_thrown) + return d |