diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/s3/test_key.py | 5 | ||||
-rw-r--r-- | tests/unit/s3/test_connection.py | 31 | ||||
-rw-r--r-- | tests/unit/test_connect_to_region.py | 12 | ||||
-rw-r--r-- | tests/unit/test_regioninfo.py | 11 |
4 files changed, 55 insertions, 4 deletions
diff --git a/tests/integration/s3/test_key.py b/tests/integration/s3/test_key.py index 16f0220b..471857a7 100644 --- a/tests/integration/s3/test_key.py +++ b/tests/integration/s3/test_key.py @@ -419,7 +419,10 @@ class S3KeyTest(unittest.TestCase): remote_metadata = check._get_remote_metadata() # TODO: investigate whether encoding ' ' as '%20' makes sense - self.assertEqual(check.cache_control, 'public,%20max-age=500') + self.assertIn( + check.cache_control, + ('public,%20max-age=500', 'public, max-age=500') + ) self.assertEqual(remote_metadata['cache-control'], 'public,%20max-age=500') self.assertEqual(check.get_metadata('test-plus'), 'A plus (+)') self.assertEqual(check.content_disposition, 'filename=Sch%C3%B6ne%20Zeit.txt') diff --git a/tests/unit/s3/test_connection.py b/tests/unit/s3/test_connection.py index b382605d..05c561b4 100644 --- a/tests/unit/s3/test_connection.py +++ b/tests/unit/s3/test_connection.py @@ -96,6 +96,8 @@ class TestSigV4HostError(MockServiceWithConfigTestCase): self.assertEqual(self.service_connection.host, 's3.amazonaws.com') def test_sigv4_opt_in(self): + host_value = 's3.cn-north-1.amazonaws.com.cn' + # Switch it at the config, so we can check to see how the host is # handled. self.config = { @@ -104,6 +106,8 @@ class TestSigV4HostError(MockServiceWithConfigTestCase): } } + # Should raise an error if no host is given in either the config or + # in connection arguments. with self.assertRaises(HostRequiredError): # No host+SigV4 == KABOOM self.connection_class( @@ -111,11 +115,32 @@ class TestSigV4HostError(MockServiceWithConfigTestCase): aws_secret_access_key='more' ) - # Ensure passing a ``host`` still works. + # Ensure passing a ``host`` in the connection args still works. conn = self.connection_class( aws_access_key_id='less', aws_secret_access_key='more', - host='s3.cn-north-1.amazonaws.com.cn' + host=host_value + ) + self.assertEqual( + conn._required_auth_capability(), + ['hmac-v4-s3'] + ) + self.assertEqual( + conn.host, + host_value + ) + + # Ensure that the host is populated from our config if one is not + # provided when creating a connection. + self.config = { + 's3': { + 'host': host_value, + 'use-sigv4': True, + } + } + conn = self.connection_class( + aws_access_key_id='less', + aws_secret_access_key='more' ) self.assertEqual( conn._required_auth_capability(), @@ -123,7 +148,7 @@ class TestSigV4HostError(MockServiceWithConfigTestCase): ) self.assertEqual( conn.host, - 's3.cn-north-1.amazonaws.com.cn' + host_value ) diff --git a/tests/unit/test_connect_to_region.py b/tests/unit/test_connect_to_region.py index f7944b32..5f28112f 100644 --- a/tests/unit/test_connect_to_region.py +++ b/tests/unit/test_connect_to_region.py @@ -19,6 +19,8 @@ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +import os + from tests.unit import unittest @@ -191,6 +193,16 @@ class TestDynamodb2Connection(unittest.TestCase): self.assertIsInstance(connection, DynamoDBConnection) self.assertEqual(connection.host, 'dynamodb.us-east-1.amazonaws.com') + def test_connect_to_unkown_region(self): + from boto.dynamodb2 import connect_to_region + from boto.dynamodb2.layer1 import DynamoDBConnection + os.environ['BOTO_USE_ENDPOINT_HEURISTICS'] = 'True' + connection = connect_to_region( + 'us-east-45', aws_access_key_id='foo', + aws_secret_access_key='bar') + self.assertIsInstance(connection, DynamoDBConnection) + self.assertEqual(connection.host, 'dynamodb.us-east-45.amazonaws.com') + class TestEC2Connection(unittest.TestCase): def test_connect_to_region(self): diff --git a/tests/unit/test_regioninfo.py b/tests/unit/test_regioninfo.py index cff52be8..da73cb9b 100644 --- a/tests/unit/test_regioninfo.py +++ b/tests/unit/test_regioninfo.py @@ -200,6 +200,17 @@ class TestConnectToRegion(unittest.TestCase): expected_endpoint = 'ec2.us-southeast-43.amazonaws.com' self.assertEqual(connection.region.endpoint, expected_endpoint) + def test_connect_with_hueristics_without_explicit_regioninfo(self): + os.environ['BOTO_USE_ENDPOINT_HEURISTICS'] = 'True' + self.addCleanup(os.environ.pop, 'BOTO_USE_ENDPOINT_HEURISTICS') + connection = connect( + 'ec2', 'us-southeast-43', connection_cls=FakeConn) + self.assertIsNotNone(connection) + self.assertIsInstance(connection.region, RegionInfo) + self.assertEqual(connection.region.name, 'us-southeast-43') + expected_endpoint = 'ec2.us-southeast-43.amazonaws.com' + self.assertEqual(connection.region.endpoint, expected_endpoint) + if __name__ == '__main__': unittest.main() |