"""Test integration of an app with SQS.""" from unittest import mock import boto3 from boto3.resources.base import ServiceResource from botocore.exceptions import ProfileNotFound from moto import mock_sqs from notifications_delivery.connectors import sqs def test_get_connection(): """Test if get_connection() returns a valid connection object.""" # mocking with mock_sqs(): # test function call connection = sqs.get_sqs_resources() # checking assert connection assert isinstance(connection, ServiceResource) @mock.patch('boto3.resource') def test_get_connection_failure(boto3_mock): """Test if get_connection() returns a valid connection object.""" # mocking boto3_mock.side_effect = ProfileNotFound(profile='none') with mock_sqs(): # test function call sqs_resource = sqs.get_sqs_resources() # checking assert sqs_resource is None def test_get_queue_success(): """Test if get_queue() returns a Queue.""" # mocking with mock_sqs(): test_queue_name = 'test_queue_name' client = boto3.client('sqs') response = client.create_queue(QueueName=test_queue_name) expected_queue_url = response['QueueUrl'] # test function call queue = sqs.get_queue(expected_queue_url) # checking assert queue is not None assert queue.url == expected_queue_url @mock.patch('notifications_delivery.connectors.sqs.get_sqs_resources') def test_get_queue_failure(get_sqs_resources_mock): """Test failure if get_queue() returns None.""" # data preparation test_queue_url = 'test_queue_url' # mocking get_sqs_resources_mock.return_value = None # test function call queue = sqs.get_queue(test_queue_url) # checking assert queue is None