Skip to content

Commit

Permalink
Merge pull request #15070 from jntullo/enhancement/csp_subcollection
Browse files Browse the repository at this point in the history
configuration_script_sources subcollection
(cherry picked from commit 632c2d0)

https://bugzilla.redhat.com/show_bug.cgi?id=1459986
  • Loading branch information
abellotti authored and simaishi committed Jun 8, 2017
1 parent b434d12 commit 5f807cc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class ConfigurationScriptSourcesController < BaseController
include Subcollections::ConfigurationScriptPayloads

def edit_resource(type, id, data)
config_script_src = resource_search(id, type, collection_class(:configuration_script_sources))
raise "Update not supported for #{config_script_src_ident(config_script_src)}" unless config_script_src.respond_to?(:update_in_provider_queue)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module ConfigurationScriptPayloads
def configuration_script_payloads_query_resource(object)
object.configuration_script_payloads
end
end
end
end
7 changes: 7 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@
:description: Configuration Script Payloads
:options:
- :collection
- :subcollection
:verbs: *g
:klass: ConfigurationScriptPayload
:subcollections:
Expand All @@ -624,6 +625,10 @@
:get:
- :name: read
:identifier: embedded_configuration_script_payload_view
:subcollection_actions:
:get:
- :name: read
:identifier: embedded_configuration_script_payload_view
:authentications_subcollection_actions:
:get:
- :name: read
Expand All @@ -637,6 +642,8 @@
- :collection
:verbs: *gpppd
:klass: ConfigurationScriptSource
:subcollections:
- :configuration_script_payloads
:collection_actions:
:get:
- :name: read
Expand Down
51 changes: 51 additions & 0 deletions spec/requests/api/configuration_script_sources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,55 @@
expect(response).to have_http_status(:forbidden)
end
end

describe 'GET /api/configuration_script_sources/:id/configuration_script_payloads' do
let(:payload) { FactoryGirl.create(:configuration_script_payload) }
let(:url) { "#{configuration_script_sources_url(config_script_src.id)}/configuration_script_payloads" }

before do
config_script_src.configuration_script_payloads << payload
end

it 'forbids configuration_script_payload retrievel without an appropriate role' do
api_basic_authorize

run_get(url)

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

it 'lists all configuration_script_payloads belonging to a configuration_script_source' do
api_basic_authorize subcollection_action_identifier(:configuration_script_sources, :configuration_script_payloads, :read, :get)

run_get(url)

expected = {
'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'can filter on region_number' do
api_basic_authorize subcollection_action_identifier(:configuration_script_sources, :configuration_script_payloads, :read, :get)

run_get url, :filter => ["region_number=#{payload.region_number}"]

expected = {
'subcount' => 1,
'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)

run_get url, :filter => ["region_number=foo"]

expected = {
'subcount' => 0,
'resources' => []
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end

0 comments on commit 5f807cc

Please sign in to comment.