def test_model_deepcopy(self): parent = Model('Person', { 'name': fields.String, 'age': fields.Integer(description="foo"), }) child = parent.inherit('Child', { 'extra': fields.String, }) parent_copy = copy.deepcopy(parent) assert parent_copy["age"].description == "foo" parent_copy["age"].description = "bar" assert parent["age"].description == "foo" assert parent_copy["age"].description == "bar" child = parent.inherit('Child', { 'extra': fields.String, }) child_copy = copy.deepcopy(child) assert child_copy.__parents__[0] == parent
def test_polymorph_inherit_common_ancestor(self): class Child1: pass class Child2: pass parent = Model('Person', { 'name': fields.String, 'age': fields.Integer, }) child1 = parent.inherit('Child1', { 'extra1': fields.String, }) child2 = parent.inherit('Child2', { 'extra2': fields.String, }) mapping = { Child1: child1, Child2: child2, } output = Model('Output', { 'child': fields.Polymorph(mapping) }) # Should use the common ancestor self.assertEqual(output.__schema__, { 'properties': { 'child': {'$ref': '#/definitions/Person'}, } })
def test_model_deepcopy(self): parent = Model('Person', { 'name': fields.String, 'age': fields.Integer(description="foo"), }) child = parent.inherit('Child', { 'extra': fields.String, }) parent_copy = copy.deepcopy(parent) self.assertEqual(parent_copy["age"].description, "foo") parent_copy["age"].description = "bar" self.assertEqual(parent["age"].description, "foo") self.assertEqual(parent_copy["age"].description, "bar") child = parent.inherit('Child', { 'extra': fields.String, }) child_copy = copy.deepcopy(child) self.assertEqual(child_copy.__parents__[0], parent)
def test_inherit_from_class_from_multiple_parents(self): grand_parent = Model('GrandParent', { 'grand_parent': fields.String, }) parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = Model.inherit('Child', grand_parent, parent, { 'extra': fields.String, }) self.assertEqual(child.__schema__, { 'allOf': [ {'$ref': '#/definitions/GrandParent'}, {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} } } ] })
def test_inherit_from_instance(self): parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = parent.inherit('Child', { 'extra': fields.String, }) self.assertEqual(parent.__schema__, { 'properties': { 'name': {'type': 'string'}, 'age': {'type': 'integer'}, }, 'type': 'object' }) self.assertEqual(child.__schema__, { 'allOf': [ {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} }, 'type': 'object' } ] })
def test_inherit_from_class(self): parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = Model.inherit('Child', parent, { 'extra': fields.String, }) self.assertEqual(parent.__schema__, { 'properties': { 'name': {'type': 'string'}, 'age': {'type': 'integer'}, }, 'type': 'object' }) self.assertEqual(child.__schema__, { 'allOf': [ {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} }, 'type': 'object' } ] })
def test_inherit_from_instance(self): parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = parent.inherit('Child', { 'extra': fields.String, }) assert parent.__schema__ == { 'properties': { 'name': { 'type': 'string' }, 'age': { 'type': 'integer' }, }, 'type': 'object' } assert child.__schema__ == { 'allOf': [{ '$ref': '#/definitions/Parent' }, { 'properties': { 'extra': { 'type': 'string' } }, 'type': 'object' }] }
def test_inherit_from_instance_from_multiple_parents(self): grand_parent = Model('GrandParent', { 'grand_parent': fields.String, }) parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = grand_parent.inherit('Child', parent, { 'extra': fields.String, }) assert child.__schema__ == { 'allOf': [ {'$ref': '#/definitions/GrandParent'}, {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} }, 'type': 'object' } ] }
def test_inherit_from_class(self): parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = Model.inherit('Child', parent, { 'extra': fields.String, }) assert parent.__schema__ == { 'properties': { 'name': {'type': 'string'}, 'age': {'type': 'integer'}, }, 'type': 'object' } assert child.__schema__ == { 'allOf': [ {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} }, 'type': 'object' } ] }
def test_inherit_from_instance_from_multiple_parents(self): grand_parent = Model('GrandParent', { 'grand_parent': fields.String, }) parent = Model('Parent', { 'name': fields.String, 'age': fields.Integer, }) child = grand_parent.inherit('Child', parent, { 'extra': fields.String, }) self.assertEqual(child.__schema__, { 'allOf': [ {'$ref': '#/definitions/GrandParent'}, {'$ref': '#/definitions/Parent'}, { 'properties': { 'extra': {'type': 'string'} }, 'type': 'object' } ] })
funct_uid = Model("VNF", { 'id': fields.String(required=True, description='The VNF UID'), 'name': fields.String(required=True, description='The VNF Name'), 'vendor': fields.String(required=True, description='The VNF Vendor'), 'version': fields.String(required=True, description='The VNF Version') }) uid = Model("VNF_UID", { 'id': fields.String(required=True, description='The VNF UID') }) funct_response = funct.inherit("FunctionResponse", funct, { "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"), "id": fields.Integer(description='The Project ID'), "project_id": fields.Integer(description='The parent project id'), }) message_response = proj_namespace.model("Message", { 'message': fields.String(required=True, description="The result message") }) proj_namespace.add_model(funct.name, funct) proj_namespace.add_model(funct_response.name, funct_response) @proj_namespace.route('/') @cata_namespace.route('/') @plat_namespace.route('/') @proj_namespace.param('ws_id', 'The Workspace identifier')
'run_uuid': fields.String(required=True, description='UUID of run'), 'pipeline_uuid': fields.String(required=True, description='UUID of pipeline'), 'status': fields.String(required=True, description='Status of the run'), 'pipeline_steps': fields.List( # TODO: rename fields.Nested(pipeline_run_pipeline_step), description='Status of each pipeline step'), }) interactive_run_config = pipeline_run_config.inherit( 'InteractiveRunConfig', { 'pipeline-dir': fields.String( required=True, description='Absolute path on the host to the "pipeline-dir"'), }) interactive_run_spec = pipeline_run_spec.inherit( 'InteractiveRunSpec', { 'pipeline_description': fields.Raw(required=True, description='Pipeline description in JSON'), 'run_config': fields.Nested(interactive_run_config, required=True, description='Configuration for compute backend'), }) interactive_run = pipeline_run.inherit('InteractiveRun', {})
'id': fields.Integer(), 'host_identifier': fields.String(), 'os_info': fields.Raw(), 'node_info': fields.Nested(node_info_wrapper, default=None), 'arch': fields.String(), 'network_info': fields.Raw(), 'last_checkin': fields.DateTime(default=None), 'enrolled_on': fields.DateTime(default=None), }) nodebyid_data = Model('node_by_id_data', { 'name': fields.String(), 'path': fields.String(), 'status': fields.String() }) system_data_wrapper = Model( 'system_data', { 'name': fields.String(), 'data': fields.Nested(nodebyid_data), 'updated_at': fields.DateTime() }) nodebyid_wrapper = nodewrapper.inherit( 'node_by_id', {'system_data': fields.Nested(system_data_wrapper)}) node_tag_wrapper = Model('node_tag_wrapper', { 'host_identifier': fields.String(), 'node_key': fields.String() })
} relationships_model = Model('Relationships', relationships_field) """ entity_field = { 'type': fields.String(example='Zone_Temperature_Sensor'), 'relationships': fields.List(fields.List(fields.String), example=[['bf:hasLocation', 'room_1']]), 'name': fields.String(example='ZNT101'), 'entity_id': fields.String(example='b0d8a253-0c6d-4491-b2be-faa965cd72ec'), } """ #entity_model = Model('Entity', entity_field) entity_model = relationships_model.inherit( 'Entity', { 'type': fields.String(example='Zone_Temperature_Sensor'), 'name': fields.String(example='ZNT101'), 'entity_id': fields.String(example='b0d8a253-0c6d-4491-b2be-faa965cd72ec'), }) entities_model = Model('Entities', {'entities': fields.List(fields.Nested(entity_model))}) entity_api.models[relationships_model.name] = relationships_model entity_api.models[entity_model.name] = entity_model entity_api.models[entities_model.name] = entities_model reqparser = reqparse.RequestParser() reqparser.add_argument( 'Content-Type', type=str, location='headers',
fields.String(required=True, description="UUID of run"), "project_uuid": fields.String(required=True, description="UUID of project"), "pipeline_uuid": fields.String(required=True, description="UUID of pipeline"), "status": fields.String(required=True, description="Status of the run"), "pipeline_steps": fields.List( # TODO: rename fields.Nested(pipeline_run_pipeline_step), description="Status of each pipeline step", ), }, ) interactive_run_config = pipeline_run_config.inherit("InteractiveRunConfig", {}) interactive_run_spec = pipeline_run_spec.inherit( "InteractiveRunSpec", { "pipeline_description": fields.Raw(required=True, description="Pipeline description in JSON"), "run_config": fields.Nested( interactive_run_config, required=True, description="Configuration for compute backend", ), }, )
'version': fields.String(required=True, description='The Service Version') }) serv_update = Model("Service Update", { "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor") }) serv_id = Model("Service ID", { 'id': fields.Integer(required=True, description='The son-editor id of the service being published') }) serv_response = serv.inherit("ServiceResponse", serv, { "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor"), "id": fields.Integer(description='The Project ID'), "project_id": fields.Integer(description='The parent workspace id'), }) message_response = proj_namespace.model("Message", { 'message': fields.String(required=True, description="The result message") }) proj_namespace.add_model(serv_update.name, serv_update) proj_namespace.add_model(serv.name, serv) proj_namespace.add_model(serv_response.name, serv_response) @proj_namespace.route('/') @cata_namespace.route('/') @plat_namespace.route('/')
'version': fields.String(required=True, description='The Service Version') }) serv_update = Model( "Service Update", { "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor") }) serv_response = serv.inherit( "ServiceResponse", serv, { "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor"), "id": fields.Integer(description='The Project ID'), "project_id": fields.Integer(description='The parent workspace id'), }) message_response = namespace.model("Message", { 'message': fields.String(required=True, description="The result message") }) namespace.add_model(serv_update.name, serv_update) namespace.add_model(serv.name, serv) namespace.add_model(serv_response.name, serv_response)
funct_uid = Model( "VNF", { 'id': fields.String(required=True, description='The VNF UID'), 'name': fields.String(required=True, description='The VNF Name'), 'vendor': fields.String(required=True, description='The VNF Vendor'), 'version': fields.String(required=True, description='The VNF Version') }) uid = Model("VNF_UID", {'id': fields.String(required=True, description='The VNF UID')}) funct_response = funct.inherit( "FunctionResponse", funct, { "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"), "id": fields.Integer(description='The Project ID'), "project_id": fields.Integer(description='The parent project id'), }) message_response = proj_namespace.model("Message", { 'message': fields.String(required=True, description="The result message") }) proj_namespace.add_model(funct.name, funct) proj_namespace.add_model(funct_response.name, funct_response) @proj_namespace.route('/')