diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-02-16 13:42:50 -0200 |
---|---|---|
committer | Anike Arni <aarni@thoughtworks.com> | 2017-02-16 17:02:01 -0200 |
commit | 64780114ae90bb890d3ffa0a9aebe4686c6b74d3 (patch) | |
tree | 98bc9728eac3f7163a113db8554460d757588301 /service | |
parent | c75cc8b57138cd8fc316d9371477b13e98f16d88 (diff) |
[#907] Adapt login status to work with single user
with @anikarni
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/resources/login_resource.py | 4 | ||||
-rw-r--r-- | service/pixelated/resources/root_resource.py | 3 | ||||
-rw-r--r-- | service/test/unit/resources/test_login_resource.py | 35 |
3 files changed, 39 insertions, 3 deletions
diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 6c0b6cdd..160f12bf 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -176,5 +176,7 @@ class LoginStatusResource(BaseResource): def render_GET(self, request): session = IPixelatedSession(request.getSession()) - response = {'status': str(session.check_login_status())} + status = 'completed' if self._services_factory.mode.is_single_user else str(session.check_login_status()) + + response = {'status': status} return respond_json(response, request) diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 77c7d950..37a0013e 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -27,7 +27,7 @@ from pixelated.resources.backup_account_resource import BackupAccountResource from pixelated.resources.contacts_resource import ContactsResource from pixelated.resources.features_resource import FeaturesResource from pixelated.resources.feedback_resource import FeedbackResource -from pixelated.resources.login_resource import LoginResource +from pixelated.resources.login_resource import LoginResource, LoginStatusResource from pixelated.resources.logout_resource import LogoutResource from pixelated.resources.user_settings_resource import UserSettingsResource from pixelated.resources.mail_resource import MailResource @@ -61,6 +61,7 @@ class RootResource(BaseResource): def _startup_mode(self): self.putChild('assets', File(self._static_folder)) + self.putChild('status', LoginStatusResource(self._services_factory)) self._mode = MODE_STARTUP def getChild(self, path, request): diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py index eeb7349a..29592c1d 100644 --- a/service/test/unit/resources/test_login_resource.py +++ b/service/test/unit/resources/test_login_resource.py @@ -23,7 +23,7 @@ from twisted.internet import defer from twisted.trial import unittest from twisted.web.test.requesthelper import DummyRequest -from pixelated.resources.login_resource import LoginResource +from pixelated.resources.login_resource import LoginResource, LoginStatusResource from pixelated.resources.login_resource import parse_accept_language from test.unit.resources import DummySite @@ -306,3 +306,36 @@ class TestLoginPOST(unittest.TestCase): d.addCallback(assert_login_error_called) return d + + +class TestLoginStatus(unittest.TestCase): + def setUp(self): + self.services_factory = mock() + self.resource = LoginStatusResource(self.services_factory) + self.web = DummySite(self.resource) + + self.request = DummyRequest(['/status']) + + def test_login_status_completed_when_single_user(self): + self.services_factory.mode = mock() + self.services_factory.mode.is_single_user = True + d = self.web.get(self.request) + + def assert_login_completed(_): + self.assertIn('completed', self.request.written[0]) + + d.addCallback(assert_login_completed) + return d + + @patch('pixelated.resources.session.PixelatedSession.check_login_status') + def test_login_status_when_multi_user_returns_check_login_status(self, mock_login_status): + self.services_factory.mode = mock() + self.services_factory.mode.is_single_user = False + mock_login_status.return_value = 'started' + d = self.web.get(self.request) + + def assert_login_completed(_): + self.assertIn('started', self.request.written[0]) + + d.addCallback(assert_login_completed) + return d |