Last active
December 26, 2015 18:59
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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