Skip to content

Commit

Permalink
tests: stop depending on the values of S3 endpoints (#620)
Browse files Browse the repository at this point in the history
They seem to differ between botocore versions, so specify them manually
or mock `get_s3_endpoint` in the tests that need them.
  • Loading branch information
danielkza authored and phobologic committed Jul 4, 2018
1 parent 543f84f commit 28e2a22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
37 changes: 19 additions & 18 deletions stacker/tests/actions/test_base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()

import unittest

from botocore.stub import Stubber, ANY
import mock

import botocore.exceptions
from botocore.stub import Stubber, ANY

from stacker.actions.base import (
BaseAction
)

from stacker.providers.aws.default import Provider
from stacker.blueprints.base import Blueprint
from stacker.providers.aws.default import Provider
from stacker.session_cache import get_session

from stacker.tests.factories import (
Expand Down Expand Up @@ -121,30 +125,27 @@ def test_ensure_cfn_forbidden(self):
action.ensure_cfn_bucket()

def test_stack_template_url(self):
test_cases = (
("us-east-1", "s3.amazonaws.com"),
("us-west-1", "s3.us-west-1.amazonaws.com"),
("eu-west-1", "s3.eu-west-1.amazonaws.com"),
("sa-east-1", "s3.sa-east-1.amazonaws.com"),
)
context = mock_context("mynamespace")
blueprint = TestBlueprint(name="myblueprint", context=context)

for region, endpoint in test_cases:
session = get_session(region)
provider = Provider(session)
action = BaseAction(
context=context,
provider_builder=MockProviderBuilder(provider, region=region)
)
region = "us-east-1"
endpoint = "https://example.com"
session = get_session(region)
provider = Provider(session)
action = BaseAction(
context=context,
provider_builder=MockProviderBuilder(provider, region=region)
)

with mock.patch('stacker.actions.base.get_s3_endpoint', autospec=True,
return_value=endpoint):
self.assertEqual(
action.stack_template_url(blueprint),
"https://%s/%s/stack_templates/%s/%s-%s.json" % (
"%s/%s/stack_templates/%s/%s-%s.json" % (
endpoint,
"stacker-mynamespace",
"mynamespace-myblueprint",
"myblueprint",
MOCK_VERSION

)
)
14 changes: 4 additions & 10 deletions stacker/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,10 @@ def test_get_client_region(self):
self.assertEqual(get_client_region(client), region)

def test_get_s3_endpoint(self):
endpoint_map = {
"us-east-1": "https://s3.amazonaws.com",
"us-west-1": "https://s3.us-west-1.amazonaws.com",
"eu-west-1": "https://s3.eu-west-1.amazonaws.com",
"sa-east-1": "https://s3.sa-east-1.amazonaws.com",
}

for region in endpoint_map:
client = boto3.client("s3", region_name=region)
self.assertEqual(get_s3_endpoint(client), endpoint_map[region])
endpoint_url = "https://example.com"
client = boto3.client("s3", region_name="us-east-1",
endpoint_url=endpoint_url)
self.assertEqual(get_s3_endpoint(client), endpoint_url)

def test_s3_bucket_location_constraint(self):
tests = (
Expand Down

0 comments on commit 28e2a22

Please sign in to comment.