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)
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')
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)
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)
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')
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")
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)
import molten from config import PING_MESSAGE def ping(): return PING_MESSAGE.format(app='molten') app = molten.App(routes=[molten.Route('/', ping)])