本文整理汇总了Python中webapp2.Response方法的典型用法代码示例。如果您正苦于以下问题:Python webapp2.Response方法的具体用法?Python webapp2.Response怎么用?Python webapp2.Response使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webapp2
的用法示例。
在下文中一共展示了webapp2.Response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post(self):
self.mox.StubOutWithMock(cron_handler.CronHandler, 'dispatcher')
request = webapp2.Request.blank('/cron', POST={'url': '/url'})
response = webapp2.Response()
handler = cron_handler.CronHandler(request, response)
handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher)
handler.dispatcher.add_request(
method='GET',
relative_url='/url',
headers=[('X-AppEngine-Cron', 'true')],
body='',
source_ip='0.1.0.1').AndReturn(
dispatcher.ResponseTuple('500 Internal Server Error', [], ''))
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(500, response.status_int)
示例2: test_get_with_pytz
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_get_with_pytz(self, pytz=object()):
cron_handler.pytz = pytz
jobs = object()
request = webapp2.Request.blank('/cron')
response = webapp2.Response()
handler = cron_handler.CronHandler(request, response)
self.mox.StubOutWithMock(handler, '_get_cron_jobs')
self.mox.StubOutWithMock(handler, 'render')
handler._get_cron_jobs().AndReturn(jobs)
handler.render('cron.html',
{'has_pytz': bool(pytz), 'cronjobs': jobs}).AndReturn(
'template')
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
self.assertEqual('template', response.body)
示例3: test_get_with_invalid_cron_yaml
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_get_with_invalid_cron_yaml(self):
cron_handler.pytz = None
request = webapp2.Request.blank('/cron')
response = webapp2.Response()
handler = cron_handler.CronHandler(request, response)
self.mox.StubOutWithMock(handler, '_get_cron_jobs')
self.mox.StubOutWithMock(handler, 'render')
self.mox.StubOutWithMock(traceback, 'format_exc')
handler._get_cron_jobs().AndRaise(yaml_errors.Error)
traceback.format_exc().AndReturn('traceback')
handler.render(
'cron.html',
{'has_pytz': False, 'cron_error': 'traceback'}).AndReturn('template')
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
self.assertEqual('template', response.body)
示例4: test_empty_request_and_empty_datastore
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_empty_request_and_empty_datastore(self):
request = webapp2.Request.blank('/datastore')
response = webapp2.Response()
handler = datastore_viewer.DatastoreRequestHandler(request, response)
handler.render('datastore_viewer.html',
{'entities': [],
'headers': [],
'kind': None,
'kinds': [],
'message': None,
'namespace': '',
'num_pages': 0,
'order': None,
'paging_base_url': '/datastore?',
'order_base_url': '/datastore?',
'page': 1,
'select_namespace_url': '/datastore?namespace=',
'show_namespace': False,
'start': 0,
'total_entities': 0})
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
示例5: test_empty_request_and_populated_datastore
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_empty_request_and_populated_datastore(self):
entity = datastore.Entity('Kind1', id=123, _app=self.app_id)
entity['intprop'] = 1
entity['listprop'] = [7, 8, 9]
datastore.Put(entity)
request = webapp2.Request.blank('/datastore')
response = webapp2.Response()
handler = datastore_viewer.DatastoreRequestHandler(request, response)
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://localhost/datastore?kind=Kind1',
response.location)
示例6: test_post_no_entity_key_string
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post_no_entity_key_string(self):
request = webapp2.Request.blank(
'/datastore/edit',
POST={'kind': 'Kind1',
'int|intprop': '123',
'string|stringprop': 'Hello',
'next': 'http://redirect/'})
response = webapp2.Response()
handler = datastore_viewer.DatastoreEditRequestHandler(request, response)
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://redirect/', response.location)
# Check that the entity was added.
query = datastore.Query('Kind1')
query.update({'intprop': 123, 'stringprop': 'Hello'})
self.assertEquals(1, query.Count())
示例7: test_post_entity_key_string
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post_entity_key_string(self):
request = webapp2.Request.blank(
'/datastore/edit/%s' % self.entity4.key(),
POST={'int|intprop': '123',
'string|stringprop': '',
'next': 'http://redirect/'})
response = webapp2.Response()
handler = datastore_viewer.DatastoreEditRequestHandler(request, response)
self.mox.ReplayAll()
handler.post(str(self.entity4.key()))
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://redirect/', response.location)
# Check that the entity was updated.
entity = datastore.Get(self.entity4.key())
print entity
self.assertEqual(123, entity['intprop'])
self.assertEqual([10, 11], entity['listprop'])
self.assertNotIn('stringprop', entity)
示例8: test_post_new_server
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post_new_server(self):
request = webapp2.Request.blank('', POST={'code': 'print 5+5',
'server_name': 'default'})
response = webapp2.Response()
handler = console.ConsoleRequestHandler(request, response)
handler.dispatcher = self.dispatcher
handler.dispatcher.get_server_by_name('default').AndReturn(self.server)
self.server.create_interactive_command_server().AndReturn(
self.interactive_command_server)
self.interactive_command_server.send_interactive_command(
'print 5+5').AndReturn('10\n')
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(200, response.status_int)
self.assertEqual('10\n', response.body)
示例9: test_post_cached_server
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post_cached_server(self):
console.ConsoleRequestHandler._servername_to_shell_server = {
'default': self.interactive_command_server}
request = webapp2.Request.blank('', POST={'code': 'print 5+5',
'server_name': 'default'})
response = webapp2.Response()
handler = console.ConsoleRequestHandler(request, response)
handler.dispatcher = self.dispatcher
self.interactive_command_server.send_interactive_command(
'print 5+5').AndReturn('10\n')
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(200, response.status_int)
self.assertEqual('10\n', response.body)
示例10: test_post_exception
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post_exception(self):
console.ConsoleRequestHandler._servername_to_shell_server = {
'default': self.interactive_command_server}
request = webapp2.Request.blank('', POST={'code': 'print 5+5',
'server_name': 'default'})
response = webapp2.Response()
handler = console.ConsoleRequestHandler(request, response)
handler.dispatcher = self.dispatcher
self.interactive_command_server.send_interactive_command(
'print 5+5').AndRaise(server.InteractiveCommandError('restart'))
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(200, response.status_int)
self.assertEqual('restart', response.body)
示例11: test_presence_available
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_presence_available(self):
self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send')
request = webapp2.Request.blank('/xmpp', POST={'message_type': 'presence',
'to': 'foo@example.com',
'from': 'baz@example.com',
'presence': 'available'})
response = webapp2.Response()
handler = xmpp_request_handler.XmppRequestHandler(request, response)
data = xmpp_request_handler._FormData()
data.add_text('from', 'baz@example.com', 'plain')
data.add_text('to', 'foo@example.com', 'plain')
data.add_text(
'stanza',
CompareXml(
'<ns0:presence from="baz@example.com" to="foo@example.com" '
'xmlns:ns0="jabber:client" />'),
'xml')
handler._send('/_ah/xmpp/presence/available/', data).AndReturn(
dispatcher.ResponseTuple('404 Not Found', [], 'Response'))
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual('404 Not Found', response.status)
示例12: test_presence_unavailable
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_presence_unavailable(self):
self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send')
request = webapp2.Request.blank('/xmpp', POST={'message_type': 'presence',
'to': 'foo@example.com',
'from': 'baz@example.com',
'presence': 'unavailable'})
response = webapp2.Response()
handler = xmpp_request_handler.XmppRequestHandler(request, response)
data = xmpp_request_handler._FormData()
data.add_text('from', 'baz@example.com', 'plain')
data.add_text('to', 'foo@example.com', 'plain')
data.add_text(
'stanza',
CompareXml(
'<ns0:presence from="baz@example.com" to="foo@example.com" '
'type="unavailable" xmlns:ns0="jabber:client" />'),
'xml')
handler._send('/_ah/xmpp/presence/unavailable/', data).AndReturn(
dispatcher.ResponseTuple('404 Not Found', [], 'Response'))
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual('404 Not Found', response.status)
示例13: test_get_no_offset
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_get_no_offset(self):
request = webapp2.Request.blank('/blobstore')
response = webapp2.Response()
handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
blob_infos = [object() for _ in range(10)]
blobstore_viewer._get_blobs(0, BLOBS_PER_PAGE+1).AndReturn(blob_infos)
handler.render('blobstore_viewer.html',
{'previous': None,
'next': None,
'blob_infos': blob_infos,
'offset': 0,
'return_to': 'http://localhost/blobstore',
})
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
示例14: test_get_with_offset
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_get_with_offset(self):
request = webapp2.Request.blank('/blobstore?offset=40')
response = webapp2.Response()
handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
blob_infos = [object() for _ in range(10)]
blobstore_viewer._get_blobs(40, BLOBS_PER_PAGE+1).AndReturn(blob_infos)
handler.render('blobstore_viewer.html',
{'previous': 20,
'next': None,
'blob_infos': blob_infos,
'offset': 40,
'return_to': 'http://localhost/blobstore?offset=40',
})
self.mox.ReplayAll()
handler.get()
self.mox.VerifyAll()
示例15: test_post
# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Response [as 别名]
def test_post(self):
request = webapp2.Request.blank(
'/blobstore',
method='POST',
POST=multidict.MultiDict([('blob_key', 'a'),
('blob_key', 'b')]))
response = webapp2.Response()
handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
self.mox.StubOutWithMock(blobstore, 'delete')
blobstore.delete(['a', 'b'])
self.mox.ReplayAll()
handler.post()
self.mox.VerifyAll()
self.assertEqual(302, response.status_int)
self.assertEqual('http://localhost/blobstore',
response.headers.get('Location'))