Skip to content

Commit e174d80

Browse files
authored
Merge pull request #981 from lfu/pxe_customization_template_907
Add endpoint for creating/updating/deleting PXE Customization Templates
2 parents b033430 + 83ab4a4 commit e174d80

File tree

3 files changed

+170
-3
lines changed

3 files changed

+170
-3
lines changed

config/api.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,17 +1346,40 @@
13461346
:identifier: customization_template_accord
13471347
:options:
13481348
- :collection
1349-
:verbs: *g
1349+
:verbs: *gpppd
13501350
:klass: CustomizationTemplate
13511351
:collection_actions:
13521352
:get:
13531353
- :name: read
13541354
:identifier: customization_template_view
1355-
:subcollection_actions:
1355+
:post:
1356+
- :name: query
1357+
:identifier: customization_template_view
1358+
- :name: create
1359+
:identifier: customization_template_new
1360+
- :name: edit
1361+
:identifier: customization_template_edit
1362+
- :name: delete
1363+
:identifier: customization_template_delete
1364+
:resource_actions:
13561365
:get:
13571366
- :name: read
13581367
:identifier: customization_template_view
1359-
:resource_actions:
1368+
:post:
1369+
- :name: edit
1370+
:identifier: customization_template_edit
1371+
- :name: delete
1372+
:identifier: customization_template_delete
1373+
:patch:
1374+
- :name: edit
1375+
:identifier: customization_template_edit
1376+
:put:
1377+
- :name: edit
1378+
:identifier: customization_template_edit
1379+
:delete:
1380+
- :name: delete
1381+
:identifier: customization_template_delete
1382+
:subcollection_actions:
13601383
:get:
13611384
- :name: read
13621385
:identifier: customization_template_view

spec/requests/collections_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
378378
test_collection_query(:customization_scripts, api_customization_scripts_url, CustomizationScript)
379379
end
380380

381+
it 'query CustomizationTemplates' do
382+
FactoryBot.create(:customization_template)
383+
test_collection_query(:customization_templates, api_customization_templates_url, CustomizationTemplate)
384+
end
385+
381386
it 'query GuestDevices' do
382387
FactoryBot.create(:guest_device)
383388
test_collection_query(:guest_devices, api_guest_devices_url, GuestDevice)
@@ -715,6 +720,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
715720
test_collection_bulk_query(:customization_scripts, api_customization_scripts_url, CustomizationScript)
716721
end
717722

723+
it 'bulk query CustomizationTemplates' do
724+
FactoryBot.create(:customization_template)
725+
test_collection_bulk_query(:customization_templates, api_customization_templates_url, CustomizationTemplate)
726+
end
727+
718728
it 'bulk query GuestDevices' do
719729
FactoryBot.create(:guest_device)
720730
test_collection_bulk_query(:guest_devices, api_guest_devices_url, GuestDevice)

spec/requests/customization_templates_spec.rb

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,138 @@
4242
expect(response).to have_http_status(:forbidden)
4343
end
4444
end
45+
46+
describe 'POST /api/customization_templates' do
47+
it 'forbids creating a customization template without an appropriate role' do
48+
api_basic_authorize
49+
post(api_customization_templates_url, :params => {:action => 'create'})
50+
expect(response).to have_http_status(:forbidden)
51+
end
52+
53+
it 'forbids updating a customization template without an appropriate role' do
54+
api_basic_authorize
55+
post(api_customization_templates_url, :params => {:action => 'edit'})
56+
expect(response).to have_http_status(:forbidden)
57+
end
58+
59+
it 'forbids deleting a customization template without an appropriate role' do
60+
api_basic_authorize
61+
post(api_customization_templates_url, :params => {:action => 'delete'})
62+
expect(response).to have_http_status(:forbidden)
63+
end
64+
65+
it 'creates a customization template with an appropriate role' do
66+
pxe_image_type = FactoryBot.create(:pxe_image_type)
67+
params = {
68+
"name" => 'name',
69+
"description" => 'description',
70+
"script" => 'test',
71+
"type" => 'CustomizationTemplateKickstart',
72+
"pxe_image_type_id" => pxe_image_type.id.to_s
73+
}
74+
api_basic_authorize collection_action_identifier(:customization_templates, :create)
75+
76+
post(api_customization_templates_url, :params => params)
77+
78+
expect(response).to have_http_status(:ok)
79+
expect(response.parsed_body["results"].first).to include(params)
80+
end
81+
82+
it 'updates a customization template with an appropriate role' do
83+
api_basic_authorize collection_action_identifier(:customization_templates, :edit)
84+
85+
post(api_customization_templates_url, :params => gen_request(:edit, 'id' => template.id, 'description' => 'description updated'))
86+
87+
expect(response).to have_http_status(:ok)
88+
expect(response.parsed_body["results"].first).to include('href' => api_customization_template_url(nil, template))
89+
expect(template.reload.description).to eq('description updated')
90+
end
91+
92+
it 'deletes a customization template with an appropriate role' do
93+
api_basic_authorize collection_action_identifier(:customization_templates, :delete)
94+
95+
post(api_customization_templates_url, :params => gen_request(:delete, 'id' => template.id, 'href' => api_customization_template_url(nil, template)))
96+
97+
expect(response).to have_http_status(:ok)
98+
expect(CustomizationTemplate.exists?(template.id)).to be false
99+
end
100+
end
101+
102+
describe 'POST /api/customization_templates/:id' do
103+
it 'forbids updating a customization template without an appropriate role' do
104+
api_basic_authorize
105+
post(api_customization_template_url(nil, template), :params => {:action => 'edit', :description => 'description updated'})
106+
expect(response).to have_http_status(:forbidden)
107+
end
108+
109+
it 'forbids deleting a customization template without an appropriate role' do
110+
api_basic_authorize
111+
post(api_customization_template_url(nil, template), :params => {:action => 'delete'})
112+
expect(response).to have_http_status(:forbidden)
113+
end
114+
115+
it 'updates a customization template with an appropriate role' do
116+
api_basic_authorize collection_action_identifier(:customization_templates, :edit)
117+
118+
post(api_customization_template_url(nil, template), :params => {:action => 'edit', :description => 'description updated'})
119+
120+
expect(template.reload.description).to eq('description updated')
121+
expect(response).to have_http_status(:ok)
122+
expect(response.parsed_body).to include('href' => api_customization_template_url(nil, template))
123+
end
124+
125+
it 'deletes a customization template with an appropriate role' do
126+
api_basic_authorize collection_action_identifier(:customization_templates, :delete)
127+
128+
expect do
129+
post(api_customization_template_url(nil, template), :params => {:action => 'delete'})
130+
end.to change(CustomizationTemplate, :count).by(-1)
131+
132+
expect(response).to have_http_status(:ok)
133+
end
134+
end
135+
136+
describe 'PUT /api/customization_templates/:id' do
137+
it 'updates a customization template with an appropriate role' do
138+
api_basic_authorize(action_identifier(:customization_templates, :edit))
139+
put(api_customization_template_url(nil, template), :params => {:description => 'description updated'})
140+
expect(response).to have_http_status(:ok)
141+
expect(template.reload.description).to eq('description updated')
142+
end
143+
144+
it 'forbids updating a customization template without an appropriate role' do
145+
api_basic_authorize
146+
put(api_customization_template_url(nil, template), :params => {:description => 'description updated'})
147+
expect(response).to have_http_status(:forbidden)
148+
end
149+
end
150+
151+
describe 'PATCH /api/customization_templates/:id' do
152+
it 'updates a customization template with an appropriate role' do
153+
api_basic_authorize(action_identifier(:customization_templates, :edit))
154+
patch(api_customization_template_url(nil, template), :params => {:description => 'description updated'})
155+
expect(response).to have_http_status(:ok)
156+
expect(template.reload.description).to eq('description updated')
157+
end
158+
159+
it 'forbids updating a customization template without an appropriate role' do
160+
api_basic_authorize
161+
patch(api_customization_template_url(nil, template), :params => {:description => 'description updated'})
162+
expect(response).to have_http_status(:forbidden)
163+
end
164+
end
165+
166+
describe 'DELETE /api/customization_templates/:id' do
167+
it "deletes a customization template with an appropriate role" do
168+
api_basic_authorize(action_identifier(:customization_templates, :delete))
169+
delete(api_customization_template_url(nil, template))
170+
expect(response).to have_http_status(:no_content)
171+
end
172+
173+
it 'forbids deleting a customization template without an appropriate role' do
174+
api_basic_authorize
175+
delete(api_customization_template_url(nil, template))
176+
expect(response).to have_http_status(:forbidden)
177+
end
178+
end
45179
end

0 commit comments

Comments
 (0)