def test_http_request_with_insecure(request): host_only = MlflowHostCreds("http://my-host", ignore_tls_verification=True) response = mock.MagicMock() response.status_code = 200 request.return_value = response http_request(host_only, "/my/endpoint", "GET") request.assert_called_with( "GET", "http://my-host/my/endpoint", verify=False, headers=DefaultRequestHeaderProvider().request_headers(), timeout=120, )
def test_http_request_cleans_hostname(request): # Add a trailing slash, should be removed. host_only = MlflowHostCreds("http://my-host/") response = mock.MagicMock() response.status_code = 200 request.return_value = response http_request(host_only, "/my/endpoint", "GET") request.assert_called_with( "GET", "http://my-host/my/endpoint", verify=True, headers=DefaultRequestHeaderProvider().request_headers(), timeout=120, )
def test_http_request_with_token(request): host_only = MlflowHostCreds("http://my-host", token="my-token") response = mock.MagicMock() response.status_code = 200 request.return_value = response http_request(host_only, "/my/endpoint", "GET") headers = DefaultRequestHeaderProvider().request_headers() headers["Authorization"] = "Bearer my-token" request.assert_called_with( "GET", "http://my-host/my/endpoint", verify=True, headers=headers, timeout=120, )
def test_http_request_with_basic_auth(request): host_only = MlflowHostCreds("http://my-host", username="******", password="******") response = mock.MagicMock() response.status_code = 200 request.return_value = response http_request(host_only, "/my/endpoint", "GET") headers = DefaultRequestHeaderProvider().request_headers() headers["Authorization"] = "Basic dXNlcjpwYXNz" request.assert_called_with( "GET", "http://my-host/my/endpoint", verify=True, headers=headers, timeout=120, )
def mock_request(*args, **kwargs): # Filter out None arguments assert args == ("GET", "https://hello/api/2.0/mlflow/experiments/list") kwargs = dict((k, v) for k, v in kwargs.items() if v is not None) assert kwargs == { "params": { "view_type": "ACTIVE_ONLY" }, "headers": DefaultRequestHeaderProvider().request_headers(), "verify": True, "timeout": 120, } response = mock.MagicMock() response.status_code = 200 response.text = '{"experiments": [{"name": "Exp!", "lifecycle_stage": "active"}]}' return response
def test_default_request_header_provider_in_context(): assert DefaultRequestHeaderProvider().in_context()
def test_default_request_header_provider_request_headers(): request_headers = DefaultRequestHeaderProvider().request_headers() assert request_headers == _DEFAULT_HEADERS