本文整理汇总了Python中pyswagger.SwaggerApp._create_方法的典型用法代码示例。如果您正苦于以下问题:Python SwaggerApp._create_方法的具体用法?Python SwaggerApp._create_怎么用?Python SwaggerApp._create_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyswagger.SwaggerApp
的用法示例。
在下文中一共展示了SwaggerApp._create_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parameter
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_parameter(self):
""" Parameter -> Parameter
"""
# body
o = self.app.root.paths['/api/pet/{petId}'].patch
p = [p for p in o.parameters if getattr(p, 'in') == 'body'][0]
self.assertEqual(getattr(p, 'in'), 'body')
self.assertEqual(p.required, True)
self.assertEqual(getattr(p.schema, '$ref'), _pf('/definitions/pet!##!Pet'))
# form
o = self.app.root.paths['/api/pet/uploadImage'].post
p = [p for p in o.parameters if getattr(p, 'in') == 'formData' and p.type == 'string'][0]
self.assertEqual(p.name, 'additionalMetadata')
self.assertEqual(p.required, False)
# file
o = self.app.root.paths['/api/pet/uploadImage'].post
p = [p for p in o.parameters if getattr(p, 'in') == 'formData' and p.type == 'file'][0]
self.assertEqual(p.name, 'file')
self.assertEqual(p.required, False)
# non-body can't have $ref
try:
SwaggerApp._create_(get_test_data_folder(
version='1.2',
which='upgrade_parameter'
))
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ("Can't have $ref in non-body Parameters",))
else:
self.fail('SchemaError not raised')
示例2: test_parameter
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_parameter(self):
""" Parameter -> Parameter
"""
# body
o = self.app.root.paths["/api/pet/{petId}"].patch
p = [p for p in o.parameters if getattr(p, "in") == "body"][0]
self.assertEqual(getattr(p, "in"), "body")
self.assertEqual(p.required, True)
self.assertEqual(getattr(p.schema, "norm_ref"), _pf("/definitions/pet!##!Pet"))
# form
o = self.app.root.paths["/api/pet/uploadImage"].post
p = [p for p in o.parameters if getattr(p, "in") == "formData" and p.type == "string"][0]
self.assertEqual(p.name, "additionalMetadata")
self.assertEqual(p.required, False)
# file
o = self.app.root.paths["/api/pet/uploadImage"].post
p = [p for p in o.parameters if getattr(p, "in") == "formData" and p.type == "file"][0]
self.assertEqual(p.name, "file")
self.assertEqual(p.required, False)
# non-body can't have $ref
try:
SwaggerApp._create_(get_test_data_folder(version="1.2", which="upgrade_parameter"))
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ("Can't have $ref in non-body Parameters",))
else:
self.fail("SchemaError not raised")
示例3: test_item
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_item(self):
""" make sure to raise exception for invalid item
"""
try:
SwaggerApp._create_(get_test_data_folder(version="1.2", which=os.path.join("upgrade_items", "with_ref")))
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ("Can't have $ref for Items",))
else:
self.fail("SchemaError not raised")
try:
SwaggerApp._create_(
get_test_data_folder(version="1.2", which=os.path.join("upgrade_items", "invalid_primitive"))
)
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ("Non primitive type is not allowed for Items",))
else:
self.fail("SchemaError not raised")
示例4: test_item
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_item(self):
""" make sure to raise exception for invalid item
"""
try:
SwaggerApp._create_(get_test_data_folder(
version='1.2',
which=os.path.join('upgrade_items', 'with_ref')
))
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ('Can\'t have $ref for Items',))
else:
self.fail('SchemaError not raised')
try:
SwaggerApp._create_(get_test_data_folder(
version='1.2',
which=os.path.join('upgrade_items', 'invalid_primitive')
))
except errs.SchemaError as e:
self.failUnlessEqual(e.args, ('Non primitive type is not allowed for Items',))
else:
self.fail('SchemaError not raised')
示例5: test_auto_schemes
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_auto_schemes(self):
""" make sure we scheme of url to access
swagger.json as default scheme
"""
# load swagger.json
data = None
with open(os.path.join(get_test_data_folder(
version='2.0',
which=os.path.join('schema', 'model')
), 'swagger.json')) as f:
data = f.read()
httpretty.register_uri(
httpretty.GET,
'http://test.com/api-doc/swagger.json',
body=data
)
app = SwaggerApp._create_('http://test.com/api-doc/swagger.json')
self.assertEqual(app.schemes, ['http'])
示例6: RequestsClient_Pet_TestCase
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
from __future__ import absolute_import
from pyswagger import SwaggerApp
from pyswagger.contrib.client.requests import Client
from ...utils import get_test_data_folder
from ....primitives import Model, Array
import unittest
import httpretty
import json
import six
app = SwaggerApp._create_(get_test_data_folder(version="1.2", which="wordnik"))
client = Client()
pet_Tom = dict(id=1, name="Tom", tags=[dict(id=0, name="available"), dict(id=1, name="sold")])
pet_Qoo = dict(id=2, name="Qoo", tags=[dict(id=0, name="available")])
pet_Sue = dict(id=3, name="Sue", tags=[dict(id=0, name="available")])
pet_Kay = dict(id=4, name="Kay", category=dict(id=2, name="cat"), status="available", photoUrls=None, tags=None)
pet_QQQ = dict(id=1, name="QQQ", category=dict(id=1, name="dog"), tags=None, status=None)
@httpretty.activate
class RequestsClient_Pet_TestCase(unittest.TestCase):
""" test SwaggerClient implemented by requests """
def test_updatePet(self):
""" Pet.updatePet """
httpretty.register_uri(httpretty.PUT, "http://petstore.swagger.wordnik.com/api/pet", status=200)
resp = client.request(app.op["updatePet"](body=pet_QQQ))
示例7: setUp
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUp(self):
self.app = SwaggerApp._create_(get_test_data_folder(version='1.2', which='err'))
示例8: ModelInteritanceTestCase
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
from pyswagger import SwaggerApp
from pyswagger.contrib.client.requests import Client
from pyswagger.primitives import Model
from ..utils import get_test_data_folder
import unittest
import httpretty
import json
import pytest
import sys
app = SwaggerApp._create_(get_test_data_folder(version='1.2', which='model_subtypes'))
client = Client()
u_mission = dict(id=1, username='mission', password='123123')
uwi_mary = dict(id=2, username='mary', password='456456', email='[email protected]', phone='123')
uwi_kevin = dict(id=3, username='kevin')
@pytest.mark.skipif(sys.version_info[:2] >= (3, 3), reason='httpretty corrupt in python3')
class ModelInteritanceTestCase(unittest.TestCase):
""" test cases for model inheritance """
@httpretty.activate
def test_inheritantce_full(self):
""" init a Model with every property along
the inheritance path.
"""
httpretty.register_uri(
httpretty.GET, 'http://petstore.swagger.wordnik.com/api/user/mary',
status=200,
示例9: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(get_test_data_folder(version='1.2', which='model_subtypes'))
示例10: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(
get_test_data_folder(version="2.0", which=os.path.join("schema", "additionalProperties"))
)
示例11: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(get_test_data_folder(version='2.0', which=os.path.join('schema', 'additionalProperties')))
示例12: test_http_getter
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def test_http_getter(self):
""" make sure HTTPGetter works """
folder = get_test_data_folder(version='1.2', which='wordnik')
resource_list = user = pet = store = None
with open(os.path.join(folder, 'resource_list.json')) as f:
resource_list = f.read()
with open(os.path.join(folder, 'user.json')) as f:
user = f.read()
with open(os.path.join(folder, 'pet.json')) as f:
pet = f.read()
with open(os.path.join(folder, 'store.json')) as f:
store = f.read()
httpretty.register_uri(
httpretty.GET, 'http://petstore.swagger.wordnik.com/api/api-docs',
status=200,
body=resource_list
)
httpretty.register_uri(
httpretty.GET, 'http://petstore.swagger.wordnik.com/api/api-docs/user',
status=200,
body=user
)
httpretty.register_uri(
httpretty.GET, 'http://petstore.swagger.wordnik.com/api/api-docs/pet',
status=200,
body=pet
)
httpretty.register_uri(
httpretty.GET, 'http://petstore.swagger.wordnik.com/api/api-docs/store',
status=200,
body=store
)
local_app = SwaggerApp._create_('http://petstore.swagger.wordnik.com/api/api-docs')
self.assertEqual(sorted(local_app.raw._field_names_), sorted(['info', 'authorizations', 'apiVersion', 'swaggerVersion', 'apis']))
op = local_app.raw.apis['pet'].apis['updatePet']
self.assertEqual(sorted(op._field_names_), sorted([
'authorizations',
'consumes',
'defaultValue',
'deprecated',
'enum',
'format',
'items',
'maximum',
'method',
'minimum',
'nickname',
'parameters',
'produces',
'$ref',
'responseMessages',
'type',
'uniqueItems',
'summary',
'notes'
]))
示例13: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(get_test_data_folder(version="1.2", which="model_subtypes"))
示例14: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(get_test_data_folder(
version='2.0',
which='patch'
))
示例15: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import _create_ [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp._create_(get_test_data_folder(
version='2.0',
which=os.path.join('resolve', 'deref')
))