From b230d58eaa32a7f115881cffbf5637d98d1e8299 Mon Sep 17 00:00:00 2001 From: sw00 Date: Sun, 25 Oct 2015 18:18:23 -0200 Subject: template user's email address into title this should solve https://github.com/pixelated/pixelated-user-agent/issues/246 needed to inject leap_session into root resource to access user email on request. --- service/test/unit/resources/test_root_resource.py | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 service/test/unit/resources/test_root_resource.py (limited to 'service/test') 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 = """ + + + $account_email + + """ + 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 = """ + + + hackerman@pixelated.org + + """ + + actual = request.written[0] + self.assertEquals(expected, actual) + + d.addCallback(assert_response) + return d -- cgit v1.2.3 From e2c83c13ba0ca1edf94b5af0408f17c0d1aa4e95 Mon Sep 17 00:00:00 2001 From: sw00 Date: Mon, 9 Nov 2015 22:39:14 -0200 Subject: use mail_service to inject account_email into root_resource instead of using leap_session, mail_service can be used to get the account email. --- service/test/unit/resources/test_root_resource.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'service/test') diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py index dc1e97ae..068a531f 100644 --- a/service/test/unit/resources/test_root_resource.py +++ b/service/test/unit/resources/test_root_resource.py @@ -8,10 +8,12 @@ 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') + test_email = 'hackerman@pixelated-project.org' + mail_service = mock() + mail_service.account_email = test_email + root_resource = RootResource() - root_resource.initialize(leap_session, mock(), mock(), mock(), mock(), mock()) + root_resource.initialize(mock(), mock(), mail_service, mock(), mock()) root_resource._html_template = """ -- cgit v1.2.3 From ef86d4458c21f1d722fb162423cd3dfeea055844 Mon Sep 17 00:00:00 2001 From: sw00 Date: Tue, 10 Nov 2015 00:09:18 -0200 Subject: refactor unit test don't use initialize method of root_resource in test --- .../test/support/integration/app_test_client.py | 2 +- service/test/unit/adapter/test_mail_service.py | 2 +- service/test/unit/resources/test_root_resource.py | 28 +++++++--------------- 3 files changed, 10 insertions(+), 22 deletions(-) (limited to 'service/test') diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index 369a393d..484bea6e 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -166,7 +166,7 @@ class AppTestClient(object): return mail_sender def _create_mail_service(self, mail_sender, mail_store, search_engine): - mail_service = MailService(mail_sender, mail_store, search_engine) + mail_service = MailService(mail_sender, mail_store, search_engine, self.MAIL_ADDRESS) return mail_service def _generate_soledad_test_folder_name(self, soledad_test_folder='/tmp/soledad-test/test'): diff --git a/service/test/unit/adapter/test_mail_service.py b/service/test/unit/adapter/test_mail_service.py index 6faf5140..1ec3806e 100644 --- a/service/test/unit/adapter/test_mail_service.py +++ b/service/test/unit/adapter/test_mail_service.py @@ -37,7 +37,7 @@ class TestMailService(unittest.TestCase): self.mail_sender = mock() self.search_engine = mock() - self.mail_service = MailService(self.mail_sender, self.mail_store, self.search_engine) + self.mail_service = MailService(self.mail_sender, self.mail_store, self.search_engine, 'acount@email') def tearDown(self): unstub() diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py index 068a531f..4cdaf97a 100644 --- a/service/test/unit/resources/test_root_resource.py +++ b/service/test/unit/resources/test_root_resource.py @@ -1,4 +1,5 @@ import unittest +import re from mockito import mock, when from test.unit.resources import DummySite from twisted.web.test.requesthelper import DummyRequest @@ -6,20 +7,13 @@ from pixelated.resources.root_resource import RootResource class TestRootResource(unittest.TestCase): + MAIL_ADDRESS = 'test_user@pixelated-project.org' def setUp(self): - test_email = 'hackerman@pixelated-project.org' - mail_service = mock() - mail_service.account_email = test_email - root_resource = RootResource() - root_resource.initialize(mock(), mock(), mail_service, mock(), mock()) - root_resource._html_template = """ - - - $account_email - - """ + root_resource._mode = root_resource + root_resource.account_email = self.MAIL_ADDRESS + root_resource._html_template = "$account_email" self.web = DummySite(root_resource) def test_render_GET_should_template_account_email(self): @@ -28,15 +22,9 @@ class TestRootResource(unittest.TestCase): d = self.web.get(request) def assert_response(_): - expected = """ - - - hackerman@pixelated.org - - """ - - actual = request.written[0] - self.assertEquals(expected, actual) + expected = "{0}".format(self.MAIL_ADDRESS) + matches = re.findall(expected, request.written[0]) + self.assertEquals(len(matches), 1) d.addCallback(assert_response) return d -- cgit v1.2.3