diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-01-18 15:39:59 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-01-18 15:39:59 +0100 |
commit | c5d61bc8001b16e3dcedda9fd1229c27cca4bd3b (patch) | |
tree | a36fb87a31b7692d124b959ba32ba49f48a14ed8 /service/test | |
parent | 0b06feff629f91d2fa4e7bdbe3b8e46b412e6158 (diff) |
Refactory KeyResource to get services from session
- Issue #576
- Only first step (other services not changed yet)
- Faked session access for now
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/support/integration/app_test_client.py | 9 | ||||
-rw-r--r-- | service/test/unit/resources/test_keys_resources.py | 11 |
2 files changed, 17 insertions, 3 deletions
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index 40c24418..16344171 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -33,6 +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.config.site import PixelatedSite from pixelated.adapter.mailstore import LeapMailStore @@ -85,8 +86,14 @@ class AppTestClient(object): self.search_engine.index_mails(mails) self.resource = RootResource() + + self.service_factory = ServicesFactory() + services = mock() + services.keymanager = self.keymanager + self.service_factory.add_session('someuserid', services) + self.resource.initialize( - self.keymanager, self.search_engine, self.mail_service, self.draft_service, self.feedback_service) + self.service_factory, self.keymanager, self.search_engine, self.mail_service, self.draft_service, self.feedback_service) def _render(self, request, as_json=True): def get_str(_str): diff --git a/service/test/unit/resources/test_keys_resources.py b/service/test/unit/resources/test_keys_resources.py index 1990efe8..a737bc16 100644 --- a/service/test/unit/resources/test_keys_resources.py +++ b/service/test/unit/resources/test_keys_resources.py @@ -1,7 +1,9 @@ import json import ast -from mockito import mock, when +from mockito import mock, when, any as ANY from leap.keymanager import OpenPGPKey, KeyNotFound + +from pixelated.application import ServicesFactory from pixelated.resources.keys_resource import KeysResource import twisted.trial.unittest as unittest from twisted.web.test.requesthelper import DummyRequest @@ -13,7 +15,12 @@ class TestKeysResource(unittest.TestCase): def setUp(self): self.keymanager = mock() - self.web = DummySite(KeysResource(self.keymanager)) + self.servicesFactory = mock() + 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)) def test_returns_404_if_key_not_found(self): request = DummyRequest(['/keys']) |