summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/application.py9
-rw-r--r--service/pixelated/resources/root_resource.py31
-rw-r--r--service/test/support/integration/app_test_client.py5
-rw-r--r--service/test/unit/resources/test_root_resource.py8
-rw-r--r--service/test/unit/test_application.py6
5 files changed, 34 insertions, 25 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 2d7eb36d..aa0db132 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -63,7 +63,7 @@ class ServicesFactory(object):
@defer.inlineCallbacks
-def start_user_agent(root_resource, leap_home, leap_session):
+def start_user_agent(root_resource, services_factory, leap_home, leap_session):
log.info('Bootstrap done, loading services for user %s' % leap_session.user_auth.username)
services = Services(leap_home, leap_session)
@@ -72,10 +72,9 @@ def start_user_agent(root_resource, leap_home, leap_session):
if leap_session.fresh_account:
yield add_welcome_mail(leap_session.mail_store)
- services_factory = ServicesFactory()
services_factory.add_session(leap_session.user_auth.uuid, services)
- root_resource.initialize(services_factory, services.mail_service)
+ root_resource.initialize()
# soledad needs lots of threads
reactor.threadpool.adjustPoolsize(5, 15)
@@ -101,7 +100,8 @@ def initialize():
log.info('Starting the Pixelated user agent')
args = arguments.parse_user_agent_args()
logger.init(debug=args.debug)
- resource = RootResource()
+ services_factory = ServicesFactory()
+ resource = RootResource(services_factory)
start_site(args, resource)
@@ -114,6 +114,7 @@ def initialize():
deferred.addCallback(
lambda leap_session: start_user_agent(
resource,
+ services_factory,
args.leap_home,
leap_session))
diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py
index b17e33fd..0894444b 100644
--- a/service/pixelated/resources/root_resource.py
+++ b/service/pixelated/resources/root_resource.py
@@ -1,6 +1,8 @@
import os
import requests
from string import Template
+
+from pixelated.resources import BaseResource
from pixelated.resources.attachments_resource import AttachmentsResource
from pixelated.resources.contacts_resource import ContactsResource
from pixelated.resources.features_resource import FeaturesResource
@@ -18,13 +20,14 @@ MODE_STARTUP = 1
MODE_RUNNING = 2
-class RootResource(Resource):
+class RootResource(BaseResource):
- def __init__(self):
- Resource.__init__(self)
+ def __init__(self, services_factory):
+ BaseResource.__init__(self, services_factory)
self._startup_assets_folder = self._get_startup_folder()
self._static_folder = self._get_static_folder()
self._html_template = open(os.path.join(self._static_folder, 'index.html')).read()
+ self._services_factory = services_factory
self._startup_mode()
def _startup_mode(self):
@@ -36,18 +39,17 @@ class RootResource(Resource):
return self
return Resource.getChild(self, path, request)
- def initialize(self, services_factory, mail_service):
- self.account_email = mail_service.account_email
+ def initialize(self):
self.putChild('assets', File(self._static_folder))
- self.putChild('keys', KeysResource(services_factory))
- self.putChild(AttachmentsResource.BASE_URL, AttachmentsResource(services_factory))
- self.putChild('contacts', ContactsResource(services_factory))
+ self.putChild('keys', KeysResource(self._services_factory))
+ self.putChild(AttachmentsResource.BASE_URL, AttachmentsResource(self._services_factory))
+ self.putChild('contacts', ContactsResource(self._services_factory))
self.putChild('features', FeaturesResource())
- self.putChild('tags', TagsResource(services_factory))
- self.putChild('mails', MailsResource(services_factory))
- self.putChild('mail', MailResource(services_factory))
- self.putChild('feedback', FeedbackResource(services_factory))
- self.putChild('user-settings', UserSettingsResource(services_factory))
+ self.putChild('tags', TagsResource(self._services_factory))
+ self.putChild('mails', MailsResource(self._services_factory))
+ self.putChild('mail', MailResource(self._services_factory))
+ self.putChild('feedback', FeedbackResource(self._services_factory))
+ self.putChild('user-settings', UserSettingsResource(self._services_factory))
self._mode = MODE_RUNNING
@@ -72,5 +74,6 @@ class RootResource(Resource):
if self._is_starting():
return open(os.path.join(self._startup_assets_folder, 'Interstitial.html')).read()
else:
- response = Template(self._html_template).safe_substitute(account_email=self.account_email)
+ account_email = self.mail_service(request).account_email
+ response = Template(self._html_template).safe_substitute(account_email=account_email)
return str(response)
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 8ff64e39..1cec62c2 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -85,8 +85,6 @@ class AppTestClient(object):
mails = yield self.mail_service.all_mails()
self.search_engine.index_mails(mails)
- self.resource = RootResource()
-
self.service_factory = ServicesFactory()
services = mock()
services.keymanager = self.keymanager
@@ -96,7 +94,8 @@ class AppTestClient(object):
services.feedback_service = self.feedback_service
self.service_factory.add_session('someuserid', services)
- self.resource.initialize(self.service_factory, self.mail_service)
+ self.resource = RootResource(self.service_factory)
+ self.resource.initialize()
def _render(self, request, as_json=True):
def get_str(_str):
diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py
index 4cdaf97a..c4ffc068 100644
--- a/service/test/unit/resources/test_root_resource.py
+++ b/service/test/unit/resources/test_root_resource.py
@@ -1,6 +1,6 @@
import unittest
import re
-from mockito import mock, when
+from mockito import mock, when, any as ANY
from test.unit.resources import DummySite
from twisted.web.test.requesthelper import DummyRequest
from pixelated.resources.root_resource import RootResource
@@ -10,13 +10,17 @@ class TestRootResource(unittest.TestCase):
MAIL_ADDRESS = 'test_user@pixelated-project.org'
def setUp(self):
- root_resource = RootResource()
+ self.services_factory_mock = mock()
+ self.mail_service_mock = mock()
+ root_resource = RootResource(self.services_factory_mock)
root_resource._mode = root_resource
root_resource.account_email = self.MAIL_ADDRESS
root_resource._html_template = "<html><head><title>$account_email</title></head></html>"
self.web = DummySite(root_resource)
def test_render_GET_should_template_account_email(self):
+ when(self.services_factory_mock).mail_service(ANY()).thenReturn(self.mail_service_mock)
+ self.mail_service_mock.account_email = self.MAIL_ADDRESS
request = DummyRequest([''])
d = self.web.get(request)
diff --git a/service/test/unit/test_application.py b/service/test/unit/test_application.py
index 2f9ee742..7f46d9e9 100644
--- a/service/test/unit/test_application.py
+++ b/service/test/unit/test_application.py
@@ -42,10 +42,11 @@ class ApplicationTest(unittest.TestCase):
def test_that_start_user_agent_binds_to_tcp_port_if_no_ssl_options(self, services_mock, reactor_mock, _):
# FIXME patch something closer, instead of leap.common
app_mock = MagicMock()
+ services_factory_mock = MagicMock()
leap_session = MagicMock()
config = ApplicationTest.MockConfig(12345, '127.0.0.1', leap_session)
- d = pixelated.application.start_user_agent(app_mock, config.home, leap_session)
+ d = pixelated.application.start_user_agent(app_mock, services_factory_mock, config.home, leap_session)
def _assert(_):
services_mock.assert_called_once_with(config.home, leap_session)
@@ -59,12 +60,13 @@ class ApplicationTest(unittest.TestCase):
def test_that_start_user_agent_binds_to_ssl_if_ssl_options(self, services_mock, reactor_mock, _):
# FIXME patch something closer, instead of leap.common
app_mock = MagicMock()
+ services_factory_mock = MagicMock()
leap_session = MagicMock()
pixelated.application._ssl_options = lambda x, y: 'options'
config = ApplicationTest.MockConfig(12345, '127.0.0.1', sslkey="sslkey", sslcert="sslcert")
- d = pixelated.application.start_user_agent(app_mock, config.home, leap_session)
+ d = pixelated.application.start_user_agent(app_mock, services_factory_mock, config.home, leap_session)
def _assert(_):
services_mock.assert_called_once_with(config.home, leap_session)