summaryrefslogtreecommitdiff
path: root/service/test/unit/resources
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2016-03-04 10:22:14 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2016-03-04 10:22:35 +0100
commit9284db24513ff33c2c9c0cdc34c12fca91e42f36 (patch)
treec07500c4ff1cb569f31af250acbf06b43e282a98 /service/test/unit/resources
parent59532a50c8b0233b2a596b996cbe799b745c4fac (diff)
Fix: Logout calls session expire
- Deferred was not handled as required - Test did not assert call to expire
Diffstat (limited to 'service/test/unit/resources')
-rw-r--r--service/test/unit/resources/test_logout_resources.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/service/test/unit/resources/test_logout_resources.py b/service/test/unit/resources/test_logout_resources.py
index 6246eeb9..312d2ba4 100644
--- a/service/test/unit/resources/test_logout_resources.py
+++ b/service/test/unit/resources/test_logout_resources.py
@@ -1,6 +1,6 @@
-from mock import patch
-from mockito import mock, verify
+from mock import patch, MagicMock
from twisted.trial import unittest
+from twisted.internet import defer
from twisted.web.error import UnsupportedMethod
from twisted.web.test.requesthelper import DummyRequest
@@ -10,8 +10,9 @@ from test.unit.resources import DummySite
class TestLogoutResource(unittest.TestCase):
def setUp(self):
- self.services_factory = mock()
+ self.services_factory = MagicMock()
self.resource = LogoutResource(self.services_factory)
+ self.services_factory.log_out_user.return_value = defer.succeed(None)
self.web = DummySite(self.resource)
@patch('twisted.web.util.redirectTo')
@@ -19,14 +20,16 @@ class TestLogoutResource(unittest.TestCase):
request = DummyRequest(['/logout'])
request.method = 'POST'
- mock_redirect.return_value = 'haha'
+ session = self.resource.get_session(request)
+ session.expire = MagicMock()
+ mock_redirect.return_value = 'some redirect response'
d = self.web.get(request)
def expire_session_and_redirect(_):
session = self.resource.get_session(request)
- self.assertFalse(session.is_logged_in())
- verify(self.services_factory).log_out_user(session.user_uuid)
+ self.services_factory.log_out_user.assert_called_once_with(session.user_uuid)
+ session.expire.assert_called_once_with()
mock_redirect.assert_called_once_with('/login', request)
d.addCallback(expire_session_and_redirect)