From 00a99de5548296b9e4a797d204b1c86b8e440703 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Mon, 6 Nov 2017 16:30:05 -0500 Subject: [PATCH] Adds tests --- spec/requests/custom_actions_spec.rb | 303 +++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) diff --git a/spec/requests/custom_actions_spec.rb b/spec/requests/custom_actions_spec.rb index fe962b9293..d4e2176f73 100644 --- a/spec/requests/custom_actions_spec.rb +++ b/spec/requests/custom_actions_spec.rb @@ -220,4 +220,307 @@ def expect_result_to_have_custom_actions_hash expect(response.parsed_body).to include(expected) end end + + def define_custom_button1(resource) + dialog1 = FactoryGirl.create(:dialog, :label => "dialog1") + resource_action1 = FactoryGirl.create(:resource_action, :dialog_id => dialog1.id) + FactoryGirl.create(:custom_button, :name => "button1", :applies_to => resource, :userid => @user.userid, :resource_action => resource_action1) + end + + describe "Availability Zones" do + before(:each) do + @resource = FactoryGirl.create(:availability_zone) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:availability_zones, :read, :resource_actions, :get)) + + get api_availability_zone_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_availability_zone_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_availability_zone_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_availability_zone_url(nil, @resource)) + end + end + + describe "CloudSubnet" do + before(:each) do + @resource = FactoryGirl.create(:cloud_subnet) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:cloud_subnets, :read, :resource_actions, :get)) + + get api_cloud_subnet_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_cloud_subnet_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_cloud_subnet_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_subnet_url(nil, @resource)) + end + end + + describe "CloudTenant" do + before(:each) do + @resource = FactoryGirl.create(:cloud_tenant) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:cloud_tenants, :read, :resource_actions, :get)) + + get api_cloud_tenant_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_cloud_tenant_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_cloud_tenant_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_tenant_url(nil, @resource)) + end + end + + describe "CloudVolume" do + before(:each) do + @resource = FactoryGirl.create(:cloud_volume) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:cloud_volumes, :read, :resource_actions, :get)) + + get api_cloud_volume_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_cloud_volume_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_cloud_volume_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_volume_url(nil, @resource)) + end + end + + describe "ContainerNode" do + before(:each) do + @resource = FactoryGirl.create(:container_node) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:container_nodes, :read, :resource_actions, :get)) + + get api_container_node_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_container_node_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_container_node_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_container_node_url(nil, @resource)) + end + end + + describe "Host" do + before(:each) do + @resource = FactoryGirl.create(:host) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:hosts, :read, :resource_actions, :get)) + + get api_host_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_host_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_host_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_host_url(nil, @resource)) + end + end + + describe "LoadBalancer" do + before(:each) do + @resource = FactoryGirl.create(:load_balancer) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:load_balancers, :read, :resource_actions, :get)) + + get api_load_balancer_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_load_balancer_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_load_balancer_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_load_balancer_url(nil, @resource)) + end + end + + describe "NetworkRouter" do + before(:each) do + @resource = FactoryGirl.create(:network_router) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:network_routers, :read, :resource_actions, :get)) + + get api_network_router_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_network_router_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_network_router_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_network_router_url(nil, @resource)) + end + end + + describe "Tenant" do + before(:each) do + @resource = FactoryGirl.create(:tenant) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:tenants, :read, :resource_actions, :get)) + + get api_tenant_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_tenant_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_tenant_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_tenant_url(nil, @resource)) + end + end + + describe "User" do + before(:each) do + @resource = FactoryGirl.create(:user) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:users, :read, :resource_actions, :get)) + + get api_user_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_user_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_user_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_user_url(nil, @resource)) + end + end + + describe "Vms" do + before(:each) do + @resource = FactoryGirl.create(:vm) + define_custom_button1(@resource) + end + + it "queries return custom actions defined" do + api_basic_authorize(action_identifier(:vms, :read, :resource_actions, :get)) + + get api_vm_url(nil, @resource) + + expect(response.parsed_body).to include( + "id" => @resource.id.to_s, + "href" => api_vm_url(nil, @resource), + "actions" => a_collection_including(a_hash_including("name" => "button1")) + ) + end + + it "accept custom actions" do + api_basic_authorize + + post api_vm_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1") + + expect_single_action_result(:success => true, :message => /.*/, :href => api_vm_url(nil, @resource)) + end + end end