本文整理汇总了Python中pyramid.testing.DummyRequest.matchdict['number']方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.matchdict['number']方法的具体用法?Python DummyRequest.matchdict['number']怎么用?Python DummyRequest.matchdict['number']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.matchdict['number']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vote__returned_options
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict['number'] [as 别名]
def test_vote__returned_options(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote
from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.url import route_url
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()
csrf_token = request.session.new_csrf_token()
request.matchdict['number'] = '1'
options = vote(request)
self.assertEquals({
'action_url': request.path_url,
'select_url': route_url('select', request),
'candidate': {
'number': 1,
'name': u'Turhapuro, Uuno',
},
'profile': {
'fullname': u'Matti Meikäläinen',
'district': u'Ahvenanmaan maakunnan vaalipiiri',
},
'error': False,
'csrf_token': csrf_token
}, options)
示例2: test_vote__invalid_candidate_number
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict['number'] [as 别名]
def test_vote__invalid_candidate_number(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote
from pyramid.exceptions import NotFound
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.config.testing_securitypolicy(userid=voter.openid)
request = DummyRequest()
request.matchdict['number'] = 666
self.assertRaises(NotFound, lambda: vote(request))
示例3: test_vote__candidate_number_mismatch
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict['number'] [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'])
示例4: test_vote__successful_voting_response
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict['number'] [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)
示例5: test_vote__successful_vote_log
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict['number'] [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)