本文整理汇总了Python中pyswagger.SwaggerApp.load方法的典型用法代码示例。如果您正苦于以下问题:Python SwaggerApp.load方法的具体用法?Python SwaggerApp.load怎么用?Python SwaggerApp.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyswagger.SwaggerApp
的用法示例。
在下文中一共展示了SwaggerApp.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_load(self):
""" make sure the result of yaml and json are identical """
app_json = SwaggerApp.load(get_test_data_folder(
version='2.0',
which='wordnik'
))
app_yaml = SwaggerApp.load(get_test_data_folder(
version='2.0',
which='yaml',
)
)
s = Scanner(app_yaml)
s.scan(route=[YamlFixer()], root=app_yaml.raw, leaves=[Operation])
self.assertEqual((True, ''), app_json.raw.compare(app_yaml.raw))
示例2: test_schema
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_schema(self):
folder = get_test_data_folder(version="2.0", which=os.path.join("circular", "schema"))
def _pf(s):
return six.moves.urllib.parse.urlunparse(("file", "", folder, "", "", s))
app = SwaggerApp.load(folder)
app.prepare(strict=False)
s = Scanner(app)
c = CycleDetector()
s.scan(root=app.raw, route=[c])
self.maxDiff = None
self.assertEqual(
sorted(c.cycles["schema"]),
sorted(
[
[_pf("/definitions/s10"), _pf("/definitions/s11"), _pf("/definitions/s9"), _pf("/definitions/s10")],
[_pf("/definitions/s5"), _pf("/definitions/s5")],
[
_pf("/definitions/s1"),
_pf("/definitions/s2"),
_pf("/definitions/s3"),
_pf("/definitions/s4"),
_pf("/definitions/s1"),
],
[_pf("/definitions/s12"), _pf("/definitions/s13"), _pf("/definitions/s12")],
[_pf("/definitions/s6"), _pf("/definitions/s7"), _pf("/definitions/s6")],
[_pf("/definitions/s14"), _pf("/definitions/s15"), _pf("/definitions/s14")],
]
),
)
示例3: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
global folder
kls.app = SwaggerApp.load(
url='file:///root/swagger.json',
url_load_hook=_hook
)
kls.app.prepare()
示例4: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp.load(get_test_data_folder(
version='2.0',
which='bitbucket'
))
# bypass cyclic testing
kls.app.prepare(strict=False)
示例5: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp.load(get_test_data_folder(
version='1.2', which='wordnik'), sep=':'
)
kls.app.prepare()
with open('./test.json', 'w') as r:
r.write(json.dumps(kls.app.dump(), indent=3))
示例6: test_model_inheritance
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_model_inheritance(self):
"""
"""
app = SwaggerApp.load(get_test_data_folder(version="1.2", which="model_subtypes"), sep=":")
app.prepare()
expect = {"allOf": [{"$ref": u"#/definitions/user:User"}]}
self.assertEqual(_diff_(expect, app.resolve("#/definitions/user:UserWithInfo").dump(), include=["allOf"]), [])
示例7: test_relative_schema
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_relative_schema(self):
""" test case for issue#53,
relative file, which root is a Schema Object
"""
app = SwaggerApp.load(
url="file:///relative/internal.yaml",
url_load_hook=_gen_hook(get_test_data_folder(version="2.0", which="ex")),
)
app.prepare()
示例8: setUp
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUp(self):
folder = get_test_data_folder(
version='1.2',
)
def _hook(url):
# a demo of hooking a remote url to local path
p = six.moves.urllib.parse.urlparse(url)
return utils.normalize_url(os.path.join(folder, p.path[1:]))
self.app = SwaggerApp.load('http://petstore.io/wordnik', url_load_hook=_hook)
self.app.prepare()
示例9: test_local_path_with_custome_getter
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_local_path_with_custome_getter(self):
""" make sure path would be assigned when
passing a getter class
"""
cls = UrlGetter
path = get_test_data_folder(
version='2.0',
which='random_file_name'
)
path = os.path.join(path, 'test_random.json')
# should not raise errors
app = SwaggerApp.load(path, getter=cls)
示例10: test_model_inheritance
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_model_inheritance(self):
"""
"""
app = SwaggerApp.load(get_test_data_folder(
version='1.2', which='model_subtypes'
), sep=':')
app.prepare()
expect = {
'allOf': [{'$ref': u'#/definitions/user:User'}]
}
self.assertEqual(_diff_(
expect,
app.resolve('#/definitions/user:UserWithInfo').dump(),
include=['allOf']
), [])
示例11: test_no_host_basePath
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def test_no_host_basePath(self):
""" test case for swagger.json without
'host' and 'basePath' defined
"""
path = get_test_data_folder(
version='2.0',
which=os.path.join('patch', 'no_host_schemes')
)
fu = utils.normalize_url(path) # file uri version of path
# load swagger.json from a file path
app = SwaggerApp.create(path)
req, _ = app.s('t1').get()
self.assertEqual(req.url, path+'/t1')
self.assertEqual(req.schemes, ['file'])
req.prepare(scheme='file', handle_files=False)
self.assertEqual(req.url, fu+'/t1')
# load swagger.json from a file uri
self.assertNotEqual(six.moves.urllib.parse.urlparse(fu).scheme, '')
app = SwaggerApp.create(fu)
req, _ = app.s('t1').get()
self.assertEqual(req.url, path+'/t1')
self.assertEqual(req.schemes, ['file'])
req.prepare(scheme='file', handle_files=False)
self.assertEqual(req.url, fu+'/t1')
# load swagger.json from a remote uri
def _hook(url):
# no matter what url, return the path of local swagger.json
return fu
url = 'test.com/api/v1'
app = SwaggerApp.load('https://'+url, url_load_hook=_hook)
app.prepare()
# try to make a SwaggerRequest and verify its url
req, _ = app.s('t1').get()
self.assertEqual(req.url, url+'/t1')
self.assertEqual(req.schemes, ['https'])
req.prepare(scheme='https', handle_files=False)
self.assertEqual(req.url, 'https://'+url+'/t1')
示例12: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
factory = SwaggerPrimitive()
def decode_int(obj, val, ctx):
# minus 1
return int(val) - 1
def decode_str(obj, val, ctx):
# remove the last char
return str(val)[:-1]
def str_no_validate(obj, val, ctx):
# same as the one used in pyswagger, but no validation
return str(val)
factory.register("encoded_integer", None, decode_int)
factory.register("string", "special_encoded", decode_str)
factory.register("string", None, str_no_validate, _2nd_pass=None)
kls.app = SwaggerApp.load(
get_test_data_folder(version="2.0", which=os.path.join("schema", "extension")), prim=factory
)
kls.app.prepare()
示例13: _authorization
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
@Disp.register([Authorization])
def _authorization(self, path, obj, _):
self.authorization.append(path)
@Disp.register([ResponseMessage])
def _response_message(self, path, obj, _):
if path.startswith('#/apis/store'):
self.response_message.append(path)
@Disp.register([Parameter])
def _parameter(self, path, obj, _):
if path.startswith('#/apis/pet/apis/updatePetWithForm'):
self.parameter.append(path)
app = SwaggerApp.load(get_test_data_folder(version='1.2', which='wordnik'))
class ScannerTestCase(unittest.TestCase):
""" test scanner """
def test_count(self):
s = Scanner(app)
co = CountObject()
s.scan(route=[co], root=app.raw)
self.assertEqual(co.long_name, 'createUsersWithArrayInput')
self.assertEqual(co.total, {
Authorization: 1,
Resource: 3,
Operation: 20
})
示例14: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp.load(get_test_data_folder(version="1.2", which="wordnik"), sep=":")
kls.app.prepare()
with open("./test.json", "w") as r:
r.write(json.dumps(kls.app.dump(), indent=3))
示例15: setUpClass
# 需要导入模块: from pyswagger import SwaggerApp [as 别名]
# 或者: from pyswagger.SwaggerApp import load [as 别名]
def setUpClass(kls):
kls.app = SwaggerApp.load(
url="file:///root/swagger.json", url_load_hook=_gen_hook(get_test_data_folder(version="2.0", which="ex"))
)
kls.app.prepare()