diff options
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/support/integration/multi_user_client.py | 9 | ||||
-rw-r--r-- | service/test/unit/resources/test_login_resource.py | 22 |
2 files changed, 22 insertions, 9 deletions
diff --git a/service/test/support/integration/multi_user_client.py b/service/test/support/integration/multi_user_client.py index 692dc5e9..19833c9f 100644 --- a/service/test/support/integration/multi_user_client.py +++ b/service/test/support/integration/multi_user_client.py @@ -13,8 +13,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. - - from leap.exceptions import SRPAuthenticationError from mockito import mock, when, any as ANY from twisted.internet import defer @@ -27,7 +25,7 @@ from pixelated.bitmask_libraries.session import LeapSession, LeapSessionFactory import pixelated.config.services from pixelated.resources.root_resource import RootResource from test.support.integration import AppTestClient -from test.support.integration.app_test_client import initialize_soledad, AppTestAccount +from test.support.integration.app_test_client import AppTestAccount import test.support.mockito from test.support.test_helper import request_mock @@ -60,9 +58,8 @@ class MultiUserClient(AppTestClient): leap_session.config = config leap_session.fresh_account = False - mock_srp_auth = 'mocked so irrelevant but just need a return value' - self._set_leap_srp_auth(username, password, mock_srp_auth) - when(LeapSessionFactory).create(username, password, mock_srp_auth).thenReturn(leap_session) + self._set_leap_srp_auth(username, password, user_auth) + when(LeapSessionFactory).create(username, password, user_auth).thenReturn(leap_session) when(leap_session).initial_sync().thenAnswer(lambda: defer.succeed(None)) when(pixelated.config.services).Services(ANY()).thenReturn(self._test_account.services) diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py index 50b96f15..8f65a030 100644 --- a/service/test/unit/resources/test_login_resource.py +++ b/service/test/unit/resources/test_login_resource.py @@ -1,8 +1,6 @@ -import os - from leap.exceptions import SRPAuthenticationError from mock import patch -from mockito import mock, when, any as ANY, verify, verifyZeroInteractions +from mockito import mock, when, any as ANY, verify, verifyZeroInteractions, verifyNoMoreInteractions from twisted.trial import unittest from twisted.web.resource import IResource from twisted.web.test.requesthelper import DummyRequest @@ -113,6 +111,24 @@ class TestLoginPOST(unittest.TestCase): d.addCallback(assert_login_setup_service_for_user) return d + def test_login_does_not_reload_leap_sessions_and_services_if_already_loaded(self): + irrelevant = None + when(self.portal).login(ANY(), None, IResource).thenReturn((irrelevant, self.user_auth, irrelevant)) + when(self.services_factory).is_logged_in('some_user_uuid').thenReturn(True) + + d = self.web.get(self.request) + + def assert_login_setup_service_for_user(_): + verify(self.portal).login(ANY(), None, IResource) + verify(self.services_factory).is_logged_in('some_user_uuid') + verifyNoMoreInteractions(self.services_factory) + interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>' + self.assertIn(interstitial_js_in_template, self.request.written[0]) + self.assertTrue(self.resource.is_logged_in(self.request)) + + d.addCallback(assert_login_setup_service_for_user) + return d + def test_should_return_form_back_with_error_message_when_login_fails(self): when(self.portal).login(ANY(), None, IResource).thenRaise(Exception()) d = self.web.get(self.request) |