示例#1
0
def test_extract_and_validate_properties_missing():
    source = {
        'body': {
            'GitHubBranch': 'branch',
            'CodePipelineName': 'cpname',
            'ChangeMatchExpressions': '.*'
        }
    }

    with pytest.raises(ValueError) as e:
        resource.extract_and_validate_properties(source, 'body')
        assert 'GitHubRepo' in e.value
示例#2
0
def build_cf_event(eventType):
    event = {
        'LogicalResourceId': 'logicalId',
        'RequestId': 'aeef721d-6bad-474b-9eba-c0bc90b36c75',
        'RequestType': eventType,
        'ResourceProperties': {
            'ChangeMatchExpressions': '.*',
            'CodePipelineName': 'pipeline',
            'GitHubBranch': 'branch',
            'GitHubRepo': 'repo',
            'ServiceToken': 'arn'
        },
        'ResourceType': 'resource-type',
        'ResponseURL': 'https://some-url',
        'ServiceToken': 'arn:token',
        'StackId': 'arn:stack'
    }
    if eventType == 'Update':
        event['OldResourceProperties'] = {
            'ChangeMatchExpressions': '.*',
            'CodePipelineName': 'oldpipeline',
            'GitHubBranch': 'oldbranch',
            'GitHubRepo': 'oldrepo',
            'ServiceToken': 'oldarn'
        }
    props = resource.extract_and_validate_properties(event,
                                                     'ResourceProperties')
    return event, resource.get_filename(props), resource.props_to_config_data(
        props)
示例#3
0
def test_extract_and_validate_properties_for_reals():
    source = {
        'LogicalResourceId': 'MonoRepoTrigger',
        'RequestId': 'aeef721d-6bad-474b-9eba-c0bc90b36c75',
        'RequestType': 'Create',
        'ResourceProperties': {
            'ChangeMatchExpressions': 'cf-github-monorepo/.*,readme.md',
            'CodePipelineName': 'mono-repo-example',
            'GitHubBranch': 'master',
            'GitHubRepo': 'mono-repo-experiment',
            'ServiceToken':
            'arn:aws:lambda:us-east-1:0000:function:my-function'
        },
        'ResourceType': 'Custom::MonoRepoTriggerFunction',
        'ResponseURL': 'https://some-url',
        'ServiceToken': 'arn:aws:lambda:us-east-1:0000:function:my-function',
        'StackId': 'arn:aws:cloudformation:us-east-1:0000:stack/my-stack/22'
    }

    resource.extract_and_validate_properties(source, 'ResourceProperties')
示例#4
0
def test_extract_and_validate_properties():
    source = {
        'body': {
            'GitHubRepo': 'repo',
            'GitHubBranch': 'branch',
            'CodePipelineName': 'cpname',
            'ChangeMatchExpressions': '.*',
        }
    }

    actual = resource.extract_and_validate_properties(source, 'body')

    actual_dict = asdict(actual)
    source['body']['ServiceToken'] = None
    assert actual_dict == source['body']
示例#5
0
def test_handler_update(deleteS3, putS3, sendResponse):
    event, filename, config = build_cf_event('Update')
    oldprops = resource.extract_and_validate_properties(
        event, 'OldResourceProperties')
    oldfilename = resource.get_filename(oldprops)

    resource.handler(event, None)

    s3_delete_args = deleteS3.call_args.args
    assert s3_delete_args[1] == 'test-bucket'
    assert s3_delete_args[2] == resource.get_s3_key(oldfilename)
    s3_args = putS3.call_args.args
    assert s3_args[1] == 'test-bucket'
    assert s3_args[2] == resource.get_s3_key(filename)
    assert s3_args[3] == config
    assert s3_args[4] == 'application/json'
    response_args = sendResponse.call_args.args
    assert response_args[0] == 'https://some-url'
    assert response_args[1]['Status'] == 'SUCCESS'