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


Python Tipfy.get_test_client方法代码示例

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


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

示例1: test_redirect_relative_uris

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_redirect_relative_uris(self):
        class MyHandler(RequestHandler):
            def get(self):
                return self.redirect(self.request.args.get('redirect'))

        app = Tipfy(rules=[
            Rule('/foo/bar', name='test1', handler=MyHandler),
            Rule('/foo/bar/', name='test2', handler=MyHandler),
        ])
        client = app.get_test_client()

        response = client.get('/foo/bar/', query_string={'redirect': '/baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')

        response = client.get('/foo/bar/', query_string={'redirect': './baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/bar/baz')

        response = client.get('/foo/bar/', query_string={'redirect': '../baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/baz')

        response = client.get('/foo/bar', query_string={'redirect': '/baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')

        response = client.get('/foo/bar', query_string={'redirect': './baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/baz')

        response = client.get('/foo/bar', query_string={'redirect': '../baz'})
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')
开发者ID:adilhz,项目名称:tipfy,代码行数:30,代码来源:app_test.py

示例2: test_middleware_multiple_changes

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_middleware_multiple_changes(self):
        class MyHandler(RequestHandler):
            middleware = [SessionMiddleware(), i18n.I18nMiddleware()]

            def get(self, **kwargs):
                locale = self.i18n.locale
                return Response(locale)

        app = Tipfy(rules=[
            Rule('/', name='home', handler=MyHandler)
        ], config={
            'tipfy.sessions': {
                'secret_key': 'secret',
            },
            'tipfy.i18n': {
                'locale_request_lookup': [('args', 'lang'), ('session', '_locale')],
            }
        })

        client = app.get_test_client()
        response = client.get('/')
        self.assertEqual(response.data, 'en_US')

        response = client.get('/?lang=pt_BR')
        self.assertEqual(response.data, 'pt_BR')

        response = client.get('/')
        self.assertEqual(response.data, 'pt_BR')

        response = client.get('/?lang=en_US')
        self.assertEqual(response.data, 'en_US')

        response = client.get('/')
        self.assertEqual(response.data, 'en_US')
开发者ID:ksachdeva,项目名称:tipfy,代码行数:36,代码来源:test_i18n.py

示例3: test_custom_error_handlers

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_custom_error_handlers(self):
        class HomeHandler(RequestHandler):
            def get(self):
                return Response('')

        app = Tipfy([
            Rule('/', handler=HomeHandler, name='home'),
            Rule('/broken', handler=BrokenHandler, name='broken'),
        ], debug=False)
        app.error_handlers = {
            404: Handle404,
            405: Handle405,
            500: Handle500,
        }
        client = app.get_test_client()

        res = client.get('/nowhere')
        self.assertEqual(res.status_code, 404)
        self.assertEqual(res.data, '404 custom handler')

        res = client.put('/')
        self.assertEqual(res.status_code, 405)
        self.assertEqual(res.data, '405 custom handler')
        self.assertEqual(res.headers.get('Allow'), 'GET')

        res = client.get('/broken')
        self.assertEqual(res.status_code, 500)
        self.assertEqual(res.data, '500 custom handler')
开发者ID:strogo,项目名称:tipfy,代码行数:30,代码来源:test_application.py

示例4: test_handle_exception_2

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_handle_exception_2(self):
        res = 'I fixed it!'

        class MyMiddleware(object):
            def handle_exception(self, handler, exception):
                raise ValueError()

        class MyHandler(RequestHandler):
            middleware = [MyMiddleware()]

            def get(self, **kwargs):
                raise ValueError()

        class ErrorHandler(RequestHandler):
            def handle_exception(self, exception):
                return Response(res)

        app = Tipfy(rules=[
            Rule('/', name='home', handler=MyHandler),
        ], debug=False)
        app.error_handlers[500] = ErrorHandler

        client = app.get_test_client()
        response = client.get('/')
        self.assertEqual(response.data, res)
开发者ID:adilhz,项目名称:tipfy,代码行数:27,代码来源:app_test.py

示例5: test_abort

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_abort(self):
        class HandlerWith400(RequestHandler):
            def get(self, **kwargs):
                self.abort(400)

        class HandlerWith403(RequestHandler):
            def post(self, **kwargs):
                self.abort(403)

        class HandlerWith404(RequestHandler):
            def put(self, **kwargs):
                self.abort(404)

        app = Tipfy(rules=[
            Rule('/400', endpoint='400', handler=HandlerWith400),
            Rule('/403', endpoint='403', handler=HandlerWith403),
            Rule('/404', endpoint='404', handler=HandlerWith404),
        ], debug=True)

        client = app.get_test_client()

        response = client.get('/400')
        self.assertEqual(response.status_code, 400)

        response = client.post('/403')
        self.assertEqual(response.status_code, 403)

        response = client.put('/404')
        self.assertEqual(response.status_code, 404)
开发者ID:strogo,项目名称:tipfy,代码行数:31,代码来源:test_handler.py

示例6: test_404

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_404(self):
        """No URL rules defined."""
        app = Tipfy()
        client = app.get_test_client()

        # Normal mode.
        response = client.get('/')
        self.assertEqual(response.status_code, 404)

        # Debug mode.
        app.debug = True
        response = client.get('/')
        self.assertEqual(response.status_code, 404)
开发者ID:adilhz,项目名称:tipfy,代码行数:15,代码来源:app_test.py

示例7: test_json

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_json(self):
        class JsonHandler(RequestHandler):
            def get(self, **kwargs):
                return Response(self.request.json['foo'])

        app = Tipfy(rules=[
            Rule('/', name='home', handler=JsonHandler),
        ], debug=True)

        data = json_encode({'foo': 'bar'})
        client = app.get_test_client()
        response = client.get('/', content_type='application/json', data=data)
        self.assertEqual(response.data, 'bar')
开发者ID:adilhz,项目名称:tipfy,代码行数:15,代码来源:app_test.py

示例8: test_redirect_to_empty

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_redirect_to_empty(self):
        class HandlerWithRedirectTo(RequestHandler):
            def get(self, **kwargs):
                return self.redirect_to('home', _empty=True)

        app = Tipfy(rules=[
            Rule('/', name='home', handler=AllMethodsHandler),
            Rule('/redirect-me', name='redirect', handler=HandlerWithRedirectTo),
        ])

        client = app.get_test_client()
        response = client.get('/redirect-me', follow_redirects=False)
        self.assertEqual(response.data, '')
开发者ID:adilhz,项目名称:tipfy,代码行数:15,代码来源:app_test.py

示例9: test_405_debug

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_405_debug(self):
        class HomeHandler(RequestHandler):
            pass

        app = Tipfy(rules=[
            Rule('/', endpoint='home', handler=HomeHandler),
        ], debug=True)

        client = app.get_test_client()

        for method in ALLOWED_METHODS:
            response = client.open('/', method=method)
            self.assertEqual(response.status_code, 405)
开发者ID:strogo,项目名称:tipfy,代码行数:15,代码来源:test_handler.py

示例10: test_501

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_501(self):
        """Method is not in app.allowed_methods."""
        app = Tipfy()
        client = app.get_test_client()

        # Normal mode.
        response = client.open('/', method='CONNECT')
        self.assertEqual(response.status_code, 501)

        # Debug mode.
        app.debug = True
        response = client.open('/', method='CONNECT')
        self.assertEqual(response.status_code, 501)
开发者ID:adilhz,项目名称:tipfy,代码行数:15,代码来源:app_test.py

示例11: test_500

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_500(self):
        """Handler import will fail."""
        app = Tipfy(rules=[Rule('/', name='home', handler='non.existent.handler')])
        client = app.get_test_client()

        # Normal mode.
        response = client.get('/')
        self.assertEqual(response.status_code, 500)

        # Debug mode.
        app.debug = True
        app.config['tipfy']['enable_debugger'] = False
        self.assertRaises(ImportError, client.get, '/')
开发者ID:adilhz,项目名称:tipfy,代码行数:15,代码来源:app_test.py

示例12: test_handle_exception

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_handle_exception(self):
        app = Tipfy([
            Rule('/', handler=AllMethodsHandler, name='home'),
            Rule('/broken', handler=BrokenHandler, name='broken'),
            Rule('/broken-but-fixed', handler=BrokenButFixedHandler, name='broken-but-fixed'),
        ], debug=False)
        client = app.get_test_client()

        response = client.get('/broken')
        self.assertEqual(response.status_code, 500)

        response = client.get('/broken-but-fixed')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, 'That was close!')
开发者ID:adilhz,项目名称:tipfy,代码行数:16,代码来源:app_test.py

示例13: TestBaseModel

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
class TestBaseModel(unittest.TestCase):
    #---------------------------------------------------------------------------
    def setUp(self):
        datastore_stub = apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map[
            'datastore_v3'
        ]
        datastore_stub.Clear()
        self.app = Tipfy()
        self.client = self.app.get_test_client()

        # plans
        self.plan_active = models.Plan(
            name='Plan Active',
            plan_key='ACTIVE',
            is_active=True,
            default=False
        )
        self.plan_active.put()
        self.plan_inactive = models.Plan(
            name='Plan InActive',
            plan_key='INACTIVE',
            is_active=False,
            default=False
        )
        self.plan_inactive.put()
        self.plan_default = models.Plan(
            name='Plan Default',
            plan_key='DEFAULT',
            is_active=True,
            default=True
        )
        self.plan_default.put()

        # accounts
        self.user_1 = User(
            username='user_1',
            password='pass',
            session_id='1',
            auth_id='own|user_1'
        )
        self.user_1.put()
        self.user_2 = User(
            username='user_2',
            password='pass',
            session_id='2',
            auth_id='own|user_2'
        )
        self.user_2.put()
        self.account_active = models.Account.get_or_insert_plan(user=self.user_1)
开发者ID:reinbach,项目名称:kidvm,代码行数:51,代码来源:test_base.py

示例14: test_handler_prefix

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_handler_prefix(self):
        rules = [
            HandlerPrefix('resources.handlers.', [
                Rule('/', name='home', handler='HomeHandler'),
                Rule('/defaults', name='defaults', handler='HandlerWithRuleDefaults', defaults={'foo': 'bar'}),
            ])
        ]

        app = Tipfy(rules)
        client = app.get_test_client()

        response = client.get('/')
        self.assertEqual(response.data, 'Hello, World!')

        response = client.get('/defaults')
        self.assertEqual(response.data, 'bar')
开发者ID:aswadrangnekar,项目名称:tipfy,代码行数:18,代码来源:test_routing.py

示例15: test_handle_exception_3

# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_client [as 别名]
    def test_handle_exception_3(self):
        class MyMiddleware(object):
            def handle_exception(self, handler, exception):
                pass

        class MyHandler(RequestHandler):
            middleware = [MyMiddleware()]

            def get(self, **kwargs):
                raise ValueError()

        app = Tipfy(rules=[
            Rule('/', name='home', handler=MyHandler),
        ])
        client = app.get_test_client()
        response = client.get('/')
        self.assertEqual(response.status_code, 500)
开发者ID:adilhz,项目名称:tipfy,代码行数:19,代码来源:app_test.py


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