def test_clone_with_multiple_parents(self): api = Namespace('test') grand_parent = api.model('GrandParent', {}) parent = api.model('Parent', {}) api.clone('Child', grand_parent, parent, {}) assert 'Child' in api.models assert 'Parent' in api.models assert 'GrandParent' in api.models
def test_inherit_from_multiple_parents(self): api = Namespace('test') grand_parent = api.model('GrandParent', {}) parent = api.model('Parent', {}) api.inherit('Child', grand_parent, parent, {}) assert 'GrandParent' in api.models assert 'Parent' in api.models assert 'Child' in api.models
def test_inherit(self): api = Namespace('test') parent = api.model('Parent', {}) api.inherit('Child', parent, {}) assert 'Parent' in api.models assert 'Child' in api.models
def test_api_payload(self, app, client): api = Api(app, validate=True) ns = Namespace('apples') api.add_namespace(ns) f = ns.model( 'Person', { 'name': fields.String(required=True), 'age': fields.Integer, 'birthdate': fields.DateTime, }) @ns.route('/validation/') class Payload(Resource): payload = None @ns.expect(f) async def post(self, request): Payload.payload = ns.payload return {} data = { 'name': 'John Doe', 'age': 15, } client.post_json('/apples/validation/', data) assert Payload.payload == data
def test_inherit(self): authorizations = { 'apikey': { 'type': 'apiKey', 'in': 'header', 'name': 'X-API-KEY' } } api = Namespace('test', authorizations=authorizations) parent = api.model('Parent', {}) api.inherit('Child', parent, {}) assert 'Parent' in api.models assert 'Child' in api.models assert api.authorizations == authorizations
from sanic_restplus import Namespace, Resource, fields from sanic.exceptions import SanicException, InvalidUsage api = Namespace('cats', description='Cats related operations') cat = api.model('Cat', { 'id': fields.String(required=True, description='The cat identifier'), 'name': fields.String(required=True, description='The cat name'), }) CATS = [ {'id': 'felix', 'name': 'Felix'}, ] @api.route('/') class CatList(Resource): @api.doc('list_cats') @api.marshal_list_with(cat) def get(self, request): '''List all cats''' return CATS @api.route('/<id>') @api.param('id', 'The cat identifier') @api.response(404, 'Cat not found') class Cat(Resource): @api.doc('get_cat') @api.marshal_with(cat) def get(self, request, id):
def test_model(self): api = Namespace('test') api.model('Person', {}) assert 'Person' in api.models
from sanic_restplus import Namespace, Resource, fields api = Namespace('dogs', description='Dogs related operations') dog = api.model('Dog', { 'id': fields.String(required=True, description='The dog identifier'), 'name': fields.String(required=True, description='The dog name'), }) DOGS = [ {'id': 'medor', 'name': 'Medor'}, ] @api.route('/') class DogList(Resource): @api.doc('list_dogs') @api.marshal_list_with(dog) def get(self, request): '''List all dogs''' return DOGS @api.route('/<id>') @api.param('id', 'The dog identifier') @api.response(404, 'Dog not found') class Dog(Resource): @api.doc('get_dog') @api.marshal_with(dog) def get(self, request, id): '''Fetch a dog given its identifier'''
def test_ordered_model(self): api = Namespace('test', ordered=True) api.model('Person', {}) assert 'Person' in api.models assert isinstance(api.models['Person'], OrderedModel)
def test_model(self): api = Namespace('test') api.model('Person', {}) assert 'Person' in api.models assert isinstance(api.models['Person'], Model)