Exemplo n.º 1
0
def test_replace_body():
    updater = RestAPIBodyUpdater()
    updater.resource_name = 'RestAPI'
    updater.template = json.loads(json.dumps(sample))
    updater.body = {'swagger': '2.0', 'description': 'a new one'}

    updater.update_template()
    assert updater.dirty
    assert 'description' in updater.template['Resources']['RestAPI'][
        'Properties']['Body']
    assert updater.template['Resources']['RestAPI']['Properties']['Body'][
        'description'] == 'a new one'
Exemplo n.º 2
0
def test_load_and_merge():
    updater = RestAPIBodyUpdater()
    updater.resource_name = 'RestAPI'
    updater.template = json.loads(json.dumps(sample))
    updater.api_gateway_extensions = 'tests/aws-extensions.yaml'
    updater.open_api_specification = 'tests/api-specification.yaml'
    updater.body = updater.load_and_merge_swagger_body()
    updater.update_template()

    assert updater.dirty
    assert updater.template['Resources']['RestAPI']['Properties'][
        'Body'] == updater.body
Exemplo n.º 3
0
def test_add_new_version_keep_two():
    updater = RestAPIBodyUpdater()
    updater.resource_name = 'RestAPI'
    updater.template = json.loads(json.dumps(multiple))
    updater.body = {'swagger': '2.0', 'description': 'a new one'}

    updater.add_new_version = True
    updater.keep = 2
    updater.update_template()
    assert updater.dirty
    assert 'RestAPI' not in updater.template['Resources']
    assert 'RestAPIv2' not in updater.template['Resources']
    assert 'RestAPIv3' in updater.template['Resources']
    assert 'RestAPIv4' in updater.template['Resources']
    assert 'GLOBAL' == updater.template['Resources']['RestAPIv4'][
        'Properties']['EndpointConfiguration']['Types'][0]
    assert 'description' in updater.template['Resources']['RestAPIv4'][
        'Properties']['Body']
    assert updater.template['Resources']['RestAPIv4']['Properties']['Body'][
        'description'] == 'a new one'

    assert updater.template['Resources']['Deployment']['Properties'][
        'RestApiId']['Ref'] == 'RestAPIv4'
Exemplo n.º 4
0
def test_matching_names():
    updater = RestAPIBodyUpdater()
    updater.resource_name = 'RestAPI'
    updater.template = {
        'Resources': {
            'RestAPIv10': {
                'Type': 'AWS::ApiGateway::RestApi'
            },
            'RestApi': {
                'Type': 'AWS::ApiGateway::RestApi'
            },
            'Restv2APiv1': {
                'Type': 'AWS::ApiGateway::RestApi'
            },
            'RestAPIv1': {
                'Type': 'AWS::ApiGateway::RestApi'
            },
            'RestAPIv0': {
                'Type': 'AWS::ApiGateway::RestApi'
            },
            'RestAPIv_01': {
                'Type': 'AWS::ApiGateway::RestApi'
            }
        }
    }

    result = updater.find_matching_resources()
    assert result == ['RestAPIv0', 'RestAPIv1', 'RestAPIv10']

    updater.resource_name = 'RestApi'
    result = updater.find_matching_resources()
    assert result == ['RestApi']

    updater.resource_name = 'NotARestApi'
    result = updater.find_matching_resources()
    assert not result