Skip to content

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Nov 16, 2017
1 parent 2bb6a8c commit 215292f
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 15 deletions.
12 changes: 0 additions & 12 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@
:options:
- :collection
- :subcollection
- :custom_actions
:verbs: *gp
:klass: CloudNetwork
:collection_actions:
Expand Down Expand Up @@ -478,7 +477,6 @@
:options:
- :collection
- :subcollection
- :custom_actions
:verbs: *gp
:klass: CloudTenant
:subcollections:
Expand Down Expand Up @@ -507,7 +505,6 @@
:identifier: cloud_volume
:options:
- :collection
- :custom_actions
:verbs: *gpd
:klass: CloudVolume
:collection_actions:
Expand All @@ -534,7 +531,6 @@
:identifier: ems_cluster
:options:
- :collection
- :custom_actions
:verbs: *gp
:klass: EmsCluster
:subcollections:
Expand Down Expand Up @@ -699,7 +695,6 @@
:verbs: *gp
:options:
- :collection
- :custom_actions
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -806,7 +801,6 @@
:identifier: storage
:options:
- :collection
- :custom_actions
:verbs: *gp
:klass: Storage
:subcollections:
Expand Down Expand Up @@ -1022,7 +1016,6 @@
:options:
- :collection
- :subcollection
- :custom_actions
:verbs: *gpd
:klass: GenericObject
:subcollections:
Expand Down Expand Up @@ -1128,7 +1121,6 @@
:identifier: host
:options:
- :collection
- :custom_actions
:verbs: *gp
:klass: Host
:subcollections:
Expand Down Expand Up @@ -1477,7 +1469,6 @@
:description: Orchestration Stacks
:options:
- :subcollection
- :custom_actions
:verbs: *g
:klass: OrchestrationStack
:subcollection_actions:
Expand Down Expand Up @@ -1712,7 +1703,6 @@
:identifier: ems_infra
:options:
- :collection
- :custom_actions
:verbs: *gpd
:klass: ExtManagementSystem
:subcollections:
Expand Down Expand Up @@ -2450,7 +2440,6 @@
:identifier: service
:options:
- :collection
- :custom_actions
:verbs: *gpppd
:klass: Service
:subcollections:
Expand Down Expand Up @@ -2647,7 +2636,6 @@
:identifier: miq_template
:options:
- :collection
- :custom_actions
:verbs: *gpd
:klass: MiqTemplate
:subcollections:
Expand Down
228 changes: 225 additions & 3 deletions spec/requests/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def expect_result_to_have_custom_actions_hash
end

describe "Querying services with custom actions" do
before(:each) do
before do
create_custom_buttons
end

Expand Down Expand Up @@ -116,7 +116,7 @@ def expect_result_to_have_custom_actions_hash
end

describe "Querying service_templates with custom actions" do
before(:each) do
before do
create_custom_buttons
end

Expand Down Expand Up @@ -152,7 +152,7 @@ def expect_result_to_have_custom_actions_hash
end

describe "Services with custom actions" do
before(:each) do
before do
create_custom_buttons
button1.resource_action = FactoryGirl.create(:resource_action)
end
Expand Down Expand Up @@ -220,4 +220,226 @@ 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 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 "accepts 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 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 "accepts 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 "Group" do
before do
@resource = FactoryGirl.create(:miq_group)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:groups, :read, :resource_actions, :get))

get api_group_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_group_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accepts custom actions" do
api_basic_authorize

post api_group_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_group_url(nil, @resource))
end
end

describe "LoadBalancer" do
before 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 "accepts 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 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 "accepts 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 "Security Group" do
before do
@resource = FactoryGirl.create(:security_group)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:security_groups, :read, :resource_actions, :get))

get api_security_group_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_security_group_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accepts custom actions" do
api_basic_authorize

post api_security_group_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_security_group_url(nil, @resource))
end
end

describe "Tenant" do
before 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 "accepts 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 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 "accepts 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
end

0 comments on commit 215292f

Please sign in to comment.