def molten_client(headers=None):
    app = molten.App(routes=[molten.Route('/hello/{name}/{age}', hello)])
    client = TestClient(app)
    uri = app.reverse_uri('hello', name='Jim', age=24)
    if headers:
        return client.request('GET', uri, headers=headers)
    return client.get(uri)
Exemplo n.º 2
0
 def test_route_failure(self):
     app = molten.App(routes=[molten.Route('/hello/{name}/{age}', hello)])
     client = TestClient(app)
     response = client.get('/goodbye')
     spans = self.tracer.writer.pop()
     self.assertEqual(response.status_code, 404)
     span = spans[0]
     self.assertEqual(span.service, 'molten')
     self.assertEqual(span.name, 'molten.request')
     self.assertEqual(span.resource, 'GET 404')
     self.assertEqual(span.get_tag('http.url'), '/goodbye')
     self.assertEqual(span.get_tag('http.method'), 'GET')
     self.assertEqual(span.get_tag('http.status_code'), '404')
Exemplo n.º 3
0
 def test_route_failure(self):
     app = molten.App(routes=[molten.Route('/hello/{name}/{age}', hello)])
     client = TestClient(app)
     response = client.get('/goodbye')
     spans = self.tracer.writer.pop()
     self.assertEqual(response.status_code, 404)
     span = spans[0]
     assert_is_measured(span)
     self.assertEqual(span.service, 'molten')
     self.assertEqual(span.name, 'molten.request')
     self.assertEqual(span.resource, 'GET 404')
     self.assertEqual(span.get_tag(http.URL), 'http://127.0.0.1:8000/goodbye')
     self.assertEqual(span.get_tag('http.method'), 'GET')
     assert_span_http_status_code(span, 404)
Exemplo n.º 4
0
 def test_route_failure(self):
     app = molten.App(routes=[molten.Route("/hello/{name}/{age}", hello)])
     client = TestClient(app)
     response = client.get("/goodbye")
     spans = self.pop_spans()
     self.assertEqual(response.status_code, 404)
     span = spans[0]
     assert_is_measured(span)
     self.assertEqual(span.service, "molten")
     self.assertEqual(span.name, "molten.request")
     self.assertEqual(span.resource, "GET 404")
     self.assertEqual(span.get_tag(http.URL), "http://127.0.0.1:8000/goodbye")
     self.assertEqual(span.get_tag("http.method"), "GET")
     assert_span_http_status_code(span, 404)
Exemplo n.º 5
0
 def test_route_exception(self):
     def route_error() -> str:
         raise Exception('Error message')
     app = molten.App(routes=[molten.Route('/error', route_error)])
     client = TestClient(app)
     response = client.get('/error')
     spans = self.tracer.writer.pop()
     self.assertEqual(response.status_code, 500)
     span = spans[0]
     route_error_span = spans[-1]
     self.assertEqual(span.service, 'molten')
     self.assertEqual(span.name, 'molten.request')
     self.assertEqual(span.resource, 'GET /error')
     self.assertEqual(span.error, 1)
     # error tags only set for route function span and not root span
     self.assertIsNone(span.get_tag(errors.ERROR_MSG))
     self.assertEqual(route_error_span.get_tag(errors.ERROR_MSG), 'Error message')
Exemplo n.º 6
0
    def test_route_exception(self):
        def route_error() -> str:
            raise Exception("Error message")

        app = molten.App(routes=[molten.Route("/error", route_error)])
        client = TestClient(app)
        response = client.get("/error")
        spans = self.pop_spans()
        self.assertEqual(response.status_code, 500)
        span = spans[0]
        assert_is_measured(span)
        route_error_span = spans[-1]
        self.assertEqual(span.service, "molten")
        self.assertEqual(span.name, "molten.request")
        self.assertEqual(span.resource, "GET /error")
        self.assertEqual(span.error, 1)
        # error tags only set for route function span and not root span
        self.assertIsNone(span.get_tag(errors.ERROR_MSG))
        self.assertEqual(route_error_span.get_tag(errors.ERROR_MSG), "Error message")
Exemplo n.º 7
0
def molten_client(headers=None, params=None):
    app = molten.App(routes=[molten.Route("/hello/{name}/{age}", hello)])
    client = TestClient(app)
    uri = app.reverse_uri("hello", name="Jim", age=24)
    return client.request("GET", uri, headers=headers, params=params)
Exemplo n.º 8
0
import molten

from config import PING_MESSAGE


def ping():
    return PING_MESSAGE.format(app='molten')


app = molten.App(routes=[molten.Route('/', ping)])