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


Python App._create_方法代码示例

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


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

示例1: test_parameter

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

示例2: test_item

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
    def test_item(self):
        """ make sure to raise exception for invalid item
        """
        try:
            App._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:
            App._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:mission-liao,项目名称:pyswagger,代码行数:24,代码来源:test_upgrade.py

示例3: test_uploadImages

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
    def test_uploadImages(self):
        """ test for uploading multiple files """
        global received_files

        app = App._create_(get_test_data_folder(version='2.0', which=os.path.join('io', 'files')))
        resp = yield self.client.request(
            app.op['upload_images'](images=[
                dict(data=six.BytesIO(six.b('test image 1')), filename='_1.k'),
                dict(data=six.BytesIO(six.b('test image 2')), filename='_2.k'),
                dict(data=six.BytesIO(six.b('test image 3')), filename='_3.k'),
            ]),
            opt=dict(
                url_netloc='localhost:'+str(self.get_http_port())
            )
        )

        self.assertEqual(received_files[0], {'body': six.b('test image 1'), 'content_type': 'application/unknown', 'filename': u'_1.k'})
        self.assertEqual(received_files[1], {'body': six.b('test image 2'), 'content_type': 'application/unknown', 'filename': u'_2.k'})
        self.assertEqual(received_files[2], {'body': six.b('test image 3'), 'content_type': 'application/unknown', 'filename': u'_3.k'})
开发者ID:mission-liao,项目名称:pyswagger,代码行数:21,代码来源:test_tornado.py

示例4: test_uploadImages

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
    def test_uploadImages(self):
        """ upload multiple files """
        httpretty.register_uri(httpretty.POST, 'http://test.com/upload', status=200)

        app = App._create_(get_test_data_folder(version='2.0', which=os.path.join('io', 'files')))
        resp = client.request(app.op['upload_images'](images=[
                dict(data=six.BytesIO(six.b('test image 1')), filename='_1.k'),
                dict(data=six.BytesIO(six.b('test image 2')), filename='_2.k'),
                dict(data=six.BytesIO(six.b('test image 3')), filename='_3.k')
            ])
        )
        self.assertEqual(resp.status, 200)
        body = httpretty.last_request().body.decode()
        self.assertTrue(body.find('_1.k') != -1)
        self.assertTrue(body.find('test image 1') != -1)
        self.assertTrue(body.find('_2.k') != -1)
        self.assertTrue(body.find('test image 2') != -1)
        self.assertTrue(body.find('_3.k') != -1)
        self.assertTrue(body.find('test image 3') != -1)
开发者ID:mission-liao,项目名称:pyswagger,代码行数:21,代码来源:test_requests.py

示例5: test_auto_schemes

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App 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 = App._create_('http://test.com/api-doc/swagger.json')
        self.assertEqual(app.schemes, ['http'])
开发者ID:mission-liao,项目名称:pyswagger,代码行数:22,代码来源:test_core.py

示例6: RESTHandler

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
from __future__ import absolute_import
from tornado import web, testing
from tornado.ioloop import IOLoop
from pyswagger import App
from pyswagger.contrib.client.tornado import TornadoClient
from ...utils import create_pet_db, get_test_data_folder, pet_Mary
import json
import six
import os


sapp = App._create_(get_test_data_folder(version='1.2', which='wordnik'))
received_file = None
received_meta = None
received_headers = None

""" refer to pyswagger.tests.data.v1_2.wordnik for details """

class RESTHandler(web.RequestHandler):
    """ base implementation of RequestHandler,
    accept a db as init paramaeter.
    """
    def initialize(self, db):
        self.db = db

    def prepare(self):
        """
        According to FAQ of tornado, they won't handle json media-type.
        """
        super(RESTHandler, self).prepare()
开发者ID:mission-liao,项目名称:pyswagger,代码行数:32,代码来源:test_tornado.py

示例7: setUpClass

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
 def setUpClass(kls):
     kls.app = App._create_(get_test_data_folder(
         version='2.0',
         which=os.path.join('resolve', 'deref')
     ))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:7,代码来源:test_resolve.py

示例8: setUpClass

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
 def setUpClass(kls):
     kls.app = App._create_(get_test_data_folder(
         version='2.0',
         which='patch'
     ))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:7,代码来源:test_patch.py

示例9: setUpClass

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
 def setUpClass(kls):
     kls.app = App._create_(get_test_data_folder(version='2.0', which=os.path.join('schema', 'model')))
开发者ID:mission-liao,项目名称:pyswagger,代码行数:4,代码来源:test_prim.py

示例10: ModelInteritanceTestCase

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
from pyswagger import App
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 = App._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')


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,
            content_type='application/json',
开发者ID:mission-liao,项目名称:pyswagger,代码行数:33,代码来源:test_model.py

示例11: setUpClass

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
 def setUpClass(kls):
     kls.app = App._create_(folder)
开发者ID:mission-liao,项目名称:pyswagger,代码行数:4,代码来源:test_upgrade.py

示例12: BasicAuthAndApiKeyTestCase

# 需要导入模块: from pyswagger import App [as 别名]
# 或者: from pyswagger.App import _create_ [as 别名]
from pyswagger import App, Security
from ..utils import get_test_data_folder
import unittest


app = App._create_(get_test_data_folder(version='1.2', which='simple_auth')) 


class BasicAuthAndApiKeyTestCase(unittest.TestCase):
    """ test cases for authorzation related """

    def setUp(self):
        self.s = Security(app)
        self.s.update_with('simple_key', '123456')
        self.s.update_with('simple_basic', ('mission', '123123'))
        self.s.update_with('simple_basic2', ('qoo', '456456'))
        self.s.update_with('simple_key2', '789789')

    def test_deleteUser(self):
        """ basic auth """
        req, _ = app.op['deleteUser'](username='mission')
        self.s(req).prepare()

        self.assertTrue('Authorization' in req.header)
        self.assertEqual(req.header['Authorization'], 'Basic bWlzc2lvbjoxMjMxMjM=')

    def test_getUserByName(self):
        """ api key, passed by query """
        req, _ = app.op['getUserByName'](username='mission')
        self.s(req).prepare()
开发者ID:mission-liao,项目名称:pyswagger,代码行数:32,代码来源:test_auth.py

示例13: test_http_getter

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


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