当前位置: 首页>>代码示例>>Python>>正文


Python App.create方法代码示例

本文整理汇总了Python中pyswagger.App.create方法的典型用法代码示例。如果您正苦于以下问题:Python App.create方法的具体用法?Python App.create怎么用?Python App.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyswagger.App的用法示例。


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

示例1: test_authorization

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_authorization(self):
        """
        """
        app = App.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:mission-liao,项目名称:pyswagger,代码行数:37,代码来源:test_conv.py

示例2: test_float_dump

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_float_dump(self):
        """ failed to dump an object with float property

        refer to issue: https://github.com/mission-liao/pyswagger/issues/92
        """
        app = App.create(get_test_data_folder(version='2.0', which=os.path.join('schema', 'floatDump')))
        app.dump() # should not raise exception
开发者ID:mission-liao,项目名称:pyswagger,代码行数:9,代码来源:test_prim.py

示例3: test_random_name_v1_2

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
 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 = App.create(path)
开发者ID:mission-liao,项目名称:pyswagger,代码行数:12,代码来源:test_getter.py

示例4: test_primfactory

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_primfactory(self):
        app = App.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:mission-liao,项目名称:pyswagger,代码行数:12,代码来源:test_circular.py

示例5: test_deref

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_deref(self):
        app = App.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:mission-liao,项目名称:pyswagger,代码行数:12,代码来源:test_circular.py

示例6: test_no_host_basePath

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [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 = App.create(path)
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//localhost/t1')
        self.assertEqual(req.schemes, ['file'])
        req.prepare(scheme='file', handle_files=False)
        self.assertEqual(req.url, 'file://localhost/t1')

        # load swagger.json from a file uri
        self.assertNotEqual(six.moves.urllib.parse.urlparse(fu).scheme, '')
        app = App.create(fu)
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//localhost/t1')
        self.assertEqual(req.schemes, ['file'])
        req.prepare(scheme='file', handle_files=False)
        self.assertEqual(req.url, 'file://localhost/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 = App.load('https://'+url, url_load_hook=_hook)
        app.prepare()
        # try to make a Request and verify its url
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//test.com/t1')
        self.assertEqual(req.schemes, ['https'])
        req.prepare(scheme='https', handle_files=False)
        self.assertEqual(req.url, 'https://test.com/t1')
开发者ID:mission-liao,项目名称:pyswagger,代码行数:43,代码来源:test_core.py

示例7: test_dict_getter_v2_0

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_dict_getter_v2_0(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 2.0
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(
            version='2.0',
            which='wordnik'
        )

        origin_app = App.create(path)

        with open(os.path.join(path, 'swagger.json'), 'r') as f:
            spec = json.loads(f.read())

        getter = DictGetter([path], {
            os.path.join(path, 'swagger.json'): spec
        })
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump())), [])

        #
        # loading via wrong path, should be ok when all internal $ref are not absoluted
        #
        getter = DictGetter([''], {
            '': spec
        })
        app = App.load('', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])), [])

        #
        # faking http path
        #
        getter = DictGetter(['https://petstore.com'], {
            'https://petstore.com': spec
        })
        app = App.load('https://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])), [])
开发者ID:mission-liao,项目名称:pyswagger,代码行数:52,代码来源:test_getter.py

示例8: test_overwrite

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    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 = App.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:mission-liao,项目名称:pyswagger,代码行数:17,代码来源:test_prim.py

示例9: test_cookie

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_cookie(self):
        global cookie_cache

        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('io', 'cookie')
        ))
        client = Webapp2TestClient(cookie_app, keep_cookie=True)
        resp = client.request(app.op['get_cookie']())
        self.assertEqual(resp.status, 200)

        resp = client.request(app.op['keep_cookie']())
        self.assertEqual(resp.status, 200)

        self.assertEqual(cookie_cache, 'test 123')
开发者ID:mission-liao,项目名称:pyswagger,代码行数:17,代码来源:test_webapp2.py

示例10: test_load_from_url_without_file

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_load_from_url_without_file(self):
        """ try to load from a url withou swagger.json """
        data = None
        with open(os.path.join(get_test_data_folder(
            version='2.0',
            which='wordnik'), 'swagger.json')) as f:
            data = f.read()

        httpretty.register_uri(
            httpretty.GET,
            'http://10.0.0.10:8080/swaggerapi/api/v1beta2',
            body=data
        )

        # no exception should be raised
        app = App.create('http://10.0.0.10:8080/swaggerapi/api/v1beta2')
        self.assertTrue(app.schemes, ['http'])
        self.assertTrue(isinstance(app.root, BaseObj))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:20,代码来源:test_core.py

示例11: test_token_endpoint

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_token_endpoint(self):
        """
        """
        app = App.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:mission-liao,项目名称:pyswagger,代码行数:22,代码来源:test_conv.py

示例12: test_path_item

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_path_item(self):
        folder = utils.normalize_url(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'path_item')
        ))

        def _pf(s):
            return folder + '#' + s

        app = App.create(folder)
        s = Scanner(app)
        c = CycleDetector()
        s.scan(root=app.raw, route=[c])
        self.assertEqual(sorted(c.cycles['path_item']), sorted([[
            _pf('/paths/~1p1'),
            _pf('/paths/~1p2'),
            _pf('/paths/~1p3'),
            _pf('/paths/~1p4'),
            _pf('/paths/~1p1')
        ]]))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:22,代码来源:test_circular.py

示例13: test_v2_0

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_v2_0(self):
        """ convert from 2.0 to 2.0 """
        path = get_test_data_folder(version='2.0', which='wordnik')
        app = App.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:mission-liao,项目名称:pyswagger,代码行数:25,代码来源:test_conv.py

示例14: test_create

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
 def test_create(self):
     """ make sure we could load a yml with status-code in int """
     app = App.create(get_test_data_folder(
         version='2.0',
         which='yaml'
     ))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:8,代码来源:test_yaml.py

示例15: test_dict_getter_v1_2

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import create [as 别名]
    def test_dict_getter_v1_2(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 1.2
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(
            version='1.2',
            which='wordnik'
        )

        path_resource_list = os.path.join(path, 'resource_list.json')
        path_pet = os.path.join(path, 'pet.json')
        path_store = os.path.join(path, 'store.json')
        path_user = os.path.join(path, 'user.json')
        with open(path_resource_list, 'r') as f:
            resource_list = json.loads(f.read())
        with open(path_pet, 'r') as f:
            pet = json.loads(f.read())
        with open(path_store, 'r') as f:
            store = json.loads(f.read())
        with open(path_user, 'r') as f:
            user = json.loads(f.read())

        getter = DictGetter([
            path_resource_list,
            path_pet,
            path_user,
            path_store,
        ], {
            path_resource_list: resource_list,
            path_pet: pet,
            path_store: store,
            path_user: user,
        })
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump())), [])

        #
        # different path, mocking an url
        #
        getter = DictGetter([
            'http://petstore.com',
            'http://petstore.com/pet.json',
            'http://petstore.com/user.json',
            'http://petstore.com/store.json',
        ], {
            'http://petstore.com': resource_list,
            'http://petstore.com/pet.json': pet,
            'http://petstore.com/store.json': store,
            'http://petstore.com/user.json': user
        })
        app = App.load('http://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])), [])

        #
        # provide empty path
        #
        getter = DictGetter([
            '',
            'pet.json',
            'user.json',
            'store.json',
        ], {
            '': resource_list,
            'pet.json': pet,
            'store.json': store,
            'user.json': user
        })
        app = App.load('http://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])), [])
开发者ID:mission-liao,项目名称:pyswagger,代码行数:84,代码来源:test_getter.py


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