Python webapp2.Response() Examples
The following are 30
code examples of webapp2.Response().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
webapp2
, or try the search function
.
Example #1
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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()
Example #2
Source File: datastore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: datastore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: blobstore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_display_blob_inline_and_binary(self): request = webapp2.Request.blank('/blob/blobkey?display=inline') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob_info = self.mox.CreateMock(blobstore.BlobInfo) blob_info.content_type = 'application/octet-stream' blobstore.BlobInfo.get('blobkey').AndReturn(blob_info) reader = self.mox.CreateMockAnything() blob_info.open().AndReturn(reader) reader.read().AndReturn('blob bytes') reader.close() self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll() self.assertEqual('text/plain', response.headers.get('Content-Type')) self.assertEqual('inline', response.headers.get('Content-Disposition')) self.assertEqual('blob bytes', response.body)
Example #5
Source File: blobstore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_display_blob_inline(self): request = webapp2.Request.blank('/blob/blobkey?display=inline') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob_info = self.mox.CreateMock(blobstore.BlobInfo) blob_info.content_type = 'image/jpeg' blobstore.BlobInfo.get('blobkey').AndReturn(blob_info) reader = self.mox.CreateMockAnything() blob_info.open().AndReturn(reader) reader.read().AndReturn('blob bytes') reader.close() self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll() self.assertEqual('image/jpeg', response.headers.get('Content-Type')) self.assertEqual('inline', response.headers.get('Content-Disposition')) self.assertEqual('blob bytes', response.body)
Example #6
Source File: blobstore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_display_blob_attachment(self): request = webapp2.Request.blank('/blob/blobkey?display=attachment') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob_info = self.mox.CreateMock(blobstore.BlobInfo) blob_info.content_type = 'image/png' blob_info.filename = 'profile.png' blobstore.BlobInfo.get('blobkey').AndReturn(blob_info) reader = self.mox.CreateMockAnything() blob_info.open().AndReturn(reader) reader.read().AndReturn('blob bytes') reader.close() self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll() self.assertEqual('image/png', response.headers.get('Content-Type')) self.assertEqual('attachment; filename=profile.png', response.headers.get('Content-Disposition')) self.assertEqual('blob bytes', response.body)
Example #7
Source File: cron_handler_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: cron_handler_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: blobstore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_display_blob_info_inlineable(self): request = webapp2.Request.blank('/blobstore/blob/blobkey') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob = self.mox.CreateMock(blobstore.BlobInfo) blob.content_type = 'image/png' blobstore.BlobInfo.get('blobkey').AndReturn(blob) handler.render('blob_viewer.html', {'blob_info': blob, 'delete_uri': '/blobstore', 'download_uri': request.path + '?display=attachment', 'inline_uri': request.path + '?display=inline', 'inlineable': True, 'return_to': '/blobstore' }) self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll()
Example #10
Source File: cron_handler_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: datastore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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())
Example #12
Source File: datastore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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()
Example #13
Source File: xmpp_request_handler_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #14
Source File: xmpp_request_handler_test.py From browserscope with Apache License 2.0 | 6 votes |
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)
Example #15
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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()
Example #16
Source File: handler_utils.py From upvote with Apache License 2.0 | 6 votes |
def CreateErrorHandler(http_status): """Creates a WSGIApplication error handler function for an HTTP status.""" def ErrorHandler(request, response, exception): """Error handling method to be registered to WSGIApplication.error_handlers. Args: request: A webapp2.Request instance. response: A webapp2.Response instance. exception: The uncaught exception. """ handler = _GetHandlerFromRequest(request) # If the target RequestHandler is an UpvoteRequestHandler, see if there's an # associated RequestCounter and increment it to reflect the error. if isclass(handler) and issubclass(handler, UpvoteRequestHandler): request_counter = handler().RequestCounter if request_counter is not None: request_counter.Increment(http_status) response.set_status(http_status) logging.exception(exception) raise exception return ErrorHandler
Example #17
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
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'))
Example #18
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_display_blob_info_inlineable(self): request = webapp2.Request.blank('/blobstore/blob/blobkey') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob = self.mox.CreateMock(blobstore.BlobInfo) blob.content_type = 'image/png' blobstore.BlobInfo.get('blobkey').AndReturn(blob) handler.render('blob_viewer.html', {'blob_info': blob, 'delete_uri': '/blobstore', 'download_uri': request.path + '?display=attachment', 'inline_uri': request.path + '?display=inline', 'inlineable': True, 'return_to': '/blobstore' }) self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll()
Example #19
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_display_blob_info_non_inlineable(self): request = webapp2.Request.blank('/blobstore/blob/blobkey') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob = self.mox.CreateMock(blobstore.BlobInfo) blob.content_type = 'application/octet-stream' blobstore.BlobInfo.get('blobkey').AndReturn(blob) handler.render('blob_viewer.html', {'blob_info': blob, 'delete_uri': '/blobstore', 'download_uri': request.path + '?display=attachment', 'inline_uri': request.path + '?display=inline', 'inlineable': False, 'return_to': '/blobstore' }) self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll()
Example #20
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_display_blob_inline(self): request = webapp2.Request.blank('/blob/blobkey?display=inline') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob_info = self.mox.CreateMock(blobstore.BlobInfo) blob_info.content_type = 'image/jpeg' blobstore.BlobInfo.get('blobkey').AndReturn(blob_info) reader = self.mox.CreateMockAnything() blob_info.open().AndReturn(reader) reader.read().AndReturn('blob bytes') reader.close() self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll() self.assertEqual('image/jpeg', response.headers.get('Content-Type')) self.assertEqual('inline', response.headers.get('Content-Disposition')) self.assertEqual('blob bytes', response.body)
Example #21
Source File: blobstore_viewer_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_display_blob_attachment(self): request = webapp2.Request.blank('/blob/blobkey?display=attachment') response = webapp2.Response() handler = blobstore_viewer.BlobRequestHandler(request, response) blob_info = self.mox.CreateMock(blobstore.BlobInfo) blob_info.content_type = 'image/png' blob_info.filename = 'profile.png' blobstore.BlobInfo.get('blobkey').AndReturn(blob_info) reader = self.mox.CreateMockAnything() blob_info.open().AndReturn(reader) reader.read().AndReturn('blob bytes') reader.close() self.mox.ReplayAll() handler.get('blobkey') self.mox.VerifyAll() self.assertEqual('image/png', response.headers.get('Content-Type')) self.assertEqual('attachment; filename=profile.png', response.headers.get('Content-Disposition')) self.assertEqual('blob bytes', response.body)
Example #22
Source File: console_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post_cached_module(self): console.ConsoleRequestHandler._modulename_to_shell_module = { 'default': self.interactive_command_module} request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post() handler.dispatcher = self.dispatcher self.interactive_command_module.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)
Example #23
Source File: console_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post_new_module(self): request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post() handler.dispatcher = self.dispatcher handler.dispatcher.get_module_by_name('default').AndReturn(self.module) self.module.create_interactive_command_module().AndReturn( self.interactive_command_module) self.interactive_command_module.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)
Example #24
Source File: datastore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post_entity_key_string(self): request = webapp2.Request.blank( '/datastore/edit/%s' % self.entity4.key(), POST={'overflowdatetime|dateprop': str(2**60), 'int|intprop': '123', 'string|stringprop': '', 'next': 'http://redirect/'}) response = webapp2.Response() handler = datastore_viewer.DatastoreEditRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post( str(self.entity4.key())) 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()) self.assertEqual(2**60, entity['dateprop']) self.assertEqual(123, entity['intprop']) self.assertEqual([10, 11], entity['listprop']) self.assertNotIn('stringprop', entity)
Example #25
Source File: datastore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post_no_entity_key_string(self): request = webapp2.Request.blank( '/datastore/edit', POST={'kind': 'Kind1', 'overflowdatetime|dateprop': '2009-12-24 23:59:59', 'int|intprop': '123', 'string|stringprop': 'Hello', 'next': 'http://redirect/'}) response = webapp2.Response() handler = datastore_viewer.DatastoreEditRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post(None) 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({'dateprop': datetime.datetime(2009, 12, 24, 23, 59, 59), 'intprop': 123, 'stringprop': 'Hello'}) self.assertEquals(1, query.Count())
Example #26
Source File: cron_handler_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_post(self): self.mox.StubOutWithMock(cron_handler.CronHandler, 'dispatcher') request = webapp2.Request.blank( '/cron', POST={'url': '/url', 'target': 'module_name'}) response = webapp2.Response() handler = cron_handler.CronHandler(request, response) admin_request_handler.AdminRequestHandler(handler).post() handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher) handler.dispatcher.add_request( method='GET', relative_url='/url', headers=[('X-AppEngine-Cron', 'true')], body='', module_name='module_name', 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)
Example #27
Source File: cron_handler_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
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) admin_request_handler.AdminRequestHandler(handler).get() 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)
Example #28
Source File: cron_handler_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
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) admin_request_handler.AdminRequestHandler(handler).get() 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)
Example #29
Source File: datastore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_empty_request_and_empty_datastore(self): request = webapp2.Request.blank('/datastore') response = webapp2.Response() handler = datastore_viewer.DatastoreRequestHandler(request, response) admin_request_handler.AdminRequestHandler(handler).get() 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()
Example #30
Source File: datastore_viewer_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
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) admin_request_handler.AdminRequestHandler(handler).get() self.mox.ReplayAll() handler.get() self.mox.VerifyAll() self.assertEqual(302, response.status_int) self.assertEqual('http://localhost/datastore?kind=Kind1', response.location)