• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyswagger.SwaggerApp类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyswagger.SwaggerApp的典型用法代码示例。如果您正苦于以下问题:Python SwaggerApp类的具体用法?Python SwaggerApp怎么用?Python SwaggerApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SwaggerApp类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_parameter

    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')
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:32,代码来源:test_upgrade.py


示例2: test_parameter

    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")
开发者ID:pwfff,项目名称:pyswagger,代码行数:29,代码来源:test_upgrade.py


示例3: test_load

    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))
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:15,代码来源:test_yaml.py


示例4: test_v2_0

    def test_v2_0(self):
        """ convert from 2.0 to 2.0 """
        path = get_test_data_folder(version="2.0", which="wordnik")
        app = SwaggerApp.create(path)

        # load swagger.json into dict
        origin = None
        with open(os.path.join(path, "swagger.json")) as r:
            origin = json.loads(r.read())

        # diff for empty list or dict is allowed
        d = app.dump()
        self.assertEqual(
            sorted(_diff_(origin, d, exclude=["$ref"])),
            sorted(
                [
                    ("paths/~1pet~1{petId}/get/security/0/api_key", "list", "NoneType"),
                    ("paths/~1store~1inventory/get/parameters", None, None),
                    ("paths/~1store~1inventory/get/security/0/api_key", "list", "NoneType"),
                    ("paths/~1user~1logout/get/parameters", None, None),
                ]
            ),
        )

        # try to load the dumped dict back, to see if anything wrong
        tmp = {"_tmp_": {}}
        with SwaggerContext(tmp, "_tmp_") as ctx:
            ctx.parse(d)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:28,代码来源:test_conv.py


示例5: test_primfactory

    def test_primfactory(self):
        app = SwaggerApp.create(
            get_test_data_folder(version="2.0", which=os.path.join("circular", "schema")), strict=False
        )

        s = app.resolve("#/definitions/s1")
        self.assertRaises(errs.CycleDetectionError, app.prim_factory.produce, s, {})
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:7,代码来源:test_circular.py


示例6: test_deref

    def test_deref(self):
        app = SwaggerApp.create(
            get_test_data_folder(version="2.0", which=os.path.join("circular", "schema")), strict=False
        )

        s = app.resolve("#/definitions/s1")
        self.assertRaises(errs.CycleDetectionError, utils.deref, s)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:7,代码来源:test_circular.py


示例7: test_schema

    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")],
                ]
            ),
        )
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:32,代码来源:test_circular.py


示例8: test_authorization

    def test_authorization(self):
        """
        """
        app = SwaggerApp.create(get_test_data_folder(
            version='1.2', which='simple_auth')
        )
            
        expect = {
            'type':'apiKey',
            'in':'query',
            'name':'simpleQK'
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_key').dump()
        ), [])

        expect = {
            'type':'apiKey',
            'in':'header',
            'name':'simpleHK'
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_key2').dump()
        ), [])


        expect = {
            'type':'basic',
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_basic').dump()
        ), [])
开发者ID:pwfff,项目名称:pyswagger,代码行数:35,代码来源:test_conv.py


示例9: setUpClass

    def setUpClass(kls):
        kls.app = SwaggerApp.load(get_test_data_folder(
            version='2.0',
            which='bitbucket'
        ))

        # bypass cyclic testing
        kls.app.prepare(strict=False)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:8,代码来源:test_bitbucket.py


示例10: setUpClass

    def setUpClass(kls):
        global folder

        kls.app = SwaggerApp.load(
            url='file:///root/swagger.json',
            url_load_hook=_hook
        )
        kls.app.prepare()
开发者ID:pwfff,项目名称:pyswagger,代码行数:8,代码来源:test_ex.py


示例11: setUpClass

    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))
开发者ID:pwfff,项目名称:pyswagger,代码行数:8,代码来源:test_conv.py


示例12: test_relative_schema

 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()
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:9,代码来源:test_ex.py


示例13: test_item

    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")
开发者ID:pwfff,项目名称:pyswagger,代码行数:18,代码来源:test_upgrade.py


示例14: test_model_inheritance

    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"]), [])
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:9,代码来源:test_conv.py


示例15: test_overwrite

    def test_overwrite(self):
        """ overrite type/format handler used in pyswagger """
        m1 = self.app.resolve("#/definitions/m1")
        v = m1._prim_({"job": "man"}, self.app.prim_factory)
        # should not raise
        self.assertEqual(v.job, "man")

        app = SwaggerApp.create(get_test_data_folder(version="2.0", which=os.path.join("schema", "extension")))
        m1 = app.resolve("#/definitions/m1")
        self.assertRaises(errs.ValidationError, m1._prim_, {"job": "man"}, app.prim_factory)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:10,代码来源:test_prim.py


示例16: test_random_name_v1_2

 def test_random_name_v1_2(self):
     """
     """
     path = get_test_data_folder(
         version='1.2',
         which='random_file_name'
     )
     path = os.path.join(path, 'test_random.json')
     # should not raise ValueError
     app = SwaggerApp.create(path)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:10,代码来源:test_getter.py


示例17: test_no_host_basePath

    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')
开发者ID:pwfff,项目名称:pyswagger,代码行数:41,代码来源:test_core.py


示例18: setUp

    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()
开发者ID:yuce,项目名称:pyswagger,代码行数:12,代码来源:test_app.py


示例19: test_local_path_with_custome_getter

    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)
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:13,代码来源:test_getter.py


示例20: test_token_endpoint

    def test_token_endpoint(self):
        """
        """
        app = SwaggerApp.create(get_test_data_folder(version="1.2", which="simple_auth"))

        expect = {
            "tokenUrl": "http://petstore.swagger.wordnik.com/api/oauth/token",
            "type": "oauth2",
            "flow": "access_code",
            "scopes": {"test:anything": "for testing purpose"},
        }

        self.assertEqual(_diff_(expect, app.resolve("#/securityDefinitions/oauth2").dump()), [])
开发者ID:WangJiannan,项目名称:pyswagger,代码行数:13,代码来源:test_conv.py



注:本文中的pyswagger.SwaggerApp类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Logger.Logger类代码示例发布时间:2022-05-27
下一篇:
Python pyswagger.App类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap