-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14731 from tzumainn/cloud-tenant-api
Add cloud tenants to API (cherry picked from commit 27e1ab0) https://bugzilla.redhat.com/show_bug.cgi?id=1458377
- Loading branch information
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Api | ||
class CloudTenantsController < BaseController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Api | ||
module Subcollections | ||
module CloudTenants | ||
def cloud_tenants_query_resource(object) | ||
object.cloud_tenants | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
RSpec.describe 'CloudTenants API' do | ||
describe 'GET /api/cloud_tenants' do | ||
it 'lists all cloud tenants with an appropriate role' do | ||
cloud_tenant = FactoryGirl.create(:cloud_tenant) | ||
api_basic_authorize collection_action_identifier(:cloud_tenants, :read, :get) | ||
run_get(cloud_tenants_url) | ||
|
||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'cloud_tenants', | ||
'resources' => [ | ||
hash_including('href' => a_string_matching(cloud_tenants_url(cloud_tenant.id))) | ||
] | ||
} | ||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
|
||
it 'forbids access to cloud tenants without an appropriate role' do | ||
api_basic_authorize | ||
|
||
run_get(cloud_tenants_url) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/cloud_tenants/:id' do | ||
it 'will show a cloud tenant with an appropriate role' do | ||
cloud_tenant = FactoryGirl.create(:cloud_tenant) | ||
api_basic_authorize action_identifier(:cloud_tenants, :read, :resource_actions, :get) | ||
|
||
run_get(cloud_tenants_url(cloud_tenant.id)) | ||
|
||
expect(response.parsed_body).to include('href' => a_string_matching(cloud_tenants_url(cloud_tenant.id))) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access to a cloud tenant without an appropriate role' do | ||
cloud_tenant = FactoryGirl.create(:cloud_tenant) | ||
api_basic_authorize | ||
|
||
run_get(cloud_tenants_url(cloud_tenant.id)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters