def test_generate_headers_sets_request_id_if_in_request_context(app_):
    api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')

    with app_.test_request_context() as request_context:
        headers = api_client.generate_headers('api_token')

    assert set(headers.keys()) == {'Authorization', 'Content-type', 'User-agent', 'NotifyRequestID'}
    assert headers['NotifyRequestID'] == request_context.request.request_id
예제 #2
0
def test_generate_headers_sets_request_id_if_in_request_context(app_):
    api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')

    with app_.test_request_context() as request_context:
        headers = api_client.generate_headers('api_token')

    assert set(headers.keys()) == {
        'Authorization', 'Content-type', 'User-agent', 'NotifyRequestID'
    }
    assert headers['NotifyRequestID'] == request_context.request.request_id
def test_generate_headers_sets_standard_headers():
    api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')

    # with patch('app.notify_client.has_request_context', return_value=False):
    headers = api_client.generate_headers('api_token')

    assert set(headers.keys()) == {'Authorization', 'Content-type', 'User-agent'}
    assert headers['Authorization'] == 'Bearer api_token'
    assert headers['Content-type'] == 'application/json'
    assert headers['User-agent'].startswith('NOTIFY-API-PYTHON-CLIENT')
예제 #4
0
def test_generate_headers_sets_standard_headers():
    api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')

    # with patch('app.notify_client.has_request_context', return_value=False):
    headers = api_client.generate_headers('api_token')

    assert set(
        headers.keys()) == {'Authorization', 'Content-type', 'User-agent'}
    assert headers['Authorization'] == 'Bearer api_token'
    assert headers['Content-type'] == 'application/json'
    assert headers['User-agent'].startswith('NOTIFY-API-PYTHON-CLIENT')
예제 #5
0
def test_generate_headers_sets_standard_headers(app_):
    api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
    with set_config(app_, 'ROUTE_SECRET_KEY_1', 'proxy-secret'):
        api_client.init_app(app_)

    # with patch('app.notify_client.has_request_context', return_value=False):
    headers = api_client.generate_headers('api_token')

    assert set(headers.keys()) == {
        'Authorization', 'Content-type', 'User-agent', 'X-Custom-Forwarder'
    }
    assert headers['Authorization'] == 'Bearer api_token'
    assert headers['Content-type'] == 'application/json'
    assert headers['User-agent'].startswith('NOTIFY-API-PYTHON-CLIENT')
    assert headers['X-Custom-Forwarder'] == 'proxy-secret'
예제 #6
0
def test_generate_headers_sets_request_id_if_in_request_context(app_):
    api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
    api_client.init_app(app_)

    with app_.test_request_context() as request_context:
        headers = api_client.generate_headers('api_token')

    assert set(headers.keys()) == {
        'Authorization',
        'Content-type',
        'User-agent',
        'X-Custom-Forwarder',
        'X-B3-TraceId',
        'X-B3-SpanId',
    }
    assert headers['X-B3-TraceId'] == request_context.request.request_id
    assert headers['X-B3-SpanId'] == request_context.request.span_id
def test_generate_headers_sets_request_id_if_in_request_context(app_):
    api_client = NotifyAdminAPIClient()
    api_client.init_app(app_)

    with app_.test_request_context() as request_context:
        headers = api_client.generate_headers("api_token")

    assert set(headers.keys()) == {
        "Authorization",
        "Content-type",
        "User-agent",
        "X-Custom-Forwarder",
        "X-B3-TraceId",
        "X-B3-SpanId",
    }
    assert headers["X-B3-TraceId"] == request_context.request.request_id
    assert headers["X-B3-SpanId"] == request_context.request.span_id
def test_generate_headers_sets_standard_headers(app_):
    api_client = NotifyAdminAPIClient()
    with set_config(app_, "ROUTE_SECRET_KEY_1", "proxy-secret"):
        api_client.init_app(app_)

    # with patch('app.notify_client.has_request_context', return_value=False):
    headers = api_client.generate_headers("api_token")

    assert set(headers.keys()) == {
        "Authorization",
        "Content-type",
        "User-agent",
        "X-Custom-Forwarder",
    }
    assert headers["Authorization"] == "Bearer api_token"
    assert headers["Content-type"] == "application/json"
    assert headers["User-agent"].startswith("NOTIFY-API-PYTHON-CLIENT")
    assert headers["X-Custom-Forwarder"] == "proxy-secret"