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='$$$')