diff --git a/moto/core/responses.py b/moto/core/responses.py index e48f7df9b..726eac686 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -43,7 +43,8 @@ def _decode_dict(d): class BaseResponse(object): - region = 'us-east-1' + default_region = 'us-east-1' + region_regex = r'\.(.+?)\.amazonaws\.com' def dispatch(self, request, full_url, headers): querystring = {} @@ -76,9 +77,11 @@ class BaseResponse(object): self.path = urlparse(full_url).path self.querystring = querystring self.method = request.method - region = re.search(r'\.(.+?)\.amazonaws\.com', full_url) + region = re.search(self.region_regex, full_url) if region: self.region = region.group(1) + else: + self.region = self.default_region self.headers = dict(request.headers) self.response_headers = headers diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index a151d62ca..6ab053483 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -16,6 +16,8 @@ MAXIMUM_VISIBILTY_TIMEOUT = 43200 class QueuesResponse(BaseResponse): + region_regex = r'://(.+?)\.queue\.amazonaws\.com' + @property def sqs_backend(self): return sqs_backends[self.region] diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 7f60bb17c..fcad635d1 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -10,6 +10,7 @@ import time from moto import mock_sqs from tests.helpers import requires_boto_gte + @mock_sqs def test_create_queue(): conn = boto.connect_sqs('the_key', 'the_secret') @@ -21,6 +22,18 @@ def test_create_queue(): all_queues[0].get_timeout().should.equal(60) +@mock_sqs +def test_create_queues_in_multiple_region(): + west1_conn = boto.sqs.connect_to_region("us-west-1") + west1_conn.create_queue("test-queue") + + west2_conn = boto.sqs.connect_to_region("us-west-2") + west2_conn.create_queue("test-queue") + + list(west1_conn.get_all_queues()).should.have.length_of(1) + list(west2_conn.get_all_queues()).should.have.length_of(1) + + @mock_sqs def test_get_queue(): conn = boto.connect_sqs('the_key', 'the_secret') @@ -113,13 +126,13 @@ def test_send_message_with_attributes(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) queue.set_message_class(RawMessage) - + body = 'this is a test message' message = queue.new_message(body) message_attributes = { - 'test.attribute_name' : {'data_type' : 'String', 'string_value' : 'attribute value'}, - 'test.binary_attribute' : {'data_type' : 'Binary', 'binary_value' : 'binary value'}, - 'test.number_attribute' : {'data_type' : 'Number', 'string_value' : 'string value'} + 'test.attribute_name': {'data_type': 'String', 'string_value': 'attribute value'}, + 'test.binary_attribute': {'data_type': 'Binary', 'binary_value': 'binary value'}, + 'test.number_attribute': {'data_type': 'Number', 'string_value': 'string value'} } message.message_attributes = message_attributes