|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | + |
| 14 | +from tests import ClientHTTPStubber, patch_load_service_model |
| 15 | +from tests.functional.botocore.test_useragent import ( |
| 16 | + get_captured_ua_strings, |
| 17 | + parse_registered_feature_ids, |
| 18 | +) |
| 19 | + |
| 20 | +MOCK_SERVICE_MODEL = { |
| 21 | + "version": "1.0", |
| 22 | + "documentation": "", |
| 23 | + "metadata": { |
| 24 | + "apiVersion": "2020-02-02", |
| 25 | + "endpointPrefix": "mockservice", |
| 26 | + "protocols": ["smithy-rpc-v2-cbor"], |
| 27 | + "protocol": "smithy-rpc-v2-cbor", |
| 28 | + "serviceFullName": "Mock Service", |
| 29 | + "serviceId": "mockservice", |
| 30 | + "signatureVersion": "v4", |
| 31 | + "signingName": "mockservice", |
| 32 | + "targetPrefix": "mockservice", |
| 33 | + "uid": "mockservice-2020-02-02", |
| 34 | + }, |
| 35 | + "operations": { |
| 36 | + "MockOperation": { |
| 37 | + "name": "MockOperation", |
| 38 | + "http": {"method": "GET", "requestUri": "/"}, |
| 39 | + "input": {"shape": "MockOperationRequest"}, |
| 40 | + "documentation": "", |
| 41 | + }, |
| 42 | + }, |
| 43 | + "shapes": { |
| 44 | + "MockOpParam": { |
| 45 | + "type": "string", |
| 46 | + }, |
| 47 | + "MockOperationRequest": { |
| 48 | + "type": "structure", |
| 49 | + "required": ["MockOpParam"], |
| 50 | + "members": { |
| 51 | + "MockOpParam": { |
| 52 | + "shape": "MockOpParam", |
| 53 | + "documentation": "", |
| 54 | + "location": "uri", |
| 55 | + "locationName": "param", |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | +} |
| 61 | + |
| 62 | +MOCK_RULESET = { |
| 63 | + "version": "1.0", |
| 64 | + "parameters": {}, |
| 65 | + "rules": [ |
| 66 | + { |
| 67 | + "conditions": [], |
| 68 | + "endpoint": { |
| 69 | + "url": "https://mockservice.us-west-2.amazonaws.com/" |
| 70 | + }, |
| 71 | + "type": "endpoint", |
| 72 | + }, |
| 73 | + ], |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +def test_user_agent_has_cbor_feature_id(patched_session, monkeypatch): |
| 78 | + patch_load_service_model( |
| 79 | + patched_session, monkeypatch, MOCK_SERVICE_MODEL, MOCK_RULESET |
| 80 | + ) |
| 81 | + client = patched_session.create_client( |
| 82 | + 'mockservice', region_name='us-west-2' |
| 83 | + ) |
| 84 | + with ClientHTTPStubber(client) as stub_client: |
| 85 | + stub_client.add_response() |
| 86 | + # The mock CBOR operation registers `'PROTOCOL_RPC_V2_CBOR': 'M'` |
| 87 | + client.mock_operation(MockOpParam='mock-op-param-value') |
| 88 | + ua_string = get_captured_ua_strings(stub_client)[0] |
| 89 | + feature_list = parse_registered_feature_ids(ua_string) |
| 90 | + assert 'M' in feature_list |
0 commit comments