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

Python tipfy.Request类代码示例

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

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



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

示例1: test_real_logout

    def test_real_logout(self):
        user = User.create('foo', 'foo_id', auth_remember=True)
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        store.login_with_auth_id('foo_id', remember=False)

        response = Response()
        local.current_handler.session_store.save(response)

        request = Request.from_values('/', headers={
            'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')),
        })
        local.current_handler = RequestHandler(app, request)
        store = MultiAuthStore(local.current_handler)
        self.assertNotEqual(store.user, None)
        self.assertEqual(store.user.username, 'foo')
        store.logout()

        response = Response()
        local.current_handler.session_store.save(response)

        request = Request.from_values('/', headers={
            'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')),
        })
        local.current_handler = RequestHandler(app, request)
        store = MultiAuthStore(local.current_handler)

        #self.assertEqual(store.user, None)
        self.assertEqual(store.session, None)
开发者ID:AmirS2,项目名称:tipfy,代码行数:32,代码来源:test_auth.py


示例2: test_redirect_relative_uris

    def test_redirect_relative_uris(self):
        app = Tipfy()
        class Handler(RequestHandler):
            pass

        request = Request.from_values('/foo/bar/')
        handler = Handler(app, request)
        response = handler.redirect('/baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')

        response = handler.redirect('./baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/bar/baz')

        response = handler.redirect('../baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/baz')

        request = Request.from_values('/foo/bar')
        handler = Handler(app, request)
        response = handler.redirect('/baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')

        response = handler.redirect('./baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/foo/baz')

        response = handler.redirect('../baz')
        self.assertEqual(response.headers['Location'], 'http://localhost/baz')
开发者ID:strogo,项目名称:tipfy,代码行数:26,代码来源:test_handler.py


示例3: test_set_cookie_encoded

    def test_set_cookie_encoded(self):
        local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values())
        store = SessionStore(handler)

        store.set_cookie('foo', 'bar', format='json')
        store.set_cookie('baz', 'ding', format='json')

        response = Response()
        store.save(response)

        headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}
        request = Request.from_values('/', headers=headers)

        self.assertEqual(json_b64decode(request.cookies.get('foo')), 'bar')
        self.assertEqual(json_b64decode(request.cookies.get('baz')), 'ding')
开发者ID:AmirS2,项目名称:tipfy,代码行数:15,代码来源:test_sessions.py


示例4: test_render_json_response

    def test_render_json_response(self):
        local.current_handler = HomeHandler(Tipfy(), Request.from_values())
        response = render_json_response({'foo': 'bar'})

        self.assertEqual(isinstance(response, Response), True)
        self.assertEqual(response.mimetype, 'application/json')
        self.assertEqual(response.data, '{"foo": "bar"}')
开发者ID:AmirS2,项目名称:tipfy,代码行数:7,代码来源:test_utils.py


示例5: test_format_date_no_format_but_configured

    def test_format_date_no_format_but_configured(self):
        app = Tipfy(config={
            'tipfy.sessions': {
                'secret_key': 'secret',
            },
            'tipfy.i18n': {
                'timezone': 'UTC',
                'date_formats': {
                    'time':             'medium',
                    'date':             'medium',
                    'datetime':         'medium',
                    'time.short':       None,
                    'time.medium':      None,
                    'time.full':        None,
                    'time.long':        None,
                    'date.short':       None,
                    'date.medium':      'full',
                    'date.full':        None,
                    'date.long':        None,
                    'datetime.short':   None,
                    'datetime.medium':  None,
                    'datetime.full':    None,
                    'datetime.long':    None,
                }
            }
        })
        local.current_handler = RequestHandler(app, Request.from_values('/'))

        value = datetime.datetime(2009, 11, 10, 16, 36, 05)
        self.assertEqual(i18n.format_date(value), u'Tuesday, November 10, 2009')
开发者ID:ksachdeva,项目名称:tipfy,代码行数:30,代码来源:test_i18n.py


示例6: test_renew_session

    def test_renew_session(self):
        app = Tipfy()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        user = User.create('my_username', 'my_id')
        user.renew_session(max_age=86400)
开发者ID:AmirS2,项目名称:tipfy,代码行数:7,代码来源:test_auth.py


示例7: test_make_response

    def test_make_response(self):
        app = Tipfy()
        request = Request.from_values()

        # Empty.
        response = app.make_response(request)
        self.assertEqual(isinstance(response, app.response_class), True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, '')

        # From Response.
        response = app.make_response(request, Response('Hello, World!'))
        self.assertEqual(isinstance(response, app.response_class), True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, 'Hello, World!')

        # From string.
        response = app.make_response(request, 'Hello, World!')
        self.assertEqual(isinstance(response, app.response_class), True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, 'Hello, World!')

        # From tuple.
        response = app.make_response(request, 'Hello, World!', 404)
        self.assertEqual(isinstance(response, app.response_class), True)
        self.assertEqual(response.status_code, 404)
        self.assertEqual(response.data, 'Hello, World!')

        # From None.
        self.assertRaises(ValueError, app.make_response, request, None)
开发者ID:adilhz,项目名称:tipfy,代码行数:30,代码来源:app_test.py


示例8: test_get_template_attribute

    def test_get_template_attribute(self):
        app = Tipfy(config={'tipfyext.jinja2': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        jinja2 = Jinja2(app)

        hello = jinja2.get_template_attribute('hello.html', 'hello')
        self.assertEqual(hello('World'), 'Hello, World!')
开发者ID:AmirS2,项目名称:tipfy,代码行数:8,代码来源:test_ext_jinja2.py


示例9: test_after_environment_created_using_string

    def test_after_environment_created_using_string(self):
        app = Tipfy(config={'tipfyext.jinja2': {'after_environment_created': 'resources.jinja2_after_environment_created.after_creation'}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        jinja2 = Jinja2(app)

        template = jinja2.environment.from_string("""{{ 'Hey'|ho }}""")
        self.assertEqual(template.render(), 'Hey, Ho!')
开发者ID:AmirS2,项目名称:tipfy,代码行数:8,代码来源:test_ext_jinja2.py


示例10: _get_app

 def _get_app(self, *args, **kwargs):
     app = Tipfy(config={
         'tipfy.sessions': {
             'secret_key': 'secret',
         },
     })
     local.current_handler = handler = RequestHandler(app, Request.from_values(*args, **kwargs))
     return app
开发者ID:ksachdeva,项目名称:tipfy,代码行数:8,代码来源:test_sessions.py


示例11: test_get_cookie_badly_encoded

    def test_get_cookie_badly_encoded(self):
        store = SecureCookieStore('secret')
        timestamp = str(int(time.time()))
        value = 'foo'
        signature = store._get_signature('session', value, timestamp)
        cookie_value = '|'.join([value, timestamp, signature])

        request = Request.from_values('/', headers=[('Cookie', 'session="%s"; Path=/' % cookie_value)])
        self.assertEqual(store.get_cookie(request, 'session'), None)
开发者ID:ckbisk,项目名称:tipfy,代码行数:9,代码来源:secure_cookie_test.py


示例12: test_render_template

    def test_render_template(self):
        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        mako = Mako(app)

        message = 'Hello, World!'
        res = mako.render_template(local.current_handler, 'template1.html', message=message)
        self.assertEqual(res, message + '\n')
开发者ID:AmirS2,项目名称:tipfy,代码行数:9,代码来源:test_ext_mako.py


示例13: test_check_password

    def test_check_password(self):
        app = Tipfy()
        request = Request.from_values("/")
        local.current_handler = RequestHandler(app, request)

        user = User.create("my_username", "my_id", password="foo")

        self.assertEqual(user.check_password("foo"), True)
        self.assertEqual(user.check_password("bar"), False)
开发者ID:adilhz,项目名称:tipfy,代码行数:9,代码来源:auth_test.py


示例14: test_login_with_form_invalid

    def test_login_with_form_invalid(self):
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        res = store.login_with_form('foo', 'bar', remember=True)

        self.assertEqual(res, False)
开发者ID:AmirS2,项目名称:tipfy,代码行数:9,代码来源:test_auth.py


示例15: test_user_model

    def test_user_model(self):
        app = get_app()
        app.router.add(Rule('/', name='home', handler=HomeHandler))

        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = AuthStore(local.current_handler)
        self.assertEqual(store.user_model, User)
开发者ID:AmirS2,项目名称:tipfy,代码行数:9,代码来源:test_auth.py


示例16: test_render_template

    def test_render_template(self):
        app = Tipfy(config={'tipfyext.jinja2': {'templates_dir': templates_dir}})
        local.request = Request.from_values()
        local.request.app = app
        handler = RequestHandler(local.request)
        jinja2 = Jinja2(app)

        message = 'Hello, World!'
        res = jinja2.render_template(handler, 'template1.html', message=message)
        self.assertEqual(res, message)
开发者ID:adilhz,项目名称:tipfy,代码行数:10,代码来源:ext_jinja2_test.py


示例17: test_signup_url

    def test_signup_url(self):
        app = get_app()
        app.router.add(Rule('/', name='home', handler=HomeHandler))

        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)
        app.router.match(request)

        store = AuthStore(local.current_handler)
        self.assertEqual(store.signup_url(), local.current_handler.url_for('auth/signup', redirect='/'))
开发者ID:AmirS2,项目名称:tipfy,代码行数:10,代码来源:test_auth.py


示例18: test_render_response

    def test_render_response(self):
        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        mako = Mako(app)

        message = 'Hello, World!'
        response = mako.render_response(local.current_handler, 'template1.html', message=message)
        self.assertEqual(isinstance(response, Response), True)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertEqual(response.data, message + '\n')
开发者ID:AmirS2,项目名称:tipfy,代码行数:11,代码来源:test_ext_mako.py


示例19: setUp

    def setUp(self):
        # Clean up datastore.
        super(TestAcl, self).setUp()

        self.app = Tipfy()
        self.app.config['tipfy']['dev'] = False
        local.current_handler = RequestHandler(self.app, Request.from_values())

        Acl.roles_map = {}
        Acl.roles_lock = CURRENT_VERSION_ID
        _rules_map.clear()
开发者ID:AmirS2,项目名称:tipfy,代码行数:11,代码来源:test_ext_acl.py


示例20: test_get_save_session

    def test_get_save_session(self):
        local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values())
        store = SessionStore(handler)

        session = store.get_session()
        self.assertEqual(isinstance(session, SecureCookieSession), True)
        self.assertEqual(session, {})

        session['foo'] = 'bar'

        response = Response()
        store.save(response)

        request = Request.from_values('/', headers={'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))})
        local.current_handler = handler = RequestHandler(self._get_app(), request)
        store = SessionStore(handler)

        session = store.get_session()
        self.assertEqual(isinstance(session, SecureCookieSession), True)
        self.assertEqual(session, {'foo': 'bar'})
开发者ID:ksachdeva,项目名称:tipfy,代码行数:20,代码来源:test_sessions.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tipfy.Tipfy类代码示例发布时间:2022-05-27
下一篇:
Python tipfy.url_for函数代码示例发布时间: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