Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RegionInfo by default with heuristics #3737

Merged
merged 1 commit into from Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions boto/regioninfo.py
Expand Up @@ -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():
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_connect_to_region.py
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_regioninfo.py
Expand Up @@ -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()