summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoald de Vries <rdevries@thoughtworks.com>2016-11-22 16:16:20 +0100
committerRoald de Vries <rdevries@thoughtworks.com>2016-11-22 16:16:20 +0100
commitd5de22115b4d091469f1abad8d8b9ae7651caa3b (patch)
treec977f5e4487721709b49258a8deeb7106072e9f0
parentad1e8d322e98c50793749e87e56ace9cccc0ef18 (diff)
fix first test for auth session wrapper
-rw-r--r--service/test/unit/resources/test_auth.py44
-rw-r--r--service/test/unit/resources/test_root_resource.py2
2 files changed, 26 insertions, 20 deletions
diff --git a/service/test/unit/resources/test_auth.py b/service/test/unit/resources/test_auth.py
index 5f65e199..ac2529dd 100644
--- a/service/test/unit/resources/test_auth.py
+++ b/service/test/unit/resources/test_auth.py
@@ -1,30 +1,36 @@
-import unittest
-
-from mockito import mock
-
+from mockito import mock, when, any as ANY
+from pixelated.resources.auth import PixelatedAuthSessionWrapper
+from pixelated.resources.login_resource import LoginResource
+from pixelated.resources.root_resource import RootResource
from test.unit.resources import DummySite
+from twisted.cred.checkers import ANONYMOUS
+from twisted.internet.defer import succeed
+from twisted.trial import unittest
+from twisted.web.resource import IResource
from twisted.web.test.requesthelper import DummyRequest
-from pixelated.resources.auth import PixelatedAuthSessionWrapper
-class TestRootResource(unittest.TestCase):
+class TestPixelatedAuthSessionWrapper(unittest.TestCase):
def setUp(self):
- self.portal = mock()
- self.mock_root_resource = mock()
- self.anonymous_resource = mock()
- self.credential_factories = mock()
+ self.portal_mock = mock()
+ self.root_resource_mock = mock()
+ self.anonymous_resource_mock = mock()
+ credential_factories_mock = mock()
- self.session_wrapper = PixelatedAuthSessionWrapper(self.portal, self.mock_root_resource, self.anonymous_resource, self.credential_factories)
- self.web = DummySite(self.session_wrapper)
+ self.session_wrapper = PixelatedAuthSessionWrapper(self.portal_mock, self.root_resource_mock, self.anonymous_resource_mock, credential_factories_mock)
- def test_should_use_login_resource_when_the_user_is_not_logged_in (self):
- request = DummyRequest([''])
- self.session_wrapper.getChildWithDefault('/', request)
+ def test_should_use_login_resource_when_the_user_is_not_logged_in(self):
+ request = DummyRequest([])
+ request.prepath = ['']
+ request.path = '/'
+ when(self.portal_mock).login(ANY(), None, IResource).thenReturn(succeed((IResource, ANONYMOUS, lambda: None)))
- def assert_response(_):
- self.assertEquals(len(matches), 1)
+ deferred_resource = self.session_wrapper.getChildWithDefault('/', request)
+ d = deferred_resource.d
- d.addCallback(assert_response)
- return d
+ def assert_anonymous_resource(resource):
+ self.assertIs(resource, self.anonymous_resource_mock)
+ d.addCallback(assert_anonymous_resource)
+ return d
diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py
index 4ff11ce8..7a7b2005 100644
--- a/service/test/unit/resources/test_root_resource.py
+++ b/service/test/unit/resources/test_root_resource.py
@@ -1,4 +1,3 @@
-import unittest
import re
from mock import MagicMock, patch
@@ -7,6 +6,7 @@ from mockito import mock, when, any as ANY
from pixelated.application import UserAgentMode
from pixelated.resources.features_resource import FeaturesResource
from test.unit.resources import DummySite
+from twisted.trial import unittest
from twisted.web.test.requesthelper import DummyRequest
from pixelated.resources.root_resource import RootResource, MODE_STARTUP, MODE_RUNNING