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

Network Routers REST API #15450

Merged
merged 2 commits into from
Jul 24, 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/network_routers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class NetworkRoutersController < BaseController
end
end
18 changes: 18 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,24 @@
- :collection
:verbs: *g
:klass: ChargebackRateDetailMeasure
:network_routers:
:description: Network_Routers
:identifier: network_router
:options:
- :collection
:verbs: *gp
:klass: NetworkRouter
:collection_actions:
:get:
- :name: read
:identifier: network_router_show_list
:post:
- :name: query
:identifier: network_router_show_list
:resource_actions:
:get:
- :name: read
:identifier: network_router_show
:notifications:
:description: "User's past notifications"
:options:
Expand Down
5 changes: 5 additions & 0 deletions spec/requests/api/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_bulk_query(:hosts, hosts_url, Host)
end

it 'bulk query NetworkRouters' do
FactoryGirl.create(:network_router)
test_collection_bulk_query(:network_routers, network_routers_url, NetworkRouter)
end

it "bulk query Policies" do
FactoryGirl.create(:miq_policy)
test_collection_bulk_query(:policies, policies_url, MiqPolicy)
Expand Down
51 changes: 51 additions & 0 deletions spec/requests/api/network_routers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
RSpec.describe 'NetworkRouters API' do
describe 'GET /api/network_routers' do
it 'lists all cloud subnets with an appropriate role' do
network_router = FactoryGirl.create(:network_router)
api_basic_authorize collection_action_identifier(:network_routers, :read, :get)
run_get(network_routers_url)

expected = {
'count' => 1,
'subcount' => 1,
'name' => 'network_routers',
'resources' => [
hash_including('href' => a_string_matching(network_routers_url(network_router.id)))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'forbids access to cloud subnets without an appropriate role' do
api_basic_authorize
run_get(network_routers_url)
expect(response).to have_http_status(:forbidden)
end
end

describe 'GET /api/network_routers/:id' do
it 'will show a cloud subnet with an appropriate role' do
network_router = FactoryGirl.create(:network_router)
api_basic_authorize action_identifier(:network_routers, :read, :resource_actions, :get)
run_get(network_routers_url(network_router.id))
expect(response.parsed_body).to include('href' => a_string_matching(network_routers_url(network_router.id)))
expect(response).to have_http_status(:ok)
end

it 'forbids access to a cloud tenant without an appropriate role' do
network_router = FactoryGirl.create(:network_router)
api_basic_authorize
run_get(network_routers_url(network_router.id))
expect(response).to have_http_status(:forbidden)
end
end

describe 'POST /api/network_routers' do
it 'forbids access to network routers without an appropriate role' do
api_basic_authorize
run_post(network_routers_url, gen_request(:query, ""))
expect(response).to have_http_status(:forbidden)
end
end
end