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

Issue #450: Chalice generate-pipeline can create incompatible yaml #453

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
import json
import hashlib
import re

from typing import Any, Dict # noqa

Expand Down Expand Up @@ -150,8 +151,9 @@ def _generate_function_events(self, app):
events = {}
for methods in app.routes.values():
for http_method, view in methods.items():
mod_view_name = re.sub(r'[^A-Za-z0-9]+', '', view.view_name)
key_name = ''.join([
view.view_name, http_method.lower(),
mod_view_name, http_method.lower(),
hashlib.md5(
view.view_name.encode('utf-8')).hexdigest()[:4],
])
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ def foo():
return {}

return app


@fixture
def sample_app_incompatible_with_cf():
app = Chalice('sample_invalid_cf')

@app.route('/')
def foo_invalid():
return {}

return app
19 changes: 19 additions & 0 deletions tests/unit/test_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mock

import pytest
import re
from chalice.config import Config
from chalice import package
from chalice import __version__ as chalice_version
Expand Down Expand Up @@ -273,3 +274,21 @@ def test_fails_with_custom_auth(sample_app_with_auth,
app_name='myapp', manage_iam_role=False, iam_role_arn='role-arn')
with pytest.raises(package.UnsupportedFeatureError):
p.generate_sam_template(config)


def test_app_incompatible_with_cf(sample_app_incompatible_with_cf,
mock_swagger_generator,
mock_policy_generator):
p = package.SAMTemplateGenerator(
mock_swagger_generator, mock_policy_generator)
mock_swagger_generator.generate_swagger.return_value = {
'swagger': 'document'
}
config = Config.create(chalice_app=sample_app_incompatible_with_cf,
api_gateway_stage='dev',
app_name='sample_invalid_cf')
template = p.generate_sam_template(config)
check_exp = re.compile(r'[^A-Za-z0-9]+')
events = template['Resources']['APIHandler']['Properties']['Events']
for k in events.keys():
assert not check_exp.search(k)