2015-11-27 23:25:33 +01:00
|
|
|
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
|
|
# may not use this file except in compliance with the License. A copy of
|
|
|
|
# the License is located at
|
|
|
|
#
|
2021-09-22 18:34:33 +02:00
|
|
|
# https://aws.amazon.com/apache2.0/
|
2015-11-27 23:25:33 +01:00
|
|
|
#
|
|
|
|
# or in the "license" file accompanying this file. This file is
|
|
|
|
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
|
|
# ANY KIND, either express or implied. See the License for the specific
|
|
|
|
# language governing permissions and limitations under the License.
|
|
|
|
|
2021-10-04 19:51:32 +02:00
|
|
|
import pytest
|
2015-11-27 23:25:33 +01:00
|
|
|
|
2021-10-04 19:51:32 +02:00
|
|
|
import boto3.session
|
|
|
|
from boto3.resources.base import ServiceResource
|
2022-05-26 01:13:54 +02:00
|
|
|
from boto3.resources.collection import CollectionManager
|
2015-11-27 23:25:33 +01:00
|
|
|
|
|
|
|
# A map of services to regions that cannot use us-west-2
|
|
|
|
# for the integration tests.
|
2022-05-26 01:13:54 +02:00
|
|
|
REGION_MAP = {'opsworks': 'us-east-1'}
|
2015-11-27 23:25:33 +01:00
|
|
|
|
|
|
|
# A list of collections to ignore. They require parameters
|
|
|
|
# or are very slow to run.
|
2021-10-04 19:51:32 +02:00
|
|
|
BLOCKLIST = {
|
2015-11-27 23:25:33 +01:00
|
|
|
'ec2': ['images'],
|
|
|
|
'iam': ['signing_certificates'],
|
2022-05-26 01:13:54 +02:00
|
|
|
'sqs': ['dead_letter_source_queues'],
|
2015-11-27 23:25:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-04 19:51:32 +02:00
|
|
|
def all_collections():
|
|
|
|
# This generator yields every collection on every available resource,
|
|
|
|
# except those which have been blocklisted.
|
2015-11-27 23:25:33 +01:00
|
|
|
session = boto3.session.Session()
|
|
|
|
for service_name in session.get_available_resources():
|
|
|
|
resource = session.resource(
|
2022-05-26 01:13:54 +02:00
|
|
|
service_name, region_name=REGION_MAP.get(service_name, 'us-west-2')
|
|
|
|
)
|
2015-11-27 23:25:33 +01:00
|
|
|
|
|
|
|
for key in dir(resource):
|
2021-10-04 19:51:32 +02:00
|
|
|
if key in BLOCKLIST.get(service_name, []):
|
2015-11-27 23:25:33 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
value = getattr(resource, key)
|
|
|
|
if isinstance(value, CollectionManager):
|
2021-10-04 19:51:32 +02:00
|
|
|
yield value
|
|
|
|
|
2015-11-27 23:25:33 +01:00
|
|
|
|
2021-10-04 19:51:32 +02:00
|
|
|
@pytest.mark.parametrize("collection", all_collections())
|
|
|
|
def test_all_collections(collection):
|
|
|
|
"""Test all collections work on every available resource."""
|
2015-11-27 23:25:33 +01:00
|
|
|
# Create a list of the first page of items. This tests that
|
|
|
|
# a remote request can be made, the response parsed, and that
|
|
|
|
# resources are successfully created.
|
2021-10-04 19:51:32 +02:00
|
|
|
collection_list = list(collection.limit(1))
|
|
|
|
assert len(collection_list) < 2
|
|
|
|
assert all([isinstance(res, ServiceResource) for res in collection_list])
|