def test_set_headers_overwrites(environ): def proxy(environ, start_response): start_response(200, [('extra', 'foo')]) return 'ok' stack = wsgi.set_headers(app, {'extra': 'header'}) env, status, headers = run_wsgi(stack, environ) assert headers['extra'] == 'header'
def test_middleware_overwrites_header(environ, id, monkeypatch): def proxy(environ, start_response): start_response(200, [('X-Request-Id', 'other-id')]) return 'ok' monkeypatch.setattr(request_id, 'generate', lambda: id) middleware = request_id.RequestIdMiddleware(proxy) body, status, headers = run_wsgi(middleware, environ) assert headers['X-Request-Id'] == id
def test_middleware_soft_request_timeout_disabled_by_default(environ, context): def app(environ, start_response): start_response(200, []) return [] mw = talisker.sentry.TaliskerSentryMiddleware(app) body, _, _ = run_wsgi(mw, environ) list(body) assert len(context.sentry) == 0
def test_middleware_soft_request_timeout(monkeypatch, environ, context): monkeypatch.setitem(os.environ, 'TALISKER_SOFT_REQUEST_TIMEOUT', '0') def app(environ, start_response): start_response(200, []) return [] mw = talisker.sentry.TaliskerSentryMiddleware(app) body, _, _ = run_wsgi(mw, environ) list(body) assert 'Start_response over timeout: 0' == context.sentry[0]['message'] assert 'warning' == context.sentry[0]['level']
def test_middleware_alt_header(environ, id): middleware = request_id.RequestIdMiddleware(app, 'X-Alternate') environ['HTTP_X_ALTERNATE'] = id body, status, headers = run_wsgi(middleware, environ) assert list(set(body)) == [id] assert headers['X-Alternate'] == id
def test_middleware_without_id(environ, id, monkeypatch): monkeypatch.setattr(request_id, 'generate', lambda: id) middleware = request_id.RequestIdMiddleware(app) body, status, headers = run_wsgi(middleware, environ) assert list(set(body)) == [id] assert headers['X-Request-Id'] == id
def test_middleware_with_id(environ, id): middleware = request_id.RequestIdMiddleware(app) environ['HTTP_X_REQUEST_ID'] = id body, status, headers = run_wsgi(middleware, environ) assert list(set(body)) == [id] assert headers['X-Request-Id'] == id
def test_set_headers(environ): stack = wsgi.set_headers(app, {'extra': 'header'}) env, status, headers = run_wsgi(stack, environ) assert headers['extra'] == 'header'
def test_set_environ(environ): stack = wsgi.set_environ(app, X=1) env, status, headers = run_wsgi(stack, environ) assert env['X'] == 1