diff options
Diffstat (limited to 'spec/requests/api/ml/mlflow/registered_models_spec.rb')
-rw-r--r-- | spec/requests/api/ml/mlflow/registered_models_spec.rb | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/spec/requests/api/ml/mlflow/registered_models_spec.rb b/spec/requests/api/ml/mlflow/registered_models_spec.rb index cd8b0a53ef3..09cf765b0b3 100644 --- a/spec/requests/api/ml/mlflow/registered_models_spec.rb +++ b/spec/requests/api/ml/mlflow/registered_models_spec.rb @@ -56,8 +56,8 @@ RSpec.describe API::Ml::Mlflow::RegisteredModels, feature_category: :mlops do end end - it_behaves_like 'MLflow|shared model registry error cases' - it_behaves_like 'MLflow|Requires read_api scope' + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read-only model registry resource' end end @@ -78,7 +78,7 @@ RSpec.describe API::Ml::Mlflow::RegisteredModels, feature_category: :mlops do context 'when the model name is not passed' do let(:params) { {} } - it_behaves_like 'MLflow|Bad Request' + it_behaves_like 'MLflow|an invalid request' end context 'when the model name already exists' do @@ -127,8 +127,8 @@ RSpec.describe API::Ml::Mlflow::RegisteredModels, feature_category: :mlops do end end - it_behaves_like 'MLflow|shared model registry error cases' - it_behaves_like 'MLflow|Requires api scope and write permission' + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read/write model registry resource' end end @@ -160,8 +160,8 @@ RSpec.describe API::Ml::Mlflow::RegisteredModels, feature_category: :mlops do end end - it_behaves_like 'MLflow|shared model registry error cases' - it_behaves_like 'MLflow|Requires api scope and write permission' + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read/write model registry resource' end end @@ -196,8 +196,88 @@ RSpec.describe API::Ml::Mlflow::RegisteredModels, feature_category: :mlops do end end - it_behaves_like 'MLflow|shared model registry error cases' - it_behaves_like 'MLflow|Requires read_api scope' + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read-only model registry resource' + end + end + + describe 'DELETE /projects/:id/ml/mlflow/api/2.0/mlflow/registered-models/delete' do + let(:model_name) { model.name } + let(:params) { { name: model_name } } + let(:route) { "/projects/#{project_id}/ml/mlflow/api/2.0/mlflow/registered-models/delete" } + let(:request) { delete api(route), params: params, headers: headers } + + it 'returns a success response', :aggregate_failures do + is_expected.to have_gitlab_http_status(:ok) + expect(json_response).to eq({}) + end + + describe 'Error States' do + context 'when destroy fails' do + it 'returns an error' do + allow(Ml::DestroyModelService).to receive_message_chain(:new, :execute).and_return(false) + + is_expected.to have_gitlab_http_status(:bad_request) + expect(json_response["message"]).to eq("Model could not be deleted") + end + end + + context 'when has access' do + context 'and model does not exist' do + let(:model_name) { 'foo' } + + it_behaves_like 'MLflow|Not Found - Resource Does Not Exist' + end + + context 'and name is not passed' do + let(:params) { {} } + + it_behaves_like 'MLflow|Not Found - Resource Does Not Exist' + end + end + + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read/write model registry resource' + end + end + + describe 'GET /projects/:id/ml/mlflow/api/2.0/mlflow/registered-models/search' do + let_it_be(:model2) do + create(:ml_models, :with_metadata, project: project) + end + + let(:route) { "/projects/#{project_id}/ml/mlflow/api/2.0/mlflow/registered-models/search" } + + it 'returns all the models', :aggregate_failures do + is_expected.to have_gitlab_http_status(:ok) + is_expected.to match_response_schema('ml/list_models') + expect(json_response["registered_models"].count).to be(2) + end + + context "with a valid filter supplied" do + let(:filter) { "name='#{model2.name}'" } + let(:route) { "/projects/#{project_id}/ml/mlflow/api/2.0/mlflow/registered-models/search?filter=#{filter}" } + + it 'returns only the models for the given filter' do + is_expected.to have_gitlab_http_status(:ok) + expect(json_response["registered_models"].count).to be(1) + end + end + + context "with an invalid filter supplied" do + let(:filter) { "description='foo'" } + let(:route) { "/projects/#{project_id}/ml/mlflow/api/2.0/mlflow/registered-models/search?filter=#{filter}" } + + it 'returns an error' do + is_expected.to have_gitlab_http_status(:bad_request) + + expect(json_response).to include({ 'error_code' => 'INVALID_PARAMETER_VALUE' }) + end + end + + describe 'Error States' do + it_behaves_like 'MLflow|an authenticated resource' + it_behaves_like 'MLflow|a read-only model registry resource' end end end |