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
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'
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'