Skip to content

Commit

Permalink
Fix bug in xform_name for already transformed names
Browse files Browse the repository at this point in the history
This is a regression introduced from boto#240

The fix here is to not translate names if they already appear
to be translated.
  • Loading branch information
jamesls committed Apr 1, 2014
1 parent bba88c7 commit f8e6391
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
11 changes: 9 additions & 2 deletions botocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ def emit(self, record):


def xform_name(name, sep='_', _xform_cache=_xform_cache):
"""Convert camel case to a "pythonic" name.
If the name contains the ``sep`` character, then it is
returned unchanged.
"""
Convert camel case to a "pythonic" name.
"""
if sep in name:
# If the sep is in the name, assume that it's already
# transformed and return the string unchanged.
return name
key = (name, sep)
if key not in _xform_cache:
s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/test_cloudtrail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# 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
#
# 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 BaseSessionTest
import botocore.session


class TestCloudTrailOperations(BaseSessionTest):

def setUp(self):
super(TestCloudTrailOperations, self).setUp()
self.cloudtrail = self.session.get_service('cloudtrail')

def test_cloudtrail_create_subscription(self):
op = self.cloudtrail.get_operation('CreateTrail')
kwargs = {
"name": "name",
"s3_bucket_name": "s3bucketname",
"s3_key_prefix": "s3keyprefix",
"sns_topic_name": "snstopicname",
"include_global_service_events": True
}
params = op.build_parameters(**kwargs)
result = {
'Name': 'name',
'S3BucketName': 's3bucketname',
'S3KeyPrefix': 's3keyprefix',
'SnsTopicName': 'snstopicname',
'IncludeGlobalServiceEvents': True,
}
self.assertEqual(params, result)
5 changes: 5 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ def test_consecutive_upper_case_middle_string(self):
self.assertEqual(xform_name('MainHTTPHeaders'), 'main_http_headers')
self.assertEqual(xform_name('MainHTTPHeaders', '-'), 'main-http-headers')

def test_s3_prefix(self):
self.assertEqual(xform_name('S3BucketName'), 's3_bucket_name')

def test_already_snake_cased(self):
self.assertEqual(xform_name('leave_alone'), 'leave_alone')
self.assertEqual(xform_name('s3_bucket_name'), 's3_bucket_name')
self.assertEqual(xform_name('bucket_s3_name'), 'bucket_s3_name')

def test_special_cases(self):
# Some patterns don't actually match the rules we expect.
Expand Down

0 comments on commit f8e6391

Please sign in to comment.