def test_query_api_key_is_sent_in_api_key_by_default(httpx_mock: HTTPXMock): auth = httpx_auth.QueryApiKey("my_provided_api_key") # Mock a dummy response httpx_mock.add_response( url="http://authorized_only?api_key=my_provided_api_key") # Send a request to this dummy URL with authentication httpx.get("http://authorized_only", auth=auth)
def test_query_api_key_and_multiple_authentication_can_be_combined( token_cache, httpx_mock: HTTPXMock): api_key_auth = httpx_auth.QueryApiKey("my_provided_api_key") api_key_auth2 = httpx_auth.QueryApiKey("my_provided_api_key2", query_parameter_name="api_key2") api_key_auth3 = httpx_auth.HeaderApiKey("my_provided_api_key3", header_name="X-Api-Key3") # Mock a dummy response httpx_mock.add_response( url= "http://authorized_only?api_key=my_provided_api_key&api_key2=my_provided_api_key2", match_headers={"X-Api-Key3": "my_provided_api_key3"}) # Send a request to this dummy URL with authentication httpx.get("http://authorized_only", auth=api_key_auth + (api_key_auth2 + api_key_auth3))
def test_query_api_key_can_be_sent_in_a_custom_field_name(httpx_mock: HTTPXMock): auth = httpx_auth.QueryApiKey("my_provided_api_key", "X-API-QUERY-KEY") # Mock a dummy response httpx_mock.add_response( url="http://authorized_only?X-API-QUERY-KEY=my_provided_api_key" ) # Send a request to this dummy URL with authentication httpx.get("http://authorized_only", auth=auth)
def test_query_api_key_requires_an_api_key(): with pytest.raises(Exception) as exception_info: httpx_auth.QueryApiKey(None) assert str(exception_info.value) == "API Key is mandatory."