2018-11-28 09:58:03 +01:00
|
|
|
# Copyright 2018 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
|
|
|
|
#
|
|
|
|
# http://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.
|
|
|
|
from botocore.session import Session
|
|
|
|
from tests import ClientHTTPStubber
|
2021-01-26 16:12:20 +01:00
|
|
|
from tests.functional import TEST_MODELS_DIR
|
2018-11-28 09:58:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_old_model_continues_to_work():
|
|
|
|
# This test ensures that botocore can load the service models as they exist
|
|
|
|
# today. There's a directory in tests/functional/models that is a
|
|
|
|
# snapshot of a service model. This test ensures that we can continue
|
|
|
|
# to stub an API call using this model. That way if the models ever
|
|
|
|
# change we have a mechanism to ensure that the existing models continue
|
|
|
|
# to work with botocore. The test should not change (with the exception
|
|
|
|
# of potential changes to the ClientHTTPStubber), and the files in
|
|
|
|
# tests/functional/models should not change!
|
|
|
|
session = Session()
|
|
|
|
loader = session.get_component('data_loader')
|
|
|
|
# We're adding our path to the existing search paths so we don't have to
|
2021-01-26 16:12:20 +01:00
|
|
|
# copy additional data files such as _retry.json to our TEST_MODELS_DIR.
|
2018-11-28 09:58:03 +01:00
|
|
|
# We only care about the service model and endpoints file not changing.
|
|
|
|
# This also prevents us from having to make any changes to this models dir
|
|
|
|
# if we end up adding a new data file that's needed to create clients.
|
2021-01-26 16:12:20 +01:00
|
|
|
# We're adding our TEST_MODELS_DIR as the first element in the list to
|
|
|
|
# ensure we load the endpoints.json file from TEST_MODELS_DIR. For the
|
2018-11-28 09:58:03 +01:00
|
|
|
# service model we have an extra safety net where we can choose a custom
|
|
|
|
# client name.
|
2021-01-26 16:12:20 +01:00
|
|
|
loader.search_paths.insert(0, TEST_MODELS_DIR)
|
2018-11-28 09:58:03 +01:00
|
|
|
|
2022-12-12 17:14:19 +01:00
|
|
|
# The model dir we copied from botocore/data/acm was renamed to
|
|
|
|
# 'custom-acm' to ensure we're loading our version of the model and
|
|
|
|
# not the built in one.
|
2018-11-28 09:58:03 +01:00
|
|
|
client = session.create_client(
|
2022-05-26 00:10:07 +02:00
|
|
|
'custom-acm',
|
|
|
|
region_name='us-west-2',
|
|
|
|
aws_access_key_id='foo',
|
|
|
|
aws_secret_access_key='bar',
|
2018-11-28 09:58:03 +01:00
|
|
|
)
|
|
|
|
with ClientHTTPStubber(client) as stubber:
|
|
|
|
stubber.add_response(
|
|
|
|
url='https://acm.us-west-2.amazonaws.com/',
|
2022-05-26 00:10:07 +02:00
|
|
|
headers={
|
|
|
|
'x-amzn-RequestId': 'abcd',
|
|
|
|
'Date': 'Fri, 26 Oct 2018 01:46:30 GMT',
|
|
|
|
'Content-Length': '29',
|
|
|
|
'Content-Type': 'application/x-amz-json-1.1',
|
|
|
|
},
|
|
|
|
body=b'{"CertificateSummaryList":[]}',
|
|
|
|
)
|
2018-11-28 09:58:03 +01:00
|
|
|
response = client.list_certificates()
|
2021-10-04 18:33:37 +02:00
|
|
|
assert response == {
|
|
|
|
'CertificateSummaryList': [],
|
|
|
|
'ResponseMetadata': {
|
|
|
|
'HTTPHeaders': {
|
|
|
|
'content-length': '29',
|
|
|
|
'content-type': 'application/x-amz-json-1.1',
|
|
|
|
'date': 'Fri, 26 Oct 2018 01:46:30 GMT',
|
2022-05-26 00:10:07 +02:00
|
|
|
'x-amzn-requestid': 'abcd',
|
|
|
|
},
|
2021-10-04 18:33:37 +02:00
|
|
|
'HTTPStatusCode': 200,
|
|
|
|
'RequestId': 'abcd',
|
2022-05-26 00:10:07 +02:00
|
|
|
'RetryAttempts': 0,
|
|
|
|
},
|
2021-10-04 18:33:37 +02:00
|
|
|
}
|
2018-11-28 09:58:03 +01:00
|
|
|
|
|
|
|
# Also verify we can use the paginators as well.
|
2021-10-04 18:33:37 +02:00
|
|
|
assert client.can_paginate('list_certificates') is True
|
|
|
|
assert client.waiter_names == ['certificate_validated']
|