Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom actions for Vms API #14817

Merged
merged 4 commits into from
Apr 26, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable custom actions in the Vms API
  • Loading branch information
imtayadeway committed Apr 26, 2017
commit f349450efbf5255642c485e8e3ce8be2fa1bba38
1 change: 1 addition & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
@@ -2259,6 +2259,7 @@
:identifier: vm
:options:
- :collection
- :custom_actions
:verbs: *gpd
:klass: Vm
:subcollections:
89 changes: 89 additions & 0 deletions spec/requests/api/vms_spec.rb
Original file line number Diff line number Diff line change
@@ -1431,4 +1431,93 @@ def update_raw_power_state(state, *vms)
expect(vm2.tags.count).to eq(0)
end
end

describe "custom actions" do
it "renders custom actions" do
vm = FactoryGirl.create(:vm_vmware)
FactoryGirl.create(
:custom_button_set,
:members => [FactoryGirl.create(:custom_button, :name => "test button", :applies_to_class => "Vm")],
)
api_basic_authorize(action_identifier(:vms, :read, :resource_actions, :get))

run_get(vms_url(vm.id))

expected = {
"actions" => a_collection_including(
a_hash_including("name" => "test button")
)
}
expect(response.parsed_body).to include(expected)
end

it "renders the custom actions when requested" do
vm = FactoryGirl.create(:vm_vmware)
FactoryGirl.create(
:custom_button_set,
:name => "test button group",
:members => [FactoryGirl.create(:custom_button, :name => "test button", :applies_to_class => "Vm")]
)
api_basic_authorize(action_identifier(:vms, :read, :resource_actions, :get))

run_get(vms_url(vm.id), :attributes => "custom_actions")

expected = {
"custom_actions" => a_hash_including(
"button_groups" => [
a_hash_including(
"name" => "test button group",
"buttons" => [
a_hash_including("name" => "test button")
]
)
]
)
}
expect(response.parsed_body).to include(expected)
end

it "renders the custom action buttons when requested" do
vm = FactoryGirl.create(:vm_vmware)
FactoryGirl.create(
:custom_button_set,
:members => [FactoryGirl.create(:custom_button, :name => "test button", :applies_to_class => "Vm")]
)
api_basic_authorize(action_identifier(:vms, :read, :resource_actions, :get))

run_get(vms_url(vm.id), :attributes => "custom_action_buttons")

expected = {
"custom_action_buttons" => a_collection_containing_exactly(
a_hash_including("name" => "test button"),
)
}
expect(response.parsed_body).to include(expected)
end

it "can execute a custom action" do
vm = FactoryGirl.create(:vm_vmware)
FactoryGirl.create(
:custom_button_set,
:members => [
FactoryGirl.create(
:custom_button,
:name => "test button",
:applies_to_class => "Vm",
:resource_action => FactoryGirl.create(:resource_action)
)
]
)
api_basic_authorize

run_post(vms_url(vm.id), :action => "test button", :button_key1 => "foo")

expected = {
"success" => true,
"message" => "Invoked custom action test button for vms id: #{vm.id}",
"href" => a_string_matching(vms_url(vm.id))
}
expect(response.parsed_body).to include(expected)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you prefer to move these tests to custom_actions_spec.rb ? maybe some stuff can be DRYed up in future PRs between services and vms custom actions specs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might, but prefer to do that in a future PR. The current specs there are set up assuming that the service template is at the center of what's being tested, so would at least need to scope the existing tests in a new context. The resultant diff I thought would be unnecessarily large for this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end