From 1bdad5bcf1742b279ba0a2840aec526e4f6175a7 Mon Sep 17 00:00:00 2001 From: Zara Gebru Date: Fri, 8 Apr 2016 15:42:09 +0200 Subject: Issue #431: extractes the generic handling for error callbacks in init and handles login, logout, mail and tags resources --- .../test/unit/resources/test_logout_resources.py | 3 +- service/test/unit/resources/test_tags_resource.py | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 service/test/unit/resources/test_tags_resource.py (limited to 'service/test') 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 -- cgit v1.2.3