diff options
author | NavaL <mnandri@thoughtworks.com> | 2016-01-18 18:36:07 +0100 |
---|---|---|
committer | NavaL <mnandri@thoughtworks.com> | 2016-01-18 18:36:07 +0100 |
commit | dfd5897b632f846f64b57108895fbbbe1a817290 (patch) | |
tree | c0f648a95842d3679ae56bda0cecb17b3aaf4ef9 | |
parent | 66a47fa2345775037b127c295f8611534527fadc (diff) |
migrating feedback resources to use services factory
Issue #576
-rw-r--r-- | service/pixelated/resources/__init__.py | 3 | ||||
-rw-r--r-- | service/pixelated/resources/feedback_resource.py | 13 | ||||
-rw-r--r-- | service/pixelated/resources/mail_resource.py | 8 | ||||
-rw-r--r-- | service/pixelated/resources/root_resource.py | 2 | ||||
-rw-r--r-- | service/test/support/integration/app_test_client.py | 1 | ||||
-rw-r--r-- | service/test/unit/resources/test_feedback_resource.py | 10 |
6 files changed, 24 insertions, 13 deletions
diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py index c5ec02f0..3d81d784 100644 --- a/service/pixelated/resources/__init__.py +++ b/service/pixelated/resources/__init__.py @@ -69,3 +69,6 @@ class BaseResource(Resource): def draft_service(self, request): return self._service(request, 'draft_service') + + def feedback_service(self, request): + return self._service(request, 'feedback_service') diff --git a/service/pixelated/resources/feedback_resource.py b/service/pixelated/resources/feedback_resource.py index b989b273..aeead401 100644 --- a/service/pixelated/resources/feedback_resource.py +++ b/service/pixelated/resources/feedback_resource.py @@ -15,18 +15,17 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import json -from twisted.web.resource import Resource -from pixelated.resources import respond_json +from pixelated.resources import respond_json, BaseResource -class FeedbackResource(Resource): +class FeedbackResource(BaseResource): isLeaf = True - def __init__(self, feedback_service): - Resource.__init__(self) - self.feedback_service = feedback_service + def __init__(self, services_factory): + BaseResource.__init__(self, services_factory) def render_POST(self, request): + _feedback_service = self.feedback_service(request) feedback = json.loads(request.content.read()).get('feedback') - self.feedback_service.open_ticket(feedback) + _feedback_service.open_ticket(feedback) return respond_json({}, request) diff --git a/service/pixelated/resources/mail_resource.py b/service/pixelated/resources/mail_resource.py index 3661be9d..37fceb9b 100644 --- a/service/pixelated/resources/mail_resource.py +++ b/service/pixelated/resources/mail_resource.py @@ -1,9 +1,11 @@ import json -from pixelated.resources import respond_json, respond_json_deferred, BaseResource -from pixelated.support import replier + +from twisted.python.log import err from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET -from twisted.python.log import err + +from pixelated.resources import respond_json_deferred, BaseResource +from pixelated.support import replier class MailTags(Resource): diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 93f90ee1..2adde991 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -47,7 +47,7 @@ class RootResource(Resource): self.putChild('tags', TagsResource(services_factory)) self.putChild('mails', MailsResource(services_factory)) self.putChild('mail', MailResource(services_factory)) - self.putChild('feedback', FeedbackResource(feedback_service)) + self.putChild('feedback', FeedbackResource(services_factory)) self.putChild('user-settings', UserSettingsResource(self.account_email)) self._mode = MODE_RUNNING diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index 3d224941..186aeca2 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -93,6 +93,7 @@ class AppTestClient(object): services.mail_service = self.mail_service services.draft_service = self.draft_service services.search_engine = self.search_engine + services.feedback_service = self.feedback_service self.service_factory.add_session('someuserid', services) self.resource.initialize( diff --git a/service/test/unit/resources/test_feedback_resource.py b/service/test/unit/resources/test_feedback_resource.py index 63e6efc4..28dcabad 100644 --- a/service/test/unit/resources/test_feedback_resource.py +++ b/service/test/unit/resources/test_feedback_resource.py @@ -1,5 +1,5 @@ import json -from mockito import verify, mock, when +from mockito import verify, mock, when, any as ANY from twisted.trial import unittest from twisted.web.test.requesthelper import DummyRequest from pixelated.resources.feedback_resource import FeedbackResource @@ -9,7 +9,13 @@ from test.unit.resources import DummySite class TestFeedbackResource(unittest.TestCase): def setUp(self): self.feedback_service = mock() - self.web = DummySite(FeedbackResource(self.feedback_service)) + self.servicesFactory = mock() + 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.web = DummySite(FeedbackResource(self.servicesFactory)) def test_sends_feedback_to_leap_web(self): request = DummyRequest(['/feedback']) |