Skip to content

Instantly share code, notes, and snippets.

@projectweekend
Last active December 26, 2015 18:59
Show Gist options
  • Save projectweekend/7197988 to your computer and use it in GitHub Desktop.
Save projectweekend/7197988 to your computer and use it in GitHub Desktop.
This function mocks the response the call to get messages from an Amazon SQS Queue...which is handy for testing when you don't want to make real calls to your SQS queue. The MESSAGE_BODY_TEMPLATE is simply a dictionary where the keys represent the keys in the output JSON message and the value represents a function to cast the appropriate datatyp…
from boto.sqs.jsonmessage import JSONMessage
MESSAGE_BODY_TEMPLATE = {
'article_id': int,
'owner_id': int,
'auth_token': str
}
NUMBER_OF_MESSAGES = 10
def mock_sqs_data():
def make_message_body(message_body_template, dummy_value):
output = {}
for k in message_body_template.keys():
apply_datatype = message_body_template[k]
output[k] = apply_datatype(dummy_value)
return output
output = []
for n in xrange(1, NUMBER_OF_MESSAGES):
message = JSONMessage()
message_body = make_message_body(MESSAGE_BODY_TEMPLATE, n)
encoded_body = message.encode(message_body)
message.set_body(encoded_body)
output.append(message)
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment