def test_parse_all_data(self):
        self.fdm_data = FdmSwaggerParser().parse_spec(self.base_data)
        operations = self.fdm_data['operations']
        without_model_name = []
        expected_operations_counter = 0
        for key in self.base_data['paths']:
            operation = self.base_data['paths'][key]
            for dummy in operation:
                expected_operations_counter += 1

        for key in operations:
            operation = operations[key]
            if not operation['modelName']:
                without_model_name.append(operation['url'])

            if operation[
                    'modelName'] == '_File' and 'download' not in operation[
                        'url']:
                self.fail(
                    'File type can be defined for download operation only')

        assert sorted([
            '/api/fdm/v2/operational/deploy/{objId}',
            '/api/fdm/v2/action/upgrade'
        ]) == sorted(without_model_name)
        assert sorted(
            self.fdm_data['model_operations'][None].keys()) == sorted(
                ['deleteDeployment', 'startUpgrade'])
        assert expected_operations_counter == len(operations)
    def test_with_all_data(self):
        fdm_data = FdmSwaggerParser().parse_spec(self.base_data)
        validator = FdmSwaggerValidator(fdm_data)
        models = fdm_data['models']
        operations = fdm_data['operations']

        invalid = set({})
        for operation in operations:
            model_name = operations[operation]['modelName']
            method = operations[operation]['method']
            if method != 'get' and model_name in models:
                if 'example' in models[model_name]:
                    example = models[model_name]['example']
                    try:
                        valid, rez = validator.validate_data(
                            operation, example)
                        assert valid
                    except Exception:
                        invalid.add(model_name)
        assert invalid == set([
            'TCPPortObject', 'UDPPortObject', 'ICMPv4PortObject',
            'ICMPv6PortObject', 'StandardAccessList', 'ExtendedAccessList',
            'ASPathList', 'RouteMap', 'StandardCommunityList',
            'ExpandedCommunityList', 'IPV4PrefixList', 'IPV6PrefixList',
            'PolicyList', 'SyslogServer', 'HAConfiguration',
            'TestIdentitySource'
        ])
Beispiel #3
0
    def test_simple_object_with_documentation(self):
        api_spec = copy.deepcopy(base)
        docs = {
            'definitions': {
                'NetworkObject': {
                    'description': 'Description for Network Object',
                    'properties': {
                        'name': 'Description for name field'
                    }
                }
            },
            'paths': {
                '/object/networks': {
                    'get': {
                        'description':
                        'Description for getNetworkObjectList operation',
                        'parameters': [{
                            'name':
                            'offset',
                            'description':
                            'Description for offset field'
                        }]
                    },
                    'post': {
                        'description':
                        'Description for addNetworkObject operation'
                    }
                }
            }
        }

        self.fdm_data = FdmSwaggerParser().parse_spec(api_spec, docs)

        assert 'Description for Network Object' == self.fdm_data['models'][
            'NetworkObject']['description']
        assert '' == self.fdm_data['models']['NetworkObjectWrapper'][
            'description']
        network_properties = self.fdm_data['models']['NetworkObject'][
            'properties']
        assert '' == network_properties['id']['description']
        assert not network_properties['id']['required']
        assert 'Description for name field' == network_properties['name'][
            'description']
        assert network_properties['name']['required']

        ops = self.fdm_data['operations']
        assert 'Description for getNetworkObjectList operation' == ops[
            'getNetworkObjectList']['description']
        assert 'Description for addNetworkObject operation' == ops[
            'addNetworkObject']['description']
        assert '' == ops['deleteNetworkObject']['description']

        get_op_params = ops['getNetworkObjectList']['parameters']
        assert 'Description for offset field' == get_op_params['query'][
            'offset']['description']
        assert '' == get_op_params['query']['limit']['description']
Beispiel #4
0
 def api_spec(self):
     if self._api_spec is None:
         spec_path_url = self._get_api_spec_path()
         response = self.send_request(url_path=spec_path_url, http_method=HTTPMethod.GET)
         if response[ResponseParams.SUCCESS]:
             self._api_spec = FdmSwaggerParser().parse_spec(response[ResponseParams.RESPONSE])
         else:
             raise ConnectionError('Failed to download API specification. Status code: %s. Response: %s' % (
                 response[ResponseParams.STATUS_CODE], response[ResponseParams.RESPONSE]))
     return self._api_spec
Beispiel #5
0
    def test_model_operations_should_contain_all_operations(self):
        data = {
            'basePath': '/v2/',
            'definitions': {
                'Model1': {
                    "type": "object"
                },
                'Model2': {
                    "type": "object"
                },
                'Model3': {
                    "type": "object"
                }
            },
            'paths': {
                'path1': {
                    'get': {
                        'operationId': 'getSomeModelList',
                        "responses": {
                            "200": {
                                "description": "",
                                "schema": {
                                    "type": "object",
                                    "title": "NetworkObjectList",
                                    "properties": {
                                        "items": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/Model1"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "post": {
                        "operationId":
                        "addSomeModel",
                        "parameters": [{
                            "in": "body",
                            "name": "body",
                            "schema": {
                                "$ref": "#/definitions/Model2"
                            }
                        }]
                    }
                },
                'path2/{id}': {
                    "get": {
                        "operationId": "getSomeModel",
                        "responses": {
                            "200": {
                                "description": "",
                                "schema": {
                                    "type": "object",
                                    "$ref": "#/definitions/Model3"
                                }
                            },
                        }
                    },
                    "put": {
                        "operationId":
                        "editSomeModel",
                        "parameters": [{
                            "in": "body",
                            "name": "body",
                            "schema": {
                                "$ref": "#/definitions/Model1"
                            }
                        }]
                    },
                    "delete": {
                        "operationId": "deleteModel3",
                    }
                },
                'path3': {
                    "delete": {
                        "operationId": "deleteNoneModel",
                    }
                }
            }
        }

        expected_operations = {
            'getSomeModelList': {
                'method': HTTPMethod.GET,
                'url': '/v2/path1',
                'modelName': 'Model1',
                'returnMultipleItems': True,
                'tags': []
            },
            'addSomeModel': {
                'method': HTTPMethod.POST,
                'url': '/v2/path1',
                'modelName': 'Model2',
                'parameters': {
                    'path': {},
                    'query': {}
                },
                'returnMultipleItems': False,
                'tags': []
            },
            'getSomeModel': {
                'method': HTTPMethod.GET,
                'url': '/v2/path2/{id}',
                'modelName': 'Model3',
                'returnMultipleItems': False,
                'tags': []
            },
            'editSomeModel': {
                'method': HTTPMethod.PUT,
                'url': '/v2/path2/{id}',
                'modelName': 'Model1',
                'parameters': {
                    'path': {},
                    'query': {}
                },
                'returnMultipleItems': False,
                'tags': []
            },
            'deleteModel3': {
                'method': HTTPMethod.DELETE,
                'url': '/v2/path2/{id}',
                'modelName': 'Model3',
                'returnMultipleItems': False,
                'tags': []
            },
            'deleteNoneModel': {
                'method': HTTPMethod.DELETE,
                'url': '/v2/path3',
                'modelName': None,
                'returnMultipleItems': False,
                'tags': []
            }
        }

        fdm_data = FdmSwaggerParser().parse_spec(data)
        assert sorted(['Model1', 'Model2',
                       'Model3']) == sorted(fdm_data['models'].keys())
        assert expected_operations == fdm_data['operations']
        assert {
            'Model1': {
                'getSomeModelList': expected_operations['getSomeModelList'],
                'editSomeModel': expected_operations['editSomeModel'],
            },
            'Model2': {
                'addSomeModel': expected_operations['addSomeModel']
            },
            'Model3': {
                'getSomeModel': expected_operations['getSomeModel'],
                'deleteModel3': expected_operations['deleteModel3']
            },
            None: {
                'deleteNoneModel': expected_operations['deleteNoneModel']
            }
        } == fdm_data['model_operations']
Beispiel #6
0
    def test_simple_object(self):
        self._data = copy.deepcopy(base)

        self.fdm_data = FdmSwaggerParser().parse_spec(self._data)

        expected_operations = {
            'getNetworkObjectList': {
                'method': HTTPMethod.GET,
                'url': '/api/fdm/v2/object/networks',
                'modelName': 'NetworkObject',
                'parameters': {
                    'path': {},
                    'query': {
                        'offset': {
                            'required': False,
                            'type': 'integer'
                        },
                        'limit': {
                            'required': False,
                            'type': 'integer'
                        },
                        'sort': {
                            'required': False,
                            'type': 'string'
                        },
                        'filter': {
                            'required': False,
                            'type': 'string'
                        }
                    }
                },
                'returnMultipleItems': True,
                "tags": ["NetworkObject"]
            },
            'addNetworkObject': {
                'method': HTTPMethod.POST,
                'url': '/api/fdm/v2/object/networks',
                'modelName': 'NetworkObject',
                'parameters': {
                    'path': {},
                    'query': {}
                },
                'returnMultipleItems': False,
                "tags": ["NetworkObject"]
            },
            'getNetworkObject': {
                'method': HTTPMethod.GET,
                'url': '/api/fdm/v2/object/networks/{objId}',
                'modelName': 'NetworkObject',
                'parameters': {
                    'path': {
                        'objId': {
                            'required': True,
                            'type': "string"
                        }
                    },
                    'query': {}
                },
                'returnMultipleItems': False,
                "tags": ["NetworkObject"]
            },
            'editNetworkObject': {
                'method': HTTPMethod.PUT,
                'url': '/api/fdm/v2/object/networks/{objId}',
                'modelName': 'NetworkObject',
                'parameters': {
                    'path': {
                        'objId': {
                            'required': True,
                            'type': "string"
                        }
                    },
                    'query': {}
                },
                'returnMultipleItems': False,
                "tags": ["NetworkObject"]
            },
            'deleteNetworkObject': {
                'method': HTTPMethod.DELETE,
                'url': '/api/fdm/v2/object/networks/{objId}',
                'modelName': 'NetworkObject',
                'parameters': {
                    'path': {
                        'objId': {
                            'required': True,
                            'type': "string"
                        }
                    },
                    'query': {}
                },
                'returnMultipleItems': False,
                "tags": ["NetworkObject"]
            }
        }
        assert sorted(['NetworkObject', 'NetworkObjectWrapper'
                       ]) == sorted(self.fdm_data['models'].keys())
        assert expected_operations == self.fdm_data['operations']
        assert {
            'NetworkObject': expected_operations
        } == self.fdm_data['model_operations']