def test_process_sqs_queue(self, client, process_fxa_event, get_session): messages = [ {'Body': 'foo', 'ReceiptHandle': '$$$'}, {'Body': 'bar'}, None, {'Body': 'thisonetoo'}, ] sqs = mock.MagicMock( **{'receive_message.side_effect': [{'Messages': messages}]} ) session_mock = mock.MagicMock( **{'get_available_regions.side_effect': ['nowh-ere']} ) get_session.return_value = session_mock delete_mock = mock.MagicMock() sqs.delete_message = delete_mock client.return_value = sqs with self.assertRaises(StopIteration): utils.process_sqs_queue(queue_url='https://sqs.nowh-ere.aws.com/123456789/') client.assert_called() client.assert_called_with('sqs', region_name='nowh-ere') process_fxa_event.assert_called() # The 'None' in messages would cause an exception, but it should be # handled, and the remaining message(s) still processed. process_fxa_event.assert_has_calls( [mock.call('foo'), mock.call('bar'), mock.call('thisonetoo')] ) delete_mock.assert_called_once() # Receipt handle is present in foo. delete_mock.assert_called_with( QueueUrl='https://sqs.nowh-ere.aws.com/123456789/', ReceiptHandle='$$$' )
def test_process_sqs_queue(self, client, process_fxa_event, get_session): messages = [ {'Body': 'foo', 'ReceiptHandle': '$$$'}, {'Body': 'bar'}, None, {'Body': 'thisonetoo'}] sqs = mock.MagicMock( **{'receive_message.side_effect': [{'Messages': messages}]}) session_mock = mock.MagicMock( **{'get_available_regions.side_effect': ['nowh-ere']}) get_session.return_value = session_mock delete_mock = mock.MagicMock() sqs.delete_message = delete_mock client.return_value = sqs with self.assertRaises(StopIteration): utils.process_sqs_queue( queue_url='https://sqs.nowh-ere.aws.com/123456789/') client.assert_called() client.assert_called_with( 'sqs', region_name='nowh-ere' ) process_fxa_event.assert_called() # The 'None' in messages would cause an exception, but it should be # handled, and the remaining message(s) still processed. process_fxa_event.assert_has_calls( [mock.call('foo'), mock.call('bar'), mock.call('thisonetoo')]) delete_mock.assert_called_once() # Receipt handle is present in foo. delete_mock.assert_called_with( QueueUrl='https://sqs.nowh-ere.aws.com/123456789/', ReceiptHandle='$$$')
def test_process_sqs_queue(self, client, process_fxa_event): messages = [{ 'Body': 'foo', 'ReceiptHandle': '$$$' }, { 'Body': 'bar' }, None, { 'Body': 'thisonetoo' }] sqs = mock.MagicMock( **{'receive_message.side_effect': [{ 'Messages': messages }]}) delete_mock = mock.MagicMock() sqs.delete_message = delete_mock client.return_value = sqs with self.assertRaises(StopIteration): utils.process_sqs_queue(queue_url='https://nowh.ere/', aws_region='NARNIA_1', queue_wait_time=20) client.assert_called() process_fxa_event.assert_called() # The 'None' in messages would cause an exception, but it should be # handled, and the remaining message(s) still processed. process_fxa_event.assert_has_calls( [mock.call('foo'), mock.call('bar'), mock.call('thisonetoo')]) delete_mock.assert_called_once() # Receipt handle is present in foo. delete_mock.assert_called_with(QueueUrl='https://nowh.ere/', ReceiptHandle='$$$')
def handle(self, *args, **options): queue_url = options['queue_url'] aws_region = options['aws_region'] queue_wait_time = settings.FXA_SQS_CONFIG['wait_time'] # Quieten boto - we don't need that much chatter in our logs logger.logging.getLogger('boto3').setLevel(logger.logging.WARNING) logger.logging.getLogger('botocore').setLevel(logger.logging.WARNING) process_sqs_queue(queue_url, aws_region, queue_wait_time)
def handle(self, *args, **options): queue_url = options['queue_url'] # Quieten boto - we don't need that much chatter in our logs logger.logging.getLogger('boto3').setLevel(logger.logging.WARNING) logger.logging.getLogger('botocore').setLevel(logger.logging.WARNING) process_sqs_queue(queue_url)
def handle(self, *args, **options): queue_url = options['queue_url'] # Quieten boto - we don't need that much chatter in our logs logger.logging.getLogger('boto3').setLevel(logger.logging.WARNING) logger.logging.getLogger('botocore').setLevel(logger.logging.WARNING) process_sqs_queue(queue_url)