Permalink
Browse files

Merge pull request #3737 from JordonPhillips/default-regioninfo

Use RegionInfo by default with heuristics
  • Loading branch information...
JordonPhillips committed Jun 14, 2017
2 parents dcfc751 + efe789f commit 0a9b11408698e3923201d27c67eef1a59e6dd105
Showing with 25 additions and 0 deletions.
  1. +2 −0 boto/regioninfo.py
  2. +12 −0 tests/unit/test_connect_to_region.py
  3. +11 −0 tests/unit/test_regioninfo.py
@@ -205,6 +205,8 @@ def connect(service_name, region_name, region_cls=None,
:returns: A configured connection class.
"""
if region_cls is None:
region_cls = RegionInfo
region = _get_region(service_name, region_name, region_cls, connection_cls)

if region is None and _use_endpoint_heuristics():
@@ -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 @@ def test_connect_to_region(self):
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):
@@ -200,6 +200,17 @@ def _getbool(section, name, default=False):
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()

0 comments on commit 0a9b114

Please sign in to comment.