summaryrefslogtreecommitdiff
path: root/service/pixelated/resources
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-07-18 00:19:25 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:24 +0200
commitd415a3a89535278ee455c79f6ddf912cd383e4f0 (patch)
treecf06351c9c17e903ac8244b6e05b144ad2329744 /service/pixelated/resources
parentad65388274feaea5f4e0c3df0aafeb800825491e (diff)
fix integration.test_drafts
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r--service/pixelated/resources/mails_resource.py18
1 files changed, 13 insertions, 5 deletions
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