Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_app_policy_generator_vpc_policy():
config = Config.create(
subnet_ids=['sn1', 'sn2'],
security_group_ids=['sg1', 'sg2'],
project_dir='.'
)
generator = AppPolicyGenerator(OsUtilsMock())
policy = generator.generate_policy(config)
assert policy == {'Statement': [
{'Action': ['logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents'],
'Effect': 'Allow',
'Resource': 'arn:aws:logs:*:*:*'},
{'Action': ['ec2:CreateNetworkInterface',
'ec2:DescribeNetworkInterfaces',
'ec2:DetachNetworkInterface',
'ec2:DeleteNetworkInterface'],
def test_can_package_sns_handler(self, sample_app):
@sample_app.on_sns_message(topic='foo')
def handler(event):
pass
config = Config.create(chalice_app=sample_app,
project_dir='.',
api_gateway_stage='api')
template = self.generate_template(config, 'dev')
assert template['resource']['aws_sns_topic_subscription'][
'handler-sns-subscription'] == {
'topic_arn': (
'arn:aws:sns:${data.aws_region.chalice.name}:'
'${data.aws_caller_identity.chalice.account_id}:foo'),
'protocol': 'lambda',
'endpoint': '${aws_lambda_function.handler.arn}'
}
def test_validate_names_using_name_kwarg(sample_app):
@sample_app.authorizer(name='duplicate')
def foo(auth_request):
pass
@sample_app.lambda_function(name='duplicate')
def bar(event):
pass
config = Config.create(chalice_app=sample_app, manage_iam_role=False)
with pytest.raises(ValueError):
validate_unique_function_names(config)
def test_python_version_invalid_from_real_config():
config = Config.create()
with pytest.warns(UserWarning):
validate_python_version(config, 'python1.0')
def test_sam_generates_sam_template_basic(self, sample_app):
config = Config.create(chalice_app=sample_app,
project_dir='.',
api_gateway_stage='api')
template = self.generate_template(config, 'dev')
# Verify the basic structure is in place. The specific parts
# are validated in other tests.
assert template['AWSTemplateFormatVersion'] == '2010-09-09'
assert template['Transform'] == 'AWS::Serverless-2016-10-31'
assert 'Outputs' in template
assert 'Resources' in template
assert list(sorted(template['Resources'])) == [
'APIHandler', 'APIHandlerInvokePermission',
# This casing on the ApiHandlerRole name is unfortunate, but the 3
# other resources in this list are hardcoded from the old deployer.
'ApiHandlerRole',
'RestAPI',
]
def test_can_package_sns_arn_handler(self, sample_app):
arn = 'arn:aws:sns:space-leo-1:1234567890:foo'
@sample_app.on_sns_message(topic=arn)
def handler(event):
pass
config = Config.create(chalice_app=sample_app,
project_dir='.',
api_gateway_stage='api')
template = self.generate_template(config, 'dev')
sns_handler = template['Resources']['Handler']
assert sns_handler['Properties']['Events'] == {
'HandlerSnsSubscription': {
'Type': 'SNS',
'Properties': {
'Topic': arn,
}
def test_can_package_s3_event_handler_sans_filters(self, sample_app):
@sample_app.on_s3_event(bucket='foo')
def handler(event):
pass
config = Config.create(chalice_app=sample_app,
project_dir='.',
api_gateway_stage='api')
template = self.generate_template(config, 'dev')
assert template['resource']['aws_s3_bucket_notification'][
'foo_notify'] == {
'bucket': 'foo',
'lambda_function': [{
'events': ['s3:ObjectCreated:*'],
'lambda_function_arn': (
'${aws_lambda_function.handler.arn}')
}]
def test_lazy_load_chalice_app_must_be_callable():
c = Config.create(chalice_app='not a callable')
with pytest.raises(TypeError):
c.chalice_app
def new_project(project_name, profile):
# type: (str, str) -> None
if project_name is None:
project_name = getting_started_prompt(click)
if os.path.isdir(project_name):
click.echo("Directory already exists: %s" % project_name, err=True)
raise click.Abort()
create_new_project_skeleton(project_name, profile)
validate_python_version(Config.create())