def test_failed_http_request(self, request): response = mock.MagicMock response.status_code = 404 response.text = '{"error_code": "RESOURCE_DOES_NOT_EXIST", "message": "No experiment"}' request.return_value = response store = RestStore(lambda: MlflowHostCreds("https://hello")) with pytest.raises(MlflowException) as cm: store.list_experiments() assert "RESOURCE_DOES_NOT_EXIST: No experiment" in str(cm.value)
def test_response_with_unknown_fields(self, request): experiment_json = { "experiment_id": "1", "name": "My experiment", "artifact_location": "foo", "lifecycle_stage": "deleted", "OMG_WHAT_IS_THIS_FIELD": "Hooly cow", } response = mock.MagicMock response.status_code = 200 experiments = {"experiments": [experiment_json]} response.text = json.dumps(experiments) request.return_value = response store = RestStore(lambda: MlflowHostCreds("https://hello")) experiments = store.list_experiments() assert len(experiments) == 1 assert experiments[0].name == "My experiment"
def test_successful_http_request(self, request): def mock_request(**kwargs): # Filter out None arguments kwargs = dict((k, v) for k, v in six.iteritems(kwargs) if v is not None) assert kwargs == { "method": "GET", "params": {"view_type": "ACTIVE_ONLY"}, "url": "https://hello/api/2.0/mlflow/experiments/list", "headers": _DEFAULT_HEADERS, "verify": True, } response = mock.MagicMock response.status_code = 200 response.text = '{"experiments": [{"name": "Exp!", "lifecycle_stage": "active"}]}' return response request.side_effect = mock_request store = RestStore(lambda: MlflowHostCreds("https://hello")) experiments = store.list_experiments() assert experiments[0].name == "Exp!"
def test_successful_http_request(self, request): 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 request.side_effect = mock_request store = RestStore(lambda: MlflowHostCreds("https://hello")) experiments = store.list_experiments() assert experiments[0].name == "Exp!"