From d415a3a89535278ee455c79f6ddf912cd383e4f0 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 18 Jul 2015 00:19:25 +0200 Subject: fix integration.test_drafts --- service/pixelated/resources/mails_resource.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index 7c9f8cc5..ef112900 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -128,11 +128,19 @@ class MailsResource(Resource): _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') + def defer_response(deferred): + deferred.addCallback(lambda pixelated_mail: respond_json_deferred({'ident': pixelated_mail.ident}, request)) + if draft_id: - if not self._mail_service.mail_exists(draft_id): - return respond_json("", request, status_code=422) - pixelated_mail = self._draft_service.update_draft(draft_id, _mail) + deferred_check = self._mail_service.mail_exists(draft_id) + + def return422otherwise(mail_exists): + if not mail_exists: + respond_json_deferred("", request, status_code=422) + else: + defer_response(self._draft_service.update_draft(draft_id, _mail)) + deferred_check.addCallback(return422otherwise) else: - pixelated_mail = self._draft_service.create_draft(_mail) + defer_response(self._draft_service.create_draft(_mail)) - return respond_json({'ident': pixelated_mail.ident}, request) + return server.NOT_DONE_YET -- cgit v1.2.3