本文整理汇总了Python中pyramid.testing.DummyRequest.POST方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.POST方法的具体用法?Python DummyRequest.POST怎么用?Python DummyRequest.POST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.POST方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_form_params
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_form_params(self):
from ptah.form.form import Form, DisplayForm
request = DummyRequest()
form = Form(None, request)
disp_form = DisplayForm(None, request)
self.assertEqual(form.method, 'post')
post = {'post': 'info'}
request.POST = post
self.assertIs(form.form_params(), post)
self.assertIs(disp_form.form_params(), DisplayForm.params)
get = {'get': 'info'}
request.GET = get
form.method = 'get'
self.assertIs(form.form_params(), get)
form.method = 'unknown'
self.assertEqual(form.form_params(), None)
params = {'params': 'info'}
form.method = 'POST'
form.params = params
self.assertIn('params', form.form_params().keys())
self.assertIsInstance(form.form_params(), MultiDict)
params = MultiDict({'params': 'info'})
form.method = 'POST'
form.params = params
self.assertIs(form.form_params(), params)
示例2: test_form_update_widgets
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_form_update_widgets(self):
from ptah import form
request = DummyRequest()
request.POST = {}
form_ob = form.Form(None, request)
form_ob.update()
self.assertIsInstance(form_ob.widgets, form.FormWidgets)
self.assertEqual(form_ob.widgets.mode, form_ob.mode)
form_ob.mode = form.FORM_DISPLAY
form_ob.update()
self.assertEqual(form_ob.widgets.mode, form.FORM_DISPLAY)
self.assertEqual(len(form_ob.widgets), 0)
form_ob.fields = form.Fieldset(form.TextField('test'))
form_ob.update()
self.assertEqual(len(form_ob.widgets), 1)
self.assertIn('test', form_ob.widgets)
self.assertIn('test', [f.name for f in form_ob.widgets.fields()])
self.assertIsInstance(form_ob.widgets['test'], form.TextField)
self.assertEqual(form_ob.widgets['test'].name, 'test')
self.assertEqual(form_ob.widgets['test'].id, 'form-widgets-test')
示例3: test_vote_finish__declined
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_vote_finish__declined(self):
from nuorisovaalit.models import Voter
from nuorisovaalit.views.voting import vote_finish
from pyramid.session import UnencryptedCookieSessionFactoryConfig
from webob.exc import HTTPFound
session = DBSession()
populate_testing_db()
voter = session.query(Voter).first()
self.assertEquals(False, voter.has_preference())
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
self.config.testing_securitypolicy(userid=voter.openid)
self.config.add_route('close-window', '/close-window')
self.config.add_route('vote-finish', '/valmis')
request = DummyRequest()
csrf_token = request.session.new_csrf_token()
request.POST = {
'form.submitted': u'1',
'csrf_token': csrf_token,
'use_open_identity': u'no',
}
response = vote_finish(request)
self.assertTrue(isinstance(response, HTTPFound))
self.assertEquals('http://example.com/close-window', response.location)
self.assertEquals(False, voter.accept_openid)
self.assertEquals(True, voter.has_preference())
示例4: test_DELETE_using_POST_param
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_DELETE_using_POST_param(self):
app = self._make_app()
request = DummyRequest(method='POST')
request.POST = {'$method': 'DELETE'}
request.headers['X-HTTP-Method-Override'] = 'DUMMY'
self._assert_before(request)
app.registry.notify(NewRequest(request))
self._assert_after(request, 'DELETE')
示例5: test_form_extract
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_form_extract(self):
import pform
request = DummyRequest()
request.POST = {}
form_ob = pform.Form(None, request)
form_ob.fields = pform.Fieldset(pform.TextField('test'))
form_ob.update_form()
data, errors = form_ob.extract()
self.assertEqual(errors[0].msg, 'Required')
request.POST = {'test': 'Test string'}
form_ob.update_form()
data, errors = form_ob.extract()
self.assertEqual(data['test'], 'Test string')
示例6: dummy_post
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def dummy_post(dbtransaction):
from pyramid.testing import DummyRequest
from webob.multidict import MultiDict
req = DummyRequest()
req.method = 'POST'
md = MultiDict()
md.add('title', 'dummy title')
md.add('text', 'dummy text')
req.POST = md
return req
示例7: test_5export_companies
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_5export_companies(self):
req = DummyRequest(path='alchemist_startups', user=self.founder)
req.referer = '/alchemist_startups'
deselect_all(req)
self.assert_(req.session['select_all'] == False, 'Select all parameter should be set to False')
req.POST = MultiDict([('include_ids[]', 1)])
ret = export_companies(req, filename='test_companies_selectpage')
self.assert_(ret.get('success') == True, 'Writing to file was not successful')
select_all(req)
self.assert_(req.session['select_all'] == True, 'Select all parameter should be set to True')
ret = export_companies(req, filename='test_companies_selectall')
self.assert_(ret.get('success') == True, 'Writing to file was not successful')
示例8: test_csrf_token
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_csrf_token(self):
from pform import form
class MyForm(form.Form):
pass
request = DummyRequest()
form_ob = MyForm(None, request)
token = form_ob.csrf_token
self.assertEqual(token, request.session.get_csrf_token())
self.assertIsNotNone(token)
self.assertIsNone(form_ob.validate_csrf_token())
request.POST = {}
form_ob.csrf = True
self.assertRaises(HTTPForbidden, form_ob.validate_csrf_token)
self.assertRaises(HTTPForbidden, form_ob.validate_form, {}, [])
request.POST = {form_ob.csrf_name: token}
self.assertIsNone(form_ob.validate_csrf_token())
示例9: dummy_post_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def dummy_post_request():
"""Make a Dummy Request that will mimic a POST method request"""
req = DummyRequest()
config = setUp()
config.add_route('add', '/compose')
config.add_route('detail', '/entries/{entry_id}')
config.add_route('edit', '/edit/{entry_id}')
config.add_route('entry', '/entries/{entry_id}')
req.method = 'POST'
test_dict = [('title', 'test title'), ('text', 'test text')]
mdict = multidict.MultiDict(test_dict)
req.POST = mdict
return req
示例10: callView
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def callView(self, config, path, matchdict=None, GET=None, POST=None, iface=None):
from pyramid.router import Router
from pyramid.testing import DummyRequest
router = Router(config.registry)
request = DummyRequest(path=path, registry=config.registry)
request.matchdict = matchdict or {}
if GET:
request.GET = GET
if POST:
request.POST = POST
if iface:
directlyProvides(request, iface)
return router.handle_request(request)
示例11: test_vote_finish__accepted_empty_fields
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_vote_finish__accepted_empty_fields(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())
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
self.config.testing_securitypolicy(userid=voter.openid)
self.config.add_route('close-window', '/close-window')
self.config.add_route('vote-finish', '/valmis')
request = DummyRequest()
csrf_token = request.session.new_csrf_token()
request.POST = {
'csrf_token': csrf_token,
'use_open_identity': 'yes',
'gsm': u'',
'email': u'',
'street': u'',
'zipcode': u'',
'city': u'',
'form.submitted': u'1',
}
self.assertEquals({
'action_url': 'http://example.com/valmis',
'csrf_token': csrf_token,
'accept_openid': True,
'message': u'Äänesi on tallennettu',
'has_preference': False,
'pref_selected': True,
'errors': [
u'GSM-numero on virheellinen, esimerkki oikeasta muodosta "0501234567".',
u'Sähköpostiosoite on virheellinen, esimerkki oikeasta muodosta "[email protected]".',
u'Katuosoite puuttuu.',
u'Postinumero on virheellinen, esimerkki oikeasta muodosta "12345".',
u'Postitoimipaikka puuttuu.',
],
'voter': voter,
'gsm': u'',
'email': u'',
'street': u'',
'zipcode': u'',
'city': u'',
}, vote_finish(request))
self.assertEquals(False, voter.has_preference())
示例12: test_4export_users
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_4export_users(self):
req = DummyRequest(path='connections', user=self.founder)
req.referer = '/connections'
ret = grid_view(req)
self.assert_(len(ret.get('items')) == 1, 'All searched user IDs should be in the session')
deselect_all(req)
self.assert_(req.session['select_all'] == False, 'Select all parameter should be set to False')
req.POST = MultiDict([('include_ids[]', 1)])
ret = export_users(req, filename='test_users_selectpage')
self.assert_(ret.get('success') == True, 'Writing to file was not successful')
select_all(req)
self.assert_(req.session['select_all'] == True, 'Select all parameter should be set to True')
ret = export_users(req, filename='test_users_selectall')
self.assert_(ret.get('success') == True, 'Writing to file was not successful')
示例13: test_vote_finish__preference_selection_missing
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_vote_finish__preference_selection_missing(self):
"""Tests a case where the OpenID selection (yes or no) is missing."""
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())
self.config.set_session_factory(UnencryptedCookieSessionFactoryConfig)
self.config.testing_securitypolicy(userid=voter.openid)
self.config.add_route('close-window', '/close-window')
self.config.add_route('vote-finish', '/valmis')
request = DummyRequest()
csrf_token = request.session.new_csrf_token()
request.POST = {
'form.submitted': u'1',
'csrf_token': csrf_token,
'gsm': u' 00358- 40 1234 567',
'email': u'[email protected] \t',
'street': u' söme stréét',
'zipcode': u' 09123',
'city': u' citÜ',
}
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': [
u'Valitse haluatko verkkovaikuttajaidentiteetin.',
],
'voter': voter,
'gsm': u' 00358- 40 1234 567',
'email': u'[email protected] \t',
'street': u' söme stréét',
'zipcode': u' 09123',
'city': u' citÜ',
}, vote_finish(request))
self.failIf(voter.has_preference())
示例14: test_vote_finish__invalid_csrf_token
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_vote_finish__invalid_csrf_token(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.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 = {
'form.submitted': u'1',
'csrf_token': 'invalid {0}'.format(csrf_token),
}
self.assertRaises(Forbidden, lambda: vote_finish(request))
示例15: test_people_index_base_post
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST [as 别名]
def test_people_index_base_post(self):
from notaliens.people.views import people_index
request = DummyRequest()
request.method = 'POST'
request.POST = {
}
request.search_settings = {
'enabled': True
}
with mock.patch('notaliens.people.views.get_users') as get_users:
get_users.return_value = {
'count': 0
}
response = people_index(request)
assert response['data']['count'] == 0
assert response['data']['current_page'] == 0