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


Python Request.from_values方法代码示例

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


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

示例1: test_real_logout

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:34,代码来源:test_auth.py

示例2: test_redirect_relative_uris

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:28,代码来源:test_handler.py

示例3: test_set_cookie_encoded

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:17,代码来源:test_sessions.py

示例4: test_render_json_response

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:9,代码来源:test_utils.py

示例5: test_format_date_no_format_but_configured

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:32,代码来源:test_i18n.py

示例6: test_renew_session

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:9,代码来源:test_auth.py

示例7: test_make_response

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:32,代码来源:app_test.py

示例8: test_get_template_attribute

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:10,代码来源:test_ext_jinja2.py

示例9: test_after_environment_created_using_string

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:10,代码来源:test_ext_jinja2.py

示例10: _get_app

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
 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,代码行数:10,代码来源:test_sessions.py

示例11: test_get_cookie_badly_encoded

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:11,代码来源:secure_cookie_test.py

示例12: test_render_template

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:11,代码来源:test_ext_mako.py

示例13: test_check_password

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:11,代码来源:auth_test.py

示例14: test_login_with_form_invalid

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:11,代码来源:test_auth.py

示例15: test_user_model

# 需要导入模块: from tipfy import Request [as 别名]
# 或者: from tipfy.Request import from_values [as 别名]
    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,代码行数:11,代码来源:test_auth.py


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