def test_not_found(self): app = webapp2.WSGIApplication([]) config.instrument_wsgi_application(app) app.get_response('/notfound') fields = {'name': '', 'status': 404, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_not_found(self): app = webapp2.WSGIApplication([]) config.instrument_wsgi_application(app) app.get_response('/notfound') fields = {'name': '', 'status': 404, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_http_exception(self): class Handler(webapp2.RequestHandler): def get(self): raise webapp2.exc.HTTPExpectationFailed() app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 417, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_set_status(self): class Handler(webapp2.RequestHandler): def get(self): self.response.set_status(418) app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 418, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_http_exception(self): class Handler(webapp2.RequestHandler): def get(self): raise webapp2.exc.HTTPExpectationFailed() app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 417, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_set_status(self): class Handler(webapp2.RequestHandler): def get(self): self.response.set_status(418) app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 418, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_missing_response_content_length(self): class Handler(webapp2.RequestHandler): def get(self): del self.response.headers['content-length'] app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertIsNone(http_metrics.server_response_bytes.get(fields))
def test_missing_response_content_length(self): class Handler(webapp2.RequestHandler): def get(self): del self.response.headers['content-length'] app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertIsNone(http_metrics.server_response_bytes.get(fields))
def test_post(self): class Handler(webapp2.RequestHandler): def post(self): pass app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/', POST='foo') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertEqual(len('foo'), http_metrics.server_request_bytes.get(fields).sum)
def test_robot(self): class Handler(webapp2.RequestHandler): def get(self): ret = webapp2.Response() ret.set_status(200) return ret app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/', user_agent='GoogleBot') fields = {'name': '^/$', 'status': 200, 'is_robot': True} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_post(self): class Handler(webapp2.RequestHandler): def post(self): pass app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/', POST='foo') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertEqual( len('foo'), http_metrics.server_request_bytes.get(fields).sum)
def test_robot(self): class Handler(webapp2.RequestHandler): def get(self): ret = webapp2.Response() ret.set_status(200) return ret app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app) app.get_response('/', user_agent='GoogleBot') fields = {'name': '^/$', 'status': 200, 'is_robot': True} self.assertEqual(1, http_metrics.server_response_status.get(fields))
def test_success(self): class Handler(webapp2.RequestHandler): def get(self): self.response.write('success!') app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app, time_fn=self.fake_time) app.get_response('/') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertLessEqual(3000, http_metrics.server_durations.get(fields).sum) self.assertEqual( len('success!'), http_metrics.server_response_bytes.get(fields).sum)
def test_success(self): class Handler(webapp2.RequestHandler): def get(self): self.response.write('success!') app = webapp2.WSGIApplication([('/', Handler)]) config.instrument_wsgi_application(app, time_fn=self.fake_time) app.get_response('/') fields = {'name': '^/$', 'status': 200, 'is_robot': False} self.assertEqual(1, http_metrics.server_response_status.get(fields)) self.assertLessEqual(3000, http_metrics.server_durations.get(fields).sum) self.assertEqual(len('success!'), http_metrics.server_response_bytes.get(fields).sum)