Skip to content

Commit

Permalink
Merge pull request #22 from holger-zeit/fix-sqs-required-region-name
Browse files Browse the repository at this point in the history
fix sqs required region name
  • Loading branch information
alexeyts authored Apr 13, 2018
2 parents f7e46f6 + 9b226ec commit 5645cae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 5 additions & 1 deletion eb_sqs/aws/sqs_queue_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals

import boto3
from botocore.config import Config
from botocore.exceptions import ClientError

from eb_sqs import settings
Expand All @@ -10,7 +11,10 @@
class SqsQueueClient(QueueClient):
def __init__(self):
# type: () -> None
self.sqs = boto3.resource('sqs')
self.sqs = boto3.resource('sqs',
region_name=settings.AWS_REGION,
config=Config(retries={'max_attempts': settings.AWS_MAX_RETRIES})
)
self.queue_cache = {}

def _get_queue(self, queue_name):
Expand Down
26 changes: 14 additions & 12 deletions eb_sqs/tests/aws/tests_aws_queue_client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import absolute_import, unicode_literals

from unittest import TestCase
import time
from unittest import TestCase, skip

import boto3
import time
from moto import mock_sqs

from eb_sqs import settings
from eb_sqs.aws.sqs_queue_client import SqsQueueClient
from eb_sqs.worker.queue_client import QueueDoesNotExistException


class AwsQueueClientTest(TestCase):
Expand Down Expand Up @@ -34,17 +36,17 @@ def test_add_message_delayed(self):
queue.reload()
self.assertEqual(queue.attributes["ApproximateNumberOfMessages"], '0')

time.sleep(delay+0.1)
time.sleep(delay + 0.1)

queue.reload()
self.assertEqual(queue.attributes["ApproximateNumberOfMessages"], '1')

# Disabled because current mock_sqs doesn't support invalid queue call
#@mock_sqs()
#def test_add_message_wrong_queue(self):
# sqs = boto3.resource('sqs')
# queue = sqs.create_queue(QueueName='default')
# queue_client = SqsQueueClient()
#
# with self.assertRaises(QueueDoesNotExistException):
# queue_client.add_message('invalid', 'msg', 0)
@skip("Disabled because current mock_sqs doesn't support invalid queue call")
@mock_sqs()
def test_add_message_wrong_queue(self):
sqs = boto3.resource('sqs')
queue = sqs.create_queue(QueueName='default')
queue_client = SqsQueueClient()

with self.assertRaises(QueueDoesNotExistException):
queue_client.add_message('invalid', 'msg', 0)

0 comments on commit 5645cae

Please sign in to comment.