summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2016-01-19 13:36:31 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2016-01-22 11:00:22 +0100
commit995049a04fb15bd4e1cf27bf11e3be46f84e3bfe (patch)
tree27990273107b573b49f6af83c3a13ee63ae37b50 /service/test
parent7be15d9231a98f5cd439030ebc16361fb43287e9 (diff)
Add mutli-user mode to user-agent
- Issue #576 - To start in multi user, run with --multi-user --provider provider-name.tld
Diffstat (limited to 'service/test')
-rw-r--r--service/test/support/integration/app_test_client.py4
-rw-r--r--service/test/unit/resources/test_attachments_resource.py10
-rw-r--r--service/test/unit/resources/test_feedback_resource.py11
-rw-r--r--service/test/unit/resources/test_keys_resources.py11
-rw-r--r--service/test/unit/resources/test_mails_resource.py14
-rw-r--r--service/test/unit/resources/test_root_resource.py3
-rw-r--r--service/test/unit/test_application.py8
-rw-r--r--service/test/unit/test_welcome_mail.py2
8 files changed, 37 insertions, 26 deletions
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 1cec62c2..dda13b4f 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -33,7 +33,7 @@ from twisted.web.resource import getChildForRequest
# from twisted.web.server import Site as PixelatedSite
from pixelated.adapter.mailstore.leap_attachment_store import LeapAttachmentStore
from pixelated.adapter.services.feedback_service import FeedbackService
-from pixelated.application import ServicesFactory
+from pixelated.application import ServicesFactory, UserAgentMode, SingleUserServicesFactory
from pixelated.config.site import PixelatedSite
from pixelated.adapter.mailstore import LeapMailStore
@@ -85,7 +85,7 @@ class AppTestClient(object):
mails = yield self.mail_service.all_mails()
self.search_engine.index_mails(mails)
- self.service_factory = ServicesFactory()
+ self.service_factory = SingleUserServicesFactory(UserAgentMode(is_single_user=True))
services = mock()
services.keymanager = self.keymanager
services.mail_service = self.mail_service
diff --git a/service/test/unit/resources/test_attachments_resource.py b/service/test/unit/resources/test_attachments_resource.py
index f3d8ce53..96677cf4 100644
--- a/service/test/unit/resources/test_attachments_resource.py
+++ b/service/test/unit/resources/test_attachments_resource.py
@@ -7,6 +7,7 @@ from mockito import mock, when, verify, any as ANY
from twisted.internet import defer
from twisted.web.test.requesthelper import DummyRequest
+from pixelated.application import UserAgentMode
from pixelated.resources.attachments_resource import AttachmentsResource
from test.unit.resources import DummySite
@@ -17,13 +18,14 @@ class AttachmentsResourceTest(unittest.TestCase):
def setUp(self):
self.mail_service = mock()
- self.servicesFactory = mock()
+ self.services_factory = mock()
+ self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services = mock()
self.services.mail_service = self.mail_service
- self.servicesFactory._services_by_user = {'someuserid': self.mail_service}
- when(self.servicesFactory).services(ANY()).thenReturn(self.services)
+ self.services_factory._services_by_user = {'someuserid': self.mail_service}
+ when(self.services_factory).services(ANY()).thenReturn(self.services)
- self.mails_resource = AttachmentsResource(self.servicesFactory)
+ self.mails_resource = AttachmentsResource(self.services_factory)
self.mails_resource.isLeaf = True
self.web = DummySite(self.mails_resource)
diff --git a/service/test/unit/resources/test_feedback_resource.py b/service/test/unit/resources/test_feedback_resource.py
index 28dcabad..56433f56 100644
--- a/service/test/unit/resources/test_feedback_resource.py
+++ b/service/test/unit/resources/test_feedback_resource.py
@@ -2,6 +2,8 @@ import json
from mockito import verify, mock, when, any as ANY
from twisted.trial import unittest
from twisted.web.test.requesthelper import DummyRequest
+
+from pixelated.application import UserAgentMode
from pixelated.resources.feedback_resource import FeedbackResource
from test.unit.resources import DummySite
@@ -9,13 +11,14 @@ from test.unit.resources import DummySite
class TestFeedbackResource(unittest.TestCase):
def setUp(self):
self.feedback_service = mock()
- self.servicesFactory = mock()
+ self.services_factory = mock()
+ self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services = mock()
self.services.feedback_service = self.feedback_service
- self.servicesFactory._services_by_user = {'someuserid': self.feedback_service}
- when(self.servicesFactory).services(ANY()).thenReturn(self.services)
+ self.services_factory._services_by_user = {'someuserid': self.feedback_service}
+ when(self.services_factory).services(ANY()).thenReturn(self.services)
- self.web = DummySite(FeedbackResource(self.servicesFactory))
+ self.web = DummySite(FeedbackResource(self.services_factory))
def test_sends_feedback_to_leap_web(self):
request = DummyRequest(['/feedback'])
diff --git a/service/test/unit/resources/test_keys_resources.py b/service/test/unit/resources/test_keys_resources.py
index a737bc16..6aa822e1 100644
--- a/service/test/unit/resources/test_keys_resources.py
+++ b/service/test/unit/resources/test_keys_resources.py
@@ -3,7 +3,7 @@ import ast
from mockito import mock, when, any as ANY
from leap.keymanager import OpenPGPKey, KeyNotFound
-from pixelated.application import ServicesFactory
+from pixelated.application import ServicesFactory, UserAgentMode
from pixelated.resources.keys_resource import KeysResource
import twisted.trial.unittest as unittest
from twisted.web.test.requesthelper import DummyRequest
@@ -15,12 +15,13 @@ class TestKeysResource(unittest.TestCase):
def setUp(self):
self.keymanager = mock()
- self.servicesFactory = mock()
+ self.services_factory = mock()
+ self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services = mock()
self.services.keymanager = self.keymanager
- self.servicesFactory._services_by_user = {'someuserid': self.keymanager}
- when(self.servicesFactory).services(ANY()).thenReturn(self.services)
- self.web = DummySite(KeysResource(self.servicesFactory))
+ self.services_factory._services_by_user = {'someuserid': self.keymanager}
+ when(self.services_factory).services(ANY()).thenReturn(self.services)
+ self.web = DummySite(KeysResource(self.services_factory))
def test_returns_404_if_key_not_found(self):
request = DummyRequest(['/keys'])
diff --git a/service/test/unit/resources/test_mails_resource.py b/service/test/unit/resources/test_mails_resource.py
index e36e4f5f..2d9cb33c 100644
--- a/service/test/unit/resources/test_mails_resource.py
+++ b/service/test/unit/resources/test_mails_resource.py
@@ -21,6 +21,7 @@ from mockito import mock, when, verify, any as ANY
from twisted.internet import defer
from twisted.web.test.requesthelper import DummyRequest
+from pixelated.application import UserAgentMode
from pixelated.resources.mails_resource import MailsResource
from test.unit.resources import DummySite
@@ -28,12 +29,13 @@ from test.unit.resources import DummySite
class TestMailsResource(unittest.TestCase):
def setUp(self):
self.mail_service = mock()
- self.servicesFactory = mock()
+ self.services_factory = mock()
+ self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services = mock()
self.services.mail_service = self.mail_service
self.services.draft_service = mock()
- self.servicesFactory._services_by_user = {'someuserid': self.mail_service}
- when(self.servicesFactory).services(ANY()).thenReturn(self.services)
+ self.services_factory._services_by_user = {'someuserid': self.mail_service}
+ when(self.services_factory).services(ANY()).thenReturn(self.services)
@patch('leap.common.events.register')
def test_render_GET_should_unicode_mails_search_query(self, mock_register):
@@ -46,7 +48,7 @@ class TestMailsResource(unittest.TestCase):
unicodified_search_term = u'coração'
when(self.mail_service).mails(unicodified_search_term, 25, 1).thenReturn(defer.Deferred())
- mails_resource = MailsResource(self.servicesFactory)
+ mails_resource = MailsResource(self.services_factory)
mails_resource.isLeaf = True
web = DummySite(mails_resource)
d = web.get(request)
@@ -66,7 +68,7 @@ class TestMailsResource(unittest.TestCase):
when(self.mail_service).attachment('some fake attachment id').thenReturn(defer.Deferred())
request.content = content
- mails_resource = MailsResource(self.servicesFactory)
+ mails_resource = MailsResource(self.services_factory)
mails_resource.isLeaf = True
web = DummySite(mails_resource)
d = web.get(request)
@@ -90,7 +92,7 @@ class TestMailsResource(unittest.TestCase):
.thenReturn(defer.succeed(as_dictable))
request.content = content
- mails_resource = MailsResource(self.servicesFactory)
+ mails_resource = MailsResource(self.services_factory)
mails_resource.isLeaf = True
web = DummySite(mails_resource)
d = web.get(request)
diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py
index 4a8e1d7e..3b0846ee 100644
--- a/service/test/unit/resources/test_root_resource.py
+++ b/service/test/unit/resources/test_root_resource.py
@@ -1,6 +1,8 @@
import unittest
import re
from mockito import mock, when, any as ANY
+
+from pixelated.application import UserAgentMode
from test.unit.resources import DummySite
from twisted.web.test.requesthelper import DummyRequest
from pixelated.resources.root_resource import RootResource
@@ -12,6 +14,7 @@ class TestRootResource(unittest.TestCase):
def setUp(self):
self.mail_service = mock()
self.services_factory = mock()
+ self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services = mock()
self.services.mail_service = self.mail_service
self.services_factory._services_by_user = {'someuserid': self.mail_service}
diff --git a/service/test/unit/test_application.py b/service/test/unit/test_application.py
index 7f46d9e9..a0eb9986 100644
--- a/service/test/unit/test_application.py
+++ b/service/test/unit/test_application.py
@@ -46,10 +46,10 @@ class ApplicationTest(unittest.TestCase):
leap_session = MagicMock()
config = ApplicationTest.MockConfig(12345, '127.0.0.1', leap_session)
- d = pixelated.application.start_user_agent(app_mock, services_factory_mock, config.home, leap_session)
+ d = pixelated.application.start_user_agent_in_single_user_mode(app_mock, services_factory_mock, config.home, leap_session)
def _assert(_):
- services_mock.assert_called_once_with(config.home, leap_session)
+ services_mock.assert_called_once_with(leap_session)
d.addCallback(_assert)
return d
@@ -66,10 +66,10 @@ class ApplicationTest(unittest.TestCase):
config = ApplicationTest.MockConfig(12345, '127.0.0.1', sslkey="sslkey", sslcert="sslcert")
- d = pixelated.application.start_user_agent(app_mock, services_factory_mock, config.home, leap_session)
+ d = pixelated.application.start_user_agent_in_single_user_mode(app_mock, services_factory_mock, config.home, leap_session)
def _assert(_):
- services_mock.assert_called_once_with(config.home, leap_session)
+ services_mock.assert_called_once_with(leap_session)
d.addCallback(_assert)
return d
diff --git a/service/test/unit/test_welcome_mail.py b/service/test/unit/test_welcome_mail.py
index b0162eec..829740d3 100644
--- a/service/test/unit/test_welcome_mail.py
+++ b/service/test/unit/test_welcome_mail.py
@@ -19,8 +19,8 @@ import unittest
from mockito import verify, mock
from mockito.matchers import Matcher
from email import message_from_file
-from pixelated.application import add_welcome_mail
from pixelated.adapter.model.mail import InputMail
+from pixelated.adapter.welcome_mail import add_welcome_mail
class TestWelcomeMail(unittest.TestCase):