File: test_smoke.py

package info (click to toggle)
python-boto3 1.26.27%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,880 kB
  • sloc: python: 12,629; makefile: 128
file content (87 lines) | stat: -rw-r--r-- 2,970 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright 2015 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
#
# https://aws.amazon.com/apache2.0/
#
# 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.
import botocore.session
import pytest

from boto3.session import Session

boto3_session = None


def create_session():
    global boto3_session
    if boto3_session is None:
        boto3_session = Session(
            aws_access_key_id='dummy',
            aws_secret_access_key='dummy',
            region_name='us-east-1',
        )

    return boto3_session


def _all_resources():
    session = create_session()
    for service_name in session.get_available_resources():
        yield session, service_name


def _all_clients():
    session = create_session()
    for service_name in session.get_available_services():
        yield session, service_name


def _all_api_version_args():
    botocore_session = botocore.session.get_session()
    boto3_session = create_session()
    for service_name in boto3_session.get_available_resources():
        yield (service_name, botocore_session, boto3_session)


@pytest.mark.parametrize('resource_args', _all_resources())
def test_can_create_all_resources(resource_args):
    """Verify we can create all existing resources."""
    session, service_name = resource_args
    resource = session.resource(service_name)
    # Verifying we have a "meta" attr is just an arbitrary
    # sanity check.
    assert hasattr(resource, 'meta')


@pytest.mark.parametrize('client_args', _all_clients())
def test_can_create_all_clients(client_args):
    """Verify we can create all existing clients."""
    session, service_name = client_args
    client = session.client(service_name)
    assert hasattr(client, 'meta')


@pytest.mark.parametrize('api_version_args', _all_api_version_args())
def test_api_versions_synced_with_botocore(api_version_args):
    """Verify both boto3 and botocore clients stay in sync."""
    service_name, botocore_session, boto3_session = api_version_args
    resource = boto3_session.resource(service_name)
    boto3_api_version = resource.meta.client.meta.service_model.api_version
    client = botocore_session.create_client(
        service_name,
        region_name='us-east-1',
        aws_access_key_id='foo',
        aws_secret_access_key='bar',
    )
    botocore_api_version = client.meta.service_model.api_version
    err = (
        f"Different latest API versions found for {service_name}: "
        f"{botocore_api_version} (botocore), {boto3_api_version} (boto3)\n"
    )
    assert botocore_api_version == boto3_api_version, err