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

[api] Collections API for Cloud Volumes #14260

Merged
merged 5 commits into from
Mar 15, 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/cloud_volumes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class CloudVolumesController < BaseController
end
end
18 changes: 18 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,24 @@
:get:
- :name: read
:identifier: miq_cloud_networks_view
:cloud_volumes:
:description: Cloud Volumes
:identifier: cloud_volume
:options:
- :collection
:verbs: *gp
:klass: CloudVolume
:collection_actions:
:get:
- :name: read
:identifier: cloud_volume_show_list
:post:
- :name: query
:identifier: cloud_volume_show_list
:resource_actions:
:get:
- :name: read
:identifier: cloud_volume
:clusters:
:description: Clusters
:identifier: ems_cluster
Expand Down
43 changes: 43 additions & 0 deletions spec/requests/api/cloud_volumes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# REST API Request Tests - Cloud Volumes
#
# Regions primary collections:
# /api/cloud_volumes
#
# Tests for:
# GET /api/cloud_volumes/:id
#

describe "Cloud Volumes API" do
it "forbids access to cloud volumes without an appropriate role" do
api_basic_authorize

run_get(cloud_volumes_url)

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

it "forbids access to a cloud volume resource without an appropriate role" do
api_basic_authorize

cloud_volume = FactoryGirl.create(:cloud_volume)

run_get(cloud_volumes_url(cloud_volume.id))

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

it "allows GETs of a cloud volume" do
api_basic_authorize action_identifier(:cloud_volumes, :read, :resource_actions, :get)

cloud_volume = FactoryGirl.create(:cloud_volume)

run_get(cloud_volumes_url(cloud_volume.id))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
"href" => a_string_matching(cloud_volumes_url(cloud_volume.id)),
"id" => cloud_volume.id
)
end
end
10 changes: 10 additions & 0 deletions spec/requests/api/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:clusters, clusters_url, EmsCluster)
end

it "query CloudVolumes" do
FactoryGirl.create(:cloud_volume)
test_collection_query(:cloud_volumes, cloud_volumes_url, CloudVolume)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add the other test for bulk queries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also probably need just the resource gets tests, look at spec/requests/api/regions_spec.rb and create a spec/requests/api/cloud_volumes_spec.rb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

it "query Conditions" do
FactoryGirl.create(:condition)
test_collection_query(:conditions, conditions_url, Condition)
Expand Down Expand Up @@ -570,5 +575,10 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
FactoryGirl.create(:load_balancer)
test_collection_bulk_query(:load_balancers, load_balancers_url, LoadBalancer)
end

it 'bulk query CloudVolumes' do
FactoryGirl.create(:cloud_volume)
test_collection_bulk_query(:cloud_volumes, cloud_volumes_url, CloudVolume)
end
end
end