本文整理汇总了Python中pyramid.testing.DummyRequest.headers['X-CSRF-Token']方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.headers['X-CSRF-Token']方法的具体用法?Python DummyRequest.headers['X-CSRF-Token']怎么用?Python DummyRequest.headers['X-CSRF-Token']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.headers['X-CSRF-Token']方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: req
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers['X-CSRF-Token'] [as 别名]
def req(db_session):
"""
(Integration Testing) Creates a dummy request
The request is setup with configuration CSRF values and the expected
``db_session`` property, the goal being to be be as close to a real
database session as possible.
Note that we must called it "req" as "request" is reserved by pytest.
:param db_session: The testing database session
:returns: a configured request object
"""
import uuid
import mock
from pyramid.testing import DummyRequest
dummy_request = DummyRequest()
# Configurable csrf token
csrf_token = str(uuid.uuid4())
get_csrf_token = mock.Mock(return_value=csrf_token)
dummy_request.session.get_csrf_token = get_csrf_token
dummy_request.headers['X-CSRF-Token'] = csrf_token
# Attach database session for expected behavior
dummy_request.db_session = db_session
db_session.info['request'] = dummy_request
return dummy_request
示例2: csrf_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers['X-CSRF-Token'] [as 别名]
def csrf_request(config):
request = DummyRequest(registry=config.registry)
request.headers['X-CSRF-Token'] = request.session.get_csrf_token()
return request
示例3: csrf_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import headers['X-CSRF-Token'] [as 别名]
def csrf_request(config, **kwargs):
request = DummyRequest(db=mock.sentinel.db_session, registry=config.registry, **kwargs)
request.headers['X-CSRF-Token'] = request.session.get_csrf_token()
return request