From a0a205328d44f6f423fe8f4f25be6b2e0af8b7b1 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sun, 19 Mar 2017 11:03:22 -0400 Subject: [PATCH] Cleanup SQS body encoding. Closes #458, #460. --- moto/core/responses.py | 3 ++- tests/test_sqs/test_sqs.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/moto/core/responses.py b/moto/core/responses.py index 2d0e485ba..a5a1f3880 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -125,6 +125,7 @@ class BaseResponse(_TemplateEnvironmentMixin): for key, value in request.form.items(): querystring[key] = [value, ] + raw_body = self.body if isinstance(self.body, six.binary_type): self.body = self.body.decode('utf-8') @@ -143,7 +144,7 @@ class BaseResponse(_TemplateEnvironmentMixin): for key, value in flat.items(): querystring[key] = [value] elif self.body: - querystring.update(parse_qs(self.body, keep_blank_values=True)) + querystring.update(parse_qs(raw_body, keep_blank_values=True)) if not querystring: querystring.update(headers) diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 2889e520f..0df4c2dc9 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from __future__ import unicode_literals import boto @@ -54,6 +55,20 @@ def test_message_send(): messages.should.have.length_of(1) +@mock_sqs +def test_send_message_with_unicode_characters(): + body_one = 'Héllo!😀' + + sqs = boto3.resource('sqs', region_name='us-east-1') + queue = sqs.create_queue(QueueName="blah") + msg = queue.send_message(MessageBody=body_one) + + messages = queue.receive_messages() + message_body = messages[0].body + + message_body.should.equal(body_one) + + @mock_sqs def test_set_queue_attributes(): sqs = boto3.resource('sqs', region_name='us-east-1')