當前位置: 首頁>>代碼示例>>Python>>正文


Python App.load方法代碼示例

本文整理匯總了Python中pyswagger.App.load方法的典型用法代碼示例。如果您正苦於以下問題:Python App.load方法的具體用法?Python App.load怎麽用?Python App.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyswagger.App的用法示例。


在下文中一共展示了App.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_dict_getter_v2_0

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [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

示例2: test_load

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def test_load(self):
        """ make sure the result of yaml and json are identical """
        app_json = App.load(get_test_data_folder(
            version='2.0',
            which='wordnik'
        ))
        app_yaml = App.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:mission-liao,項目名稱:pyswagger,代碼行數:17,代碼來源:test_yaml.py

示例3: test_schema

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def test_schema(self):
        folder = utils.normalize_url(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'schema')
        ))

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


        app = App.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:mission-liao,項目名稱:pyswagger,代碼行數:27,代碼來源:test_circular.py

示例4: setUpClass

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def setUpClass(kls):
        kls.app = App.load(get_test_data_folder(
            version='2.0',
            which='bitbucket'
        ))

        # bypass cyclic testing
        kls.app.prepare(strict=False)
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:10,代碼來源:test_bitbucket.py

示例5: test_path_item_prepare_with_cycle

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def test_path_item_prepare_with_cycle(self):
        app = App.load(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'path_item')
        ))

        # should raise nothing
        app.prepare()
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:10,代碼來源:test_circular.py

示例6: setUpClass

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def setUpClass(kls):
        kls.app = App.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:mission-liao,項目名稱:pyswagger,代碼行數:10,代碼來源:test_conv.py

示例7: test_relative_schema

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
 def test_relative_schema(self):
     """ test case for issue#53,
     relative file, which root is a Schema Object
     """
     app = App.load(
         url='file:///relative/internal.yaml',
         url_load_hook=_gen_hook(get_test_data_folder(version='2.0', which='ex'))
     )
     app.prepare()
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:11,代碼來源:test_ex.py

示例8: test_read_only_and_required

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
 def test_read_only_and_required(self):
     """ a property is both read-only and required """
     app = App.load(get_test_data_folder(
         version='2.0',
         which=os.path.join('validate', 'req_and_readonly')
     ))
     errs = app.validate(strict=False)
     self.maxDiff = None
     self.assertEqual(sorted(errs), sorted([
         ((u'#/definitions/ReadOnly', 'Schema'), 'ReadOnly property in required list: protected')
     ]))
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:13,代碼來源:test_validate.py

示例9: setUp

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App 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 = App.load('http://petstore.io/wordnik', url_load_hook=_hook)
        self.app.prepare()
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:14,代碼來源:test_app.py

示例10: test_local_path_with_custome_getter

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App 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 = App.load(path, getter=cls)
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:15,代碼來源:test_getter.py

示例11: test_model_inheritance

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def test_model_inheritance(self):
        """
        """
        app = App.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:mission-liao,項目名稱:pyswagger,代碼行數:19,代碼來源:test_conv.py

示例12: test_no_host_basePath

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App 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 = 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

示例13: setUpClass

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [as 別名]
    def setUpClass(kls):
        factory = Primitive()
        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 = App.load(get_test_data_folder(
            version='2.0',
            which=os.path.join('schema', 'extension'),
        ), prim=factory)
        kls.app.prepare()
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:25,代碼來源:test_prim.py

示例14: _authorization

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App 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 = App.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,
            ResponseMessage: 23
開發者ID:mission-liao,項目名稱:pyswagger,代碼行數:33,代碼來源:test_scan.py

示例15: test_dict_getter_v1_2

# 需要導入模塊: from pyswagger import App [as 別名]
# 或者: from pyswagger.App import load [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.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。