本文整理汇总了Python中flask_restplus.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inherit_from_instance
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'
}
]
}
示例2: test_extend_is_deprecated
def test_extend_is_deprecated(self):
parent = Model('Parent', {
'name': fields.String,
'age': fields.Integer,
'birthdate': fields.DateTime,
})
with pytest.warns(DeprecationWarning):
child = parent.extend('Child', {
'extra': fields.String,
})
assert child.__schema__ == {
'properties': {
'name': {
'type': 'string'
},
'age': {
'type': 'integer'
},
'birthdate': {
'type': 'string',
'format': 'date-time'
},
'extra': {
'type': 'string'
}
},
'type': 'object'
}
示例3: test_inherit_from_instance_from_multiple_parents
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'
}
]
}
示例4: test_clone_from_instance
def test_clone_from_instance(self):
parent = Model('Parent', {
'name': fields.String,
'age': fields.Integer,
'birthdate': fields.DateTime,
})
child = parent.clone('Child', {
'extra': fields.String,
})
assert child.__schema__ == {
'properties': {
'name': {
'type': 'string'
},
'age': {
'type': 'integer'
},
'birthdate': {
'type': 'string',
'format': 'date-time'
},
'extra': {
'type': 'string'
}
},
'type': 'object'
}
示例5: test_polymorph_inherit_common_ancestor
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'},
}
})
示例6: test_model_deepcopy
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
示例7: test_clone_from_instance_with_multiple_parents
def test_clone_from_instance_with_multiple_parents(self):
grand_parent = Model('GrandParent', {
'grand_parent': fields.String,
})
parent = Model('Parent', {
'name': fields.String,
'age': fields.Integer,
'birthdate': fields.DateTime,
})
child = grand_parent.clone('Child', parent, {
'extra': fields.String,
})
self.assertEqual(child.__schema__, {
'properties': {
'grand_parent': {
'type': 'string'
},
'name': {
'type': 'string'
},
'age': {
'type': 'integer'
},
'birthdate': {
'type': 'string',
'format': 'date-time'
},
'extra': {
'type': 'string'
}
}
})
示例8: test_inherit_from_class
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'
}
]
})
示例9: test_clone_from_class
def test_clone_from_class(self):
parent = Model('Parent', {
'name': fields.String,
'age': fields.Integer,
'birthdate': fields.DateTime,
})
child = Model.clone('Child', parent, {
'extra': fields.String,
})
self.assertEqual(child.__schema__, {
'properties': {
'name': {
'type': 'string'
},
'age': {
'type': 'integer'
},
'birthdate': {
'type': 'string',
'format': 'date-time'
},
'extra': {
'type': 'string'
}
},
'type': 'object'
})
示例10: test_inherit_from_class_from_multiple_parents
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'}
}
}
]
})
示例11: test_validate
def test_validate(self):
from jsonschema import FormatChecker
from werkzeug.exceptions import BadRequest
class IPAddress(fields.Raw):
__schema_type__ = 'string'
__schema_format__ = 'ipv4'
data = {'ip': '192.168.1'}
model = Model('MyModel', {'ip': IPAddress()})
# Test that validate without a FormatChecker does not check if a
# primitive type conforms to the defined format property
assert model.validate(data) is None
# Test that validate with a FormatChecker enforces the check of the
# format property and throws an error if invalid
with pytest.raises(BadRequest):
model.validate(data, format_checker=FormatChecker())
示例12: test_clone_from_class_with_multiple_parents
def test_clone_from_class_with_multiple_parents(self):
grand_parent = Model('GrandParent', {
'grand_parent': fields.String,
})
parent = Model('Parent', {
'name': fields.String,
'age': fields.Integer,
'birthdate': fields.DateTime,
})
child = Model.clone('Child', grand_parent, parent, {
'extra': fields.String,
})
assert child.__schema__ == {
'properties': {
'grand_parent': {
'type': 'string'
},
'name': {
'type': 'string'
},
'age': {
'type': 'integer'
},
'birthdate': {
'type': 'string',
'format': 'date-time'
},
'extra': {
'type': 'string'
}
},
'type': 'object'
}
示例13: Namespace
from son_editor.app.exceptions import InvalidArgument
from son_editor.impl import functionsimpl, catalogue_servicesimpl
from son_editor.impl.private_catalogue_impl import publish_private_nsfs
from son_editor.util.constants import get_parent, Category, WORKSPACES, PROJECTS, CATALOGUES, PLATFORMS, VNFS
from son_editor.util.requestutil import prepare_response, get_json
proj_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PROJECTS + "/<int:parent_id>/" + VNFS,
description="Project VNF Resources")
cata_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + CATALOGUES + "/<int:parent_id>/" + VNFS,
description="Catalogue VNF Resources")
plat_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PLATFORMS + "/<int:parent_id>/" + VNFS,
description="Platform VNF Resources")
funct = Model("VNF", {
'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')
})
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')
})
示例14: Namespace
from son_editor.util.constants import get_parent, Category, WORKSPACES, PROJECTS, CATALOGUES, PLATFORMS, SERVICES
from son_editor.util.requestutil import prepare_response, get_json
logger = logging.getLogger(__name__)
proj_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PROJECTS + "/<int:parent_id>/" + SERVICES,
description="Project Service Resources")
cata_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + CATALOGUES + "/<int:parent_id>/" + SERVICES,
description="Catalogue Service Resources")
plat_namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PLATFORMS + "/<int:parent_id>/" + SERVICES,
description="Platform Service Resources")
serv = Model("Service", {
'name': fields.String(required=True, description='The Service Name'),
'vendor': fields.String(required=True, description='The Service Vendor'),
'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'),
示例15: Model
API Models and DAOs for models not accessible through API
"""
from flask_restplus import Model
import custom_fields as fields
from app.helpers.data import update_or_create
from app.models.custom_forms import CustomForms
from utils import ServiceDAO
# #############
# DEFINE MODELS
# #############
CUSTOM_FORM = Model('CustomForm', {
'id': fields.Integer(),
'speaker_form': fields.String(),
'session_form': fields.String()
})
CUSTOM_FORM_POST = CUSTOM_FORM.clone('CustomFormPost')
del CUSTOM_FORM_POST['id']
# ##########
# DEFINE DAO
# ##########
class CFDAO(ServiceDAO):
def create(self, event_id, data, url):
data = self.validate(data)