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

Add support for /api/orchestration_stacks #196

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions app/controllers/api/orchestration_stacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class OrchestrationStacksController < BaseController
end
end
22 changes: 18 additions & 4 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1590,18 +1590,32 @@
- :name: delete
:orchestration_stacks:
:description: Orchestration Stacks
:identifier: orchestration_stack
:verbs: *gp
:klass: OrchestrationStack
:options:
- :collection
- :subcollection
:verbs: *g
:klass: OrchestrationStack
- :custom_actions
:collection_actions:
:get:
- :name: read
:identifier: orchestration_stack_show_list
:post:
- :name: query
:identifier: orchestration_stack_show_list
:resource_actions:
:get:
- :name: read
:identifier: orchestration_stack_show
:subcollection_actions:
:get:
- :name: read
:identifier: orchestration_stack_view
:identifier: orchestration_stack_show
:subresource_actions:
:get:
- :name: read
:identifier: orchestration_stack_view
:identifier: orchestration_stack_show
:orchestration_templates:
:description: Orchestration Template
:identifier: orchestration_templates_accord
Expand Down
10 changes: 10 additions & 0 deletions spec/requests/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
FactoryGirl.create(:switch)
test_collection_query(:switches, api_switches_url, Switch)
end

it 'query OrchestrationStacks' do
FactoryGirl.create(:orchestration_stack)
test_collection_query(:orchestration_stacks, api_orchestration_stacks_url, OrchestrationStack)
end
end

context "Collections Bulk Queries" do
Expand Down Expand Up @@ -729,5 +734,10 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
FactoryGirl.create(:switch)
test_collection_bulk_query(:switches, api_switches_url, Switch)
end

it 'bulk query orchestration stacks' do
FactoryGirl.create(:orchestration_stack)
test_collection_bulk_query(:orchestration_stacks, api_orchestration_stacks_url, OrchestrationStack)
end
end
end
27 changes: 27 additions & 0 deletions spec/requests/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,33 @@ def define_custom_button1(resource)
end
end

describe "Orchestration Stacks" do
before(:each) do
@resource = FactoryGirl.create(:orchestration_stack)
@button = define_custom_button1(@resource)
end

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

get api_orchestration_stack_url(nil, @resource)

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

it "accept custom actions" do
api_basic_authorize

post api_orchestration_stack_url(nil, @resource), :params => gen_request(@button.name, "key1" => "value1")

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

describe "Storage" do
before do
@resource = FactoryGirl.create(:storage)
Expand Down
48 changes: 48 additions & 0 deletions spec/requests/orchestration_stacks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe "Orchestration Stacks API" do
context 'GET /api/orchestration_stacks' do
it 'forbids access to orchestration_stacks without an appropriate role' do
api_basic_authorize

get(api_orchestration_stacks_url)

expect(response).to have_http_status(:forbidden)
end

it 'returns orchestration_stacks with an appropriate role' do
orchestration_stack = FactoryGirl.create(:orchestration_stack)
api_basic_authorize(collection_action_identifier(:orchestration_stacks, :read, :get))

get(api_orchestration_stacks_url)

expected = {
'resources' => [{'href' => api_orchestration_stack_url(nil, orchestration_stack)}]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

context 'GET /api/orchestration_stacks' do
let(:orchestration_stack) { FactoryGirl.create(:orchestration_stack) }

it 'forbids access to a orchestration_stack without an appropriate role' do
api_basic_authorize

get(api_orchestration_stack_url(nil, orchestration_stack))

expect(response).to have_http_status(:forbidden)
end

it 'returns the orchestration_stack with an appropriate role' do
api_basic_authorize(action_identifier(:orchestration_stacks, :read, :resource_actions, :get))

get(api_orchestration_stack_url(nil, orchestration_stack))

expected = {
'href' => api_orchestration_stack_url(nil, orchestration_stack)
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end