本文整理汇总了Python中pyramid.testing.DummyRequest.POST['csrf_token']方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.POST['csrf_token']方法的具体用法?Python DummyRequest.POST['csrf_token']怎么用?Python DummyRequest.POST['csrf_token']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.POST['csrf_token']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exit_voting__successful
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST['csrf_token'] [as 别名]
def test_exit_voting__successful(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import exit_voting
from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.url import route_url
from webob.exc import HTTPFound
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
self.config.testing_securitypolicy(userid=voter.openid)
self.config.add_route('close-window', '/close-window')
request = DummyRequest(post=dict(use_open_identity='yes'))
request.POST['csrf_token'] = request.session.new_csrf_token()
response = exit_voting(request)
self.assertTrue(isinstance(response, HTTPFound))
self.assertEquals(route_url('close-window', request), response.location)
示例2: test_vote__candidate_number_mismatch
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST['csrf_token'] [as 别名]
def test_vote__candidate_number_mismatch(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote
from pyramid.session import UnencryptedCookieSessionFactoryConfig
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.config.add_route('select', '/valitse')
self.config.testing_securitypolicy(userid=voter.openid)
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
request = DummyRequest(post=dict(vote='1'))
csrf_token = request.session.new_csrf_token()
request.POST['csrf_token'] = csrf_token
request.matchdict['number'] = '2'
options = vote(request)
self.assertTrue(options['error'])
self.assertEquals(csrf_token, options['csrf_token'])
示例3: test_vote__successful_voting_response
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST['csrf_token'] [as 别名]
def test_vote__successful_voting_response(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote
from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.url import route_url
from webob.exc import HTTPFound
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.config.add_route('select', '/valitse')
self.config.add_route('vote-finish', '/valmis')
self.config.testing_securitypolicy(userid=voter.openid)
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
request = DummyRequest(post=dict(vote='1'))
request.POST['csrf_token'] = request.session.new_csrf_token()
request.matchdict['number'] = '1'
response = vote(request)
self.assertTrue(isinstance(response, HTTPFound))
self.assertEquals(route_url('vote-finish', request), response.location)
示例4: test_vote__successful_vote_log
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST['csrf_token'] [as 别名]
def test_vote__successful_vote_log(self):
from nuorisovaalit.models import Vote
from nuorisovaalit.models import Voter
from nuorisovaalit.models import VotingLog
from nuorisovaalit.views.voting import vote
from pyramid.session import UnencryptedCookieSessionFactoryConfig
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.config.add_route('select', '/valitse')
self.config.add_route('vote-finish', '/valmis')
self.config.testing_securitypolicy(userid=voter.openid)
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
session = DBSession()
request = DummyRequest(post=dict(vote='1'))
request.POST['csrf_token'] = request.session.new_csrf_token()
request.matchdict['number'] = '1'
# Check the initial conditions.
self.assertEquals(0, session.query(VotingLog).count())
self.assertEquals(0, session.query(Vote).count())
vote(request)
# Check that the vote was recorded.
self.assertEquals(1, session.query(VotingLog).count())
self.assertEquals(1, session.query(Vote).count())
# Check that the vote record info is correct.
vote_record = session.query(Vote).first()
self.assertEquals(u'Uuno', vote_record.candidate.firstname)
self.assertEquals(u'Turhapuro', vote_record.candidate.lastname)
self.assertEquals(u'xxxx xxxx', vote_record.school.name)
示例5: test_vote_finish__no_pref_selected_valid_address
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST['csrf_token'] [as 别名]
def test_vote_finish__no_pref_selected_valid_address(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote_finish
from pyramid.session import UnencryptedCookieSessionFactoryConfig
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.assertEquals(False, voter.has_preference())
voter.address = u'Äyrävänpolku 666, 09123 Mikä-mikämaa, Pohjoisnapa'
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
self.config.testing_securitypolicy(userid=voter.openid)
self.config.add_route('exit-voting', '/exit')
self.config.add_route('vote-finish', '/valmis')
request = DummyRequest()
csrf_token = request.session.new_csrf_token()
request.POST['csrf_token'] = csrf_token
self.assertEquals({
'action_url': 'http://example.com/valmis',
'csrf_token': csrf_token,
'accept_openid': None,
'message': u'Äänesi on tallennettu',
'has_preference': False,
'pref_selected': False,
'errors': [],
'voter': voter,
'gsm': voter.gsm,
'email': voter.email,
'street': u'Äyrävänpolku 666',
'zipcode': u'09123',
'city': u'Mikä-mikämaa, Pohjoisnapa',
}, vote_finish(request))
self.assertEquals(False, voter.has_preference())