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

Fix fetch methods in services controller #14087

Merged
merged 1 commit into from
Mar 1, 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
6 changes: 3 additions & 3 deletions app/controllers/api/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ def validate_service(service)
end

def fetch_ext_management_system(data)
orchestration_manager_id = parse_id(data, :orchestration_manager)
orchestration_manager_id = parse_id(data, :providers)
raise BadRequestError, 'Missing ExtManagementSystem identifier id' if orchestration_manager_id.nil?
resource_search(orchestration_manager_id, :ext_management_systems, ExtManagementSystem)
end

def fetch_service(data)
service_id = parse_id(data, :service)
service_id = parse_id(data, :services)
raise BadRequestError, 'Missing Service identifier id' if service_id.nil?
resource_search(service_id, :services, Service)
end

def fetch_orchestration_template(data)
orchestration_template_id = parse_id(data, :orchestration_template)
orchestration_template_id = parse_id(data, :orchestration_templates)
raise BadRequestError, 'Missing OrchestrationTemplate identifier id' if orchestration_template_id.nil?
resource_search(orchestration_template_id, :orchestration_templates, OrchestrationTemplate)
end
Expand Down
42 changes: 42 additions & 0 deletions spec/requests/api/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
let(:svc) { FactoryGirl.create(:service, :name => "svc", :description => "svc description") }
let(:svc1) { FactoryGirl.create(:service, :name => "svc1", :description => "svc1 description") }
let(:svc2) { FactoryGirl.create(:service, :name => "svc2", :description => "svc2 description") }
let(:orchestration_template) { FactoryGirl.create(:orchestration_template) }
let(:ems) { FactoryGirl.create(:ext_management_system) }

describe "Services create" do
it "rejects requests without appropriate role" do
Expand Down Expand Up @@ -61,6 +63,46 @@
[{"name" => "svc_new_1"},
{"name" => "svc_new_2"}])
end

it 'supports creation of a single resource with href references' do
api_basic_authorize collection_action_identifier(:services, :create)

request = {
'action' => 'create',
'resource' => {
'type' => 'ServiceOrchestration',
'name' => 'svc_new',
'parent_service' => { 'href' => services_url(svc1.id)},
'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.id) },
'orchestration_manager' => { 'href' => providers_url(ems.id) }
}
}
expect do
run_post(services_url, request)
end.to change(Service, :count).by(1)
expect(response).to have_http_status(:ok)
expect_results_to_match_hash("results", [{"name" => "svc_new"}])
end

it 'supports creation of a single resource with id references' do
api_basic_authorize collection_action_identifier(:services, :create)

request = {
'action' => 'create',
'resource' => {
'type' => 'ServiceOrchestration',
'name' => 'svc_new',
'parent_service' => { 'id' => svc1.id},
'orchestration_template' => { 'id' => orchestration_template.id },
'orchestration_manager' => { 'id' => ems.id }
}
}
expect do
run_post(services_url, request)
end.to change(Service, :count).by(1)
expect(response).to have_http_status(:ok)
expect_results_to_match_hash("results", [{"name" => "svc_new"}])
end
end

describe "Services edit" do
Expand Down