本文整理汇总了Python中pyramid.testing.DummyRequest.accept方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.accept方法的具体用法?Python DummyRequest.accept怎么用?Python DummyRequest.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.accept方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_accept_application_json
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import accept [as 别名]
def test_accept_application_json(self):
request = DummyRequest(path='/thing/1')
request.accept = MIMEAccept('application/json')
request.matchdict = {'id': 1}
view = RESTfulView(_dummy_context_factory(), request)
response = view.get_member()
self.assertEqual(response.content_type, 'application/json')
member = json.loads(response.body)['results'][0]
self.assertEqual(member['id'], 1)
示例2: new_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import accept [as 别名]
def new_request(self, type=None):
request = self.current_request
auth = dict()
if request:
environ = request.environ
for key in self.auth_env_keys:
if environ.has_key(key):
auth[key] = environ[key]
request = DummyRequest()
request.environ['SERVER_NAME'] = 'testcase'
request.environ['AUTH_TYPE'] = 'cookie'
request.environ.update(auth)
if type == 'json':
request.headers['X-Request'] = 'JSON'
request.accept = 'application/json'
self.current_request = request
return request
示例3: DocumentContextFactory
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import accept [as 别名]
# TODO: Log result if error! By John Doe
task_manager.on_update_progress(
task_id, 5.0, msg='Preparing to change column name')
# NOTE: Get column value for each document! By John Doe
url='/%s/doc' % (base.metadata.name)
search_param='{"select":["id_doc", "%s"],"limit":null}' %\
column_path[-1]
params={
'$$': search_param
}
request=DummyRequest(path=url, params=params)
request.method='GET'
request.matchdict={"base": base.metadata.name}
request.accept=Accept("application/json")
doc_view=DocumentCustomView(
DocumentContextFactory(request),
request
)
results=doc_view.get_collection(render_to_response=True)
results=results.json_body['results']
if async:
# NOTE: Update task progress! By John Doe
# TODO: Log result if error! By John Doe
task_manager.on_update_progress(
task_id, 10.0, msg="Saved old documents' values")
# NOTE: Delete old column value from documents! By John Doe
示例4: test_xml_renderer
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import accept [as 别名]
def test_xml_renderer(self):
request = DummyRequest(path='/thing/1')
request.accept = MIMEAccept('application/xml')
request.matchdict = {'id': 1}
view = RESTfulView(_dummy_context_factory(), request)
self.assertRaises(HTTPBadRequest, view.get_member)