diff options
Diffstat (limited to 'spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb | 118 |
1 files changed, 72 insertions, 46 deletions
diff --git a/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb b/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb index 7978f43610d..5ae0b8b10b6 100644 --- a/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb @@ -1,5 +1,53 @@ # frozen_string_literal: true +RSpec.shared_examples 'MLflow|an endpoint that requires authentication' do + context 'when not authenticated' do + let(:headers) { {} } + + it "is Unauthorized" do + is_expected.to have_gitlab_http_status(:unauthorized) + end + end + + context 'when user does not have access' do + let(:access_token) { tokens[:different_user] } + + it "is Not Found" do + is_expected.to have_gitlab_http_status(:not_found) + end + end +end + +RSpec.shared_examples 'MLflow|an endpoint that requires read_model_registry' do + context 'when user does not have read_model_registry' do + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?) + .with(current_user, :read_model_registry, project) + .and_return(false) + end + + it "is Not Found" do + is_expected.to have_gitlab_http_status(:not_found) + end + end +end + +RSpec.shared_examples 'MLflow|an endpoint that requires write_model_registry' do + context 'when user does not have read_model_registry' do + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?) + .with(current_user, :write_model_registry, project) + .and_return(false) + end + + it "is Not Found" do + is_expected.to have_gitlab_http_status(:unauthorized) + end + end +end + RSpec.shared_examples 'MLflow|Not Found - Resource Does Not Exist' do it "is Resource Does Not Exist", :aggregate_failures do is_expected.to have_gitlab_http_status(:not_found) @@ -44,21 +92,7 @@ RSpec.shared_examples 'MLflow|Bad Request' do end RSpec.shared_examples 'MLflow|shared error cases' do - context 'when not authenticated' do - let(:headers) { {} } - - it "is Unauthorized" do - is_expected.to have_gitlab_http_status(:unauthorized) - end - end - - context 'when user does not have access' do - let(:access_token) { tokens[:different_user] } - - it "is Not Found" do - is_expected.to have_gitlab_http_status(:not_found) - end - end + it_behaves_like 'MLflow|an endpoint that requires authentication' context 'when model experiments is unavailable' do before do @@ -75,34 +109,8 @@ RSpec.shared_examples 'MLflow|shared error cases' do end RSpec.shared_examples 'MLflow|shared model registry error cases' do - context 'when not authenticated' do - let(:headers) { {} } - - it "is Unauthorized" do - is_expected.to have_gitlab_http_status(:unauthorized) - end - end - - context 'when user does not have access' do - let(:access_token) { tokens[:different_user] } - - it "is Not Found" do - is_expected.to have_gitlab_http_status(:not_found) - end - end - - context 'when model registry is unavailable' do - before do - allow(Ability).to receive(:allowed?).and_call_original - allow(Ability).to receive(:allowed?) - .with(current_user, :read_model_registry, project) - .and_return(false) - end - - it "is Not Found" do - is_expected.to have_gitlab_http_status(:not_found) - end - end + it_behaves_like 'MLflow|an endpoint that requires authentication' + it_behaves_like 'MLflow|an endpoint that requires read_model_registry' end RSpec.shared_examples 'MLflow|Bad Request on missing required' do |keys| @@ -110,9 +118,27 @@ RSpec.shared_examples 'MLflow|Bad Request on missing required' do |keys| context "when \"#{key}\" is missing" do let(:params) { default_params.tap { |p| p.delete(key) } } - it "is Bad Request" do - is_expected.to have_gitlab_http_status(:bad_request) - end + it_behaves_like 'MLflow|Bad Request' end end end + +RSpec.shared_examples 'MLflow|an invalid request' do + it_behaves_like 'MLflow|Bad Request' +end + +RSpec.shared_examples 'MLflow|an authenticated resource' do + it_behaves_like 'MLflow|an endpoint that requires authentication' + it_behaves_like 'MLflow|Requires read_api scope' +end + +RSpec.shared_examples 'MLflow|a read-only model registry resource' do + it_behaves_like 'MLflow|an endpoint that requires authentication' + it_behaves_like 'MLflow|an endpoint that requires read_model_registry' +end + +RSpec.shared_examples 'MLflow|a read/write model registry resource' do + it_behaves_like 'MLflow|an endpoint that requires authentication' + it_behaves_like 'MLflow|an endpoint that requires read_model_registry' + it_behaves_like 'MLflow|an endpoint that requires write_model_registry' +end |