forked from boto/botocore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 6 commits.
# This is the 1st commit message: # This is a combination of 6 commits. # This is the 1st commit message: Add idempotency token autoinjection. # The commit message boto#2 will be skipped: # Remove unused imports # The commit message boto#3 will be skipped: # First draft of injecting idempotencyToken # The commit message boto#4 will be skipped: # Register with the before-parameter-build event everywhere. # The commit message boto#5 will be skipped: # Test injecting indepotency token and not replacing an existing one. # The commit message boto#6 will be skipped: # Not sure how I managed to modify this. # The commit message boto#7 will be skipped: # PEP8 # The commit message boto#8 will be skipped: # PEP8 # The commit message boto#9 will be skipped: # Ignore mock models from tests that do not care about the model. # The commit message boto#10 will be skipped: # Remove test for members which will always be on input_shape # The commit message boto#1 will be skipped: # Rewrite functional test as two functional tests # The commit message boto#2 will be skipped: # Make the idempotency callback less specific/lower priority # The commit message boto#3 will be skipped: # Change tests so the assert happens in the test fns instead of setup # The commit message boto#4 will be skipped: # Fix tests to use MagicMock which handles iteration properly. # The commit message boto#5 will be skipped: # Add better logger message # The commit message boto#6 will be skipped: # Add a unit test for idempotent token injection # The commit message boto#2 will be skipped: # Move idempotency check to the operation model # The commit message boto#3 will be skipped: # Fix unit test to mock the new get_idempotent_members # The commit message boto#4 will be skipped: # Change name and get rid of redundant property # The commit message boto#5 will be skipped: # Added idempotency to the metadata # The commit message boto#6 will be skipped: # Added test for a pre-provided idempotency key
- Loading branch information
John Carlyle
committed
Dec 1, 2016
1 parent
59165f4
commit 1eba0c9
Showing
10 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"category": "parameter", | ||
"type": "feature", | ||
"description": "Automatically inject an idempotency token into parameters marked with the idempotencyToken trait" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2016 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 tests import unittest | ||
from tests.functional.docs import BaseDocsFunctionalTest | ||
from botocore.stub import Stubber, StubAssertionError, ANY | ||
import botocore.session | ||
|
||
|
||
class TestIdempotencyToken(unittest.TestCase): | ||
def setUp(self): | ||
self.function_name = 'purchase_scheduled_instances' | ||
self.region = 'us-west-2' | ||
self.session = botocore.session.get_session() | ||
self.client = self.session.create_client( | ||
'ec2', self.region) | ||
self.stubber = Stubber(self.client) | ||
self.service_response = {} | ||
self.params_seen = [] | ||
|
||
# Record all the parameters that get seen | ||
self.client.meta.events.register_first( | ||
'before-call.*.*', | ||
self.collect_params, | ||
unique_id='TestIdempotencyToken') | ||
|
||
def collect_params(self, model, params, *args, **kwargs): | ||
self.params_seen.extend(params['body'].keys()) | ||
|
||
def test_provided_idempotency_token(self): | ||
expected_params = { | ||
'PurchaseRequests': [ | ||
{'PurchaseToken': 'foo', | ||
'InstanceCount': 123}], | ||
'ClientToken': ANY | ||
} | ||
self.stubber.add_response( | ||
self.function_name, self.service_response, expected_params) | ||
|
||
with self.stubber: | ||
self.client.purchase_scheduled_instances( | ||
PurchaseRequests=[{'PurchaseToken': 'foo', | ||
'InstanceCount': 123}], | ||
ClientToken='foobar') | ||
self.assertIn('ClientToken', self.params_seen) | ||
|
||
def test_insert_idempotency_token(self): | ||
expected_params = { | ||
'PurchaseRequests': [ | ||
{'PurchaseToken': 'foo', | ||
'InstanceCount': 123}], | ||
} | ||
|
||
self.stubber.add_response( | ||
self.function_name, self.service_response, expected_params) | ||
|
||
with self.stubber: | ||
self.client.purchase_scheduled_instances( | ||
PurchaseRequests=[{'PurchaseToken': 'foo', | ||
'InstanceCount': 123}]) | ||
self.assertIn('ClientToken', self.params_seen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2012-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 | ||
# | ||
# 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 tests import unittest | ||
import re | ||
import mock | ||
from botocore.handlers import generate_idempotent_uuid | ||
|
||
|
||
class TestIdempotencyInjection(unittest.TestCase): | ||
def setUp(self): | ||
self.mock_model = mock.MagicMock() | ||
self.mock_model.idempotent_members = ['RequiredKey'] | ||
self.uuid_pattern = re.compile( | ||
'^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$', | ||
re.I) | ||
|
||
def test_injection(self): | ||
# No parameters are provided, RequiredKey should be autofilled | ||
params = {} | ||
generate_idempotent_uuid(params, self.mock_model) | ||
self.assertIn('RequiredKey', params) | ||
self.assertIsNotNone(self.uuid_pattern.match(params['RequiredKey'])) | ||
|
||
def test_provided(self): | ||
# RequiredKey is provided, should not be replaced | ||
params = {'RequiredKey': 'already populated'} | ||
generate_idempotent_uuid(params, self.mock_model) | ||
self.assertEquals(params['RequiredKey'], 'already populated') |