Exemplo n.º 1
0
  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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
  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))
Exemplo n.º 6
0
  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))
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
  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))
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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))
Exemplo n.º 11
0
  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)
Exemplo n.º 12
0
  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))
Exemplo n.º 13
0
  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)
Exemplo n.º 14
0
    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)