diff options
Diffstat (limited to 'service/test/unit/resources')
5 files changed, 30 insertions, 19 deletions
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} |