diff options
-rw-r--r-- | service/pixelated/application.py | 1 | ||||
-rw-r--r-- | service/pixelated/resources/root_resource.py | 10 | ||||
-rw-r--r-- | service/test/unit/resources/test_root_resource.py | 40 | ||||
-rw-r--r-- | web-ui/app/index.html | 2 |
4 files changed, 50 insertions, 3 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py index bca4d5e5..3505f884 100644 --- a/service/pixelated/application.py +++ b/service/pixelated/application.py @@ -47,6 +47,7 @@ def start_user_agent(root_resource, leap_home, leap_session): yield add_welcome_mail(leap_session.mail_store) root_resource.initialize( + leap_session, services.keymanager, services.search_engine, services.mail_service, diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index e6046eae..fd3c4f92 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -1,5 +1,6 @@ import os import requests +from string import Template from pixelated.resources.attachments_resource import AttachmentsResource from pixelated.resources.contacts_resource import ContactsResource from pixelated.resources.features_resource import FeaturesResource @@ -22,6 +23,7 @@ class RootResource(Resource): Resource.__init__(self) 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._startup_mode() def _startup_mode(self): @@ -33,7 +35,9 @@ class RootResource(Resource): return self return Resource.getChild(self, path, request) - def initialize(self, keymanager, search_engine, mail_service, draft_service, feedback_service): + def initialize(self, leap_session, keymanager, search_engine, mail_service, draft_service, feedback_service): + self._leap_session = leap_session + self.putChild('assets', File(self._static_folder)) self.putChild('keys', KeysResource(keymanager)) self.putChild('attachment', AttachmentsResource(mail_service)) @@ -67,4 +71,6 @@ class RootResource(Resource): if self._is_starting(): return open(os.path.join(self._startup_assets_folder, 'Interstitial.html')).read() else: - return open(os.path.join(self._static_folder, 'index.html')).read() + email = self._leap_session.account_email() + response = Template(self._html_template).safe_substitute(account_email=email) + return str(response) diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py new file mode 100644 index 00000000..dc1e97ae --- /dev/null +++ b/service/test/unit/resources/test_root_resource.py @@ -0,0 +1,40 @@ +import unittest +from mockito import mock, when +from test.unit.resources import DummySite +from twisted.web.test.requesthelper import DummyRequest +from pixelated.resources.root_resource import RootResource + + +class TestRootResource(unittest.TestCase): + + def setUp(self): + leap_session = mock() + when(leap_session).account_email().thenReturn('hackerman@pixelated.org') + root_resource = RootResource() + root_resource.initialize(leap_session, mock(), mock(), mock(), mock(), mock()) + 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): + request = DummyRequest(['']) + + d = self.web.get(request) + + def assert_response(_): + expected = """ + <html> + <head> + <title>hackerman@pixelated.org</title> + </head> + </html>""" + + actual = request.written[0] + self.assertEquals(expected, actual) + + d.addCallback(assert_response) + return d diff --git a/web-ui/app/index.html b/web-ui/app/index.html index 281d661e..1ff5a116 100644 --- a/web-ui/app/index.html +++ b/web-ui/app/index.html @@ -6,7 +6,7 @@ href="assets/images/Favicon.png"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -<title>Pixelated Mail</title> +<title>$account_email - Pixelated Mail</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <link href="assets/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> |