Skip to content

Commit

Permalink
Merge pull request #15450 from gildub/network_router-API-initial
Browse files Browse the repository at this point in the history
Network Routers REST API
  • Loading branch information
abellotti authored Jul 24, 2017
2 parents f3bf8c7 + cde93c5 commit 1e43457
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
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 @@ -1068,6 +1068,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 @@ -402,6 +402,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

0 comments on commit 1e43457

Please sign in to comment.