2023-07-10 21:04:31 +00:00
|
|
|
import unittest
|
2013-12-26 16:12:50 +00:00
|
|
|
|
2023-11-30 15:55:51 +00:00
|
|
|
import boto3
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws
|
2021-01-29 11:31:56 +00:00
|
|
|
from tests import EXAMPLE_AMI_ID
|
2013-12-26 16:12:50 +00:00
|
|
|
|
|
|
|
|
2021-09-22 21:50:27 +00:00
|
|
|
class TestNestedDecoratorsBoto3(unittest.TestCase):
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def setup_sqs_queue(self) -> None:
|
2021-09-22 21:50:27 +00:00
|
|
|
conn = boto3.resource("sqs", region_name="us-east-1")
|
|
|
|
queue = conn.create_queue(QueueName="some-queue")
|
|
|
|
|
|
|
|
queue.send_message(MessageBody="test message 1")
|
|
|
|
|
|
|
|
queue.reload()
|
2023-07-10 21:04:31 +00:00
|
|
|
assert queue.attributes["ApproximateNumberOfMessages"] == "1"
|
2021-09-22 21:50:27 +00:00
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def test_nested(self) -> None:
|
2021-09-22 21:50:27 +00:00
|
|
|
self.setup_sqs_queue()
|
|
|
|
|
|
|
|
conn = boto3.client("ec2", region_name="us-west-2")
|
|
|
|
conn.run_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1)
|
2024-01-07 12:03:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_multiple_mocks() -> None:
|
|
|
|
with mock_aws():
|
|
|
|
client = boto3.client("sqs", region_name="us-east-1")
|
|
|
|
client.create_queue(QueueName="some-queue")
|
|
|
|
|
|
|
|
# Starting another (inner) mock does not reset the data
|
|
|
|
with mock_aws():
|
|
|
|
assert len(client.list_queues()["QueueUrls"]) == 1
|
|
|
|
|
|
|
|
# Ending an inner mock does not reset the data
|
|
|
|
assert len(client.list_queues()["QueueUrls"]) == 1
|