-
Notifications
You must be signed in to change notification settings - Fork 27
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 #292 from rwsu/frealms
API: frontend realms index, show, and entrypoint v2
- Loading branch information
Showing
12 changed files
with
154 additions
and
5 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
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,25 @@ | ||
# | ||
# Copyright 2012 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module FrontendRealmsHelper | ||
def api_frontend_realms_collection_href(provider_realm = nil) | ||
if provider_realm | ||
api_provider_realm_frontend_realms_url(provider_realm) | ||
else | ||
api_frontend_realms_url | ||
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,11 @@ | ||
!!! XML | ||
%frontend_realm{:id => frontend_realm.id, :href => api_frontend_realm_url(frontend_realm)} | ||
- unless shallow | ||
%name= frontend_realm.name | ||
%description= frontend_realm.description | ||
%provider_realms | ||
- frontend_realm.backend_realms.each do |prealm| | ||
%provider_realm{:id => prealm.id, :href => api_provider_realm_url(prealm)} | ||
%providers | ||
- frontend_realm.backend_providers.each do |provider| | ||
%provider{:id => provider.id, :href=> api_provider_url(provider)} |
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 @@ | ||
!!! XML | ||
%frontend_realms{ :href => frontend_realms_href } | ||
- realms.each do |frealm| | ||
=render '/frontend_realms/detail', :frontend_realm => frealm, :shallow => shallow |
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,3 @@ | ||
!!! XML | ||
=render 'list', :realms => @realms, :shallow => false, | ||
:frontend_realms_href => api_frontend_realms_collection_href(@provider_realm) |
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,2 @@ | ||
!!! XML | ||
=render 'detail', :frontend_realm => frontend_realm, :shallow => false |
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
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,89 @@ | ||
require 'spec_helper' | ||
|
||
describe "FrontendRealms" do | ||
let(:headers) { { | ||
'HTTP_ACCEPT' => 'application/xml', | ||
'CONTENT_TYPE' => 'application/xml' | ||
} } | ||
|
||
context "API" do | ||
before(:each) do | ||
user = FactoryGirl.create(:admin_permission).user | ||
login_as(user) | ||
@provider = FactoryGirl.create(:mock_provider) | ||
@provider_account = FactoryGirl.create(:mock_provider_account) | ||
@frontend_realm = FactoryGirl.create(:frontend_realm) | ||
# add provider realm | ||
@provider.provider_realms.each do |prealm| | ||
realm_backend_target = FactoryGirl.create(:realm_backend_target, :frontend_realm => @frontend_realm, :provider_realm_or_provider => prealm) | ||
@frontend_realm.realm_backend_targets << realm_backend_target | ||
#@frontend_realm.backend_realms << prealm | ||
end | ||
# add provider | ||
realm_backend_target = FactoryGirl.create(:realm_backend_target, :frontend_realm => @frontend_realm, :provider_realm_or_provider => @provider) | ||
@frontend_realm.realm_backend_targets << realm_backend_target | ||
end | ||
|
||
def check_frontend_realm_xml(xml_frontend_realm, frontend_realm) | ||
xml_frontend_realm.xpath("@id").text.should == frontend_realm.id.to_s | ||
xml_frontend_realm.xpath("@href").text.should == api_frontend_realm_url(frontend_realm) | ||
xml_frontend_realm.xpath("name").text.should == frontend_realm.name | ||
xml_frontend_realm.xpath("description").text.should == frontend_realm.description.to_s | ||
|
||
frontend_realm.backend_realms.each do |prealm| | ||
xml_frontend_realm.xpath("provider_realms/provider_realm[@id='#{prealm.id}']/@href"). | ||
text.should == api_provider_realm_url(prealm) | ||
end | ||
|
||
frontend_realm.backend_providers.each do |provider| | ||
xml_frontend_realm.xpath("providers/provider[@id='#{provider.id}']/@href"). | ||
text.should == api_provider_url(provider) | ||
end | ||
end | ||
|
||
describe "#index" do | ||
|
||
it "get index" do | ||
get "/api/frontend_realms", nil, headers | ||
|
||
response.should be_success | ||
response.should have_content_type("application/xml") | ||
response.body.should be_xml | ||
xml = Nokogiri::XML(response.body) | ||
|
||
xml.xpath("/frontend_realms/frontend_realm").size.should > 0 | ||
xml.xpath("/frontend_realms/frontend_realm").size.should eq FrontendRealm.all.size | ||
FrontendRealm.all.each do |frontend_realm| | ||
xml.xpath("/frontend_realms/frontend_realm[@id='#{frontend_realm.id}']/@href"). | ||
text.should == api_frontend_realm_url(frontend_realm.id) | ||
frontend_realm_xml = xml.xpath("/frontend_realms/frontend_realm[@id='#{frontend_realm.id}']") | ||
check_frontend_realm_xml(frontend_realm_xml, frontend_realm) | ||
end | ||
end | ||
end | ||
|
||
describe "#show" do | ||
|
||
it "show frontend realm" do | ||
@frontend_realm.backend_realms.size.should > 0 | ||
@frontend_realm.backend_providers.size.should > 0 | ||
|
||
get "/api/frontend_realms/#{@frontend_realm.id}", nil, headers | ||
response.should be_success | ||
response.should have_content_type("application/xml") | ||
response.body.should be_xml | ||
xml = Nokogiri::XML(response.body) | ||
|
||
check_frontend_realm_xml(xml.xpath("/frontend_realm"), @frontend_realm) | ||
end | ||
|
||
it "show nonexistent frontend realm" do | ||
get "/api/frontend_realms/-1", nil, headers | ||
response.status.should == 404 | ||
response.should have_content_type("application/xml") | ||
response.body.should be_xml | ||
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