Skip to content

Commit

Permalink
Merge pull request #14087 from jntullo/bug/allow_for_parent_service
Browse files Browse the repository at this point in the history
Fix fetch methods in services controller
  • Loading branch information
Fryguy authored Mar 1, 2017
2 parents f1c27d2 + be5b23e commit 8cd3703
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
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

0 comments on commit 8cd3703

Please sign in to comment.