Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from bdunne/request_cancel
Request cancel (cherry picked from commit 62de390) https://bugzilla.redhat.com/show_bug.cgi?id=1610533
- Loading branch information
Showing
20 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Api | ||
module Mixins | ||
module ResourceCancel | ||
def cancel_resource(type, id, _data) | ||
api_action(type, id) do |klass| | ||
resource_search(id, type, klass).cancel | ||
action_result(true, "#{klass.name} #{id} canceled") | ||
end | ||
rescue => err | ||
action_result(false, err.to_s) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module Api | ||
class RequestTasksController < BaseController | ||
include Api::Mixins::ResourceCancel | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RSpec.describe "Request Tasks API" do | ||
context "Resource#cancel" do | ||
let(:resource_1_response) { {"success" => false, "message" => "Cancel operation is not supported for MiqRequestTask"} } | ||
let(:resource_2_response) { {"success" => false, "message" => "Cancel operation is not supported for MiqRequestTask"} } | ||
include_context "Resource#cancel", "request_task", :miq_request_task | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FactoryGirl.modify do | ||
factory :miq_request do | ||
trait :with_api_user do | ||
requester { User.find_by(:name=>"API User") } | ||
end | ||
end | ||
|
||
factory :miq_request_task do | ||
trait :with_api_user do | ||
userid { User.find_by(:name=>"API User").userid } | ||
end | ||
end | ||
|
||
factory :service_order do | ||
trait :with_api_user do | ||
user { User.find_by(:name=>"API User") } | ||
end | ||
end | ||
|
||
factory :service_template do | ||
trait :with_api_user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
RSpec.shared_context "Resource#cancel" do |ns, factory| | ||
let(:collection_identifier) { namespace.pluralize.to_sym } | ||
let(:collection_url) { send("api_#{collection_identifier}_url") } | ||
let(:namespace) { ns } # ns is not available from #instance_url method, but namespace is. | ||
let(:resource_1) { FactoryGirl.create(factory, :with_api_user) } | ||
let(:resource_2) { FactoryGirl.create(factory, :with_api_user) } | ||
|
||
def instance_url(instance) | ||
send("api_#{namespace}_url", nil, instance) | ||
end | ||
|
||
context "on a single instance" do | ||
it "unauthorized" do | ||
expect_forbidden_request { post(instance_url(resource_1), :params => gen_request(:cancel)) } | ||
end | ||
|
||
it "authorized" do | ||
api_basic_authorize collection_action_identifier(collection_identifier, :cancel) | ||
|
||
post(instance_url(resource_1), :params => gen_request(:cancel)) | ||
|
||
expect_single_action_result(resource_1_response) | ||
end | ||
end | ||
|
||
context "on multiple instances" do | ||
it "unauthorized" do | ||
expect_forbidden_request { post(collection_url, :params => gen_request(:cancel, [{"href" => instance_url(resource_1)}, {"href" => instance_url(resource_2)}])) } | ||
end | ||
|
||
it "authorized" do | ||
api_basic_authorize collection_action_identifier(collection_identifier, :cancel) | ||
|
||
post(collection_url, :params => gen_request(:cancel, [{"href" => instance_url(resource_1)}, {"href" => instance_url(resource_2)}])) | ||
|
||
expect(response.parsed_body).to include("results" => a_collection_containing_exactly(resource_1_response, resource_2_response)) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
end |
Oops, something went wrong.