Skip to content

Commit

Permalink
Merge pull request #292 from rwsu/frealms
Browse files Browse the repository at this point in the history
API: frontend realms index, show, and entrypoint v2
  • Loading branch information
Petr Blaho committed Jan 3, 2013
2 parents baa995a + 6a722fb commit 4417b74
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/app/controllers/frontend_realms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def index
clear_breadcrumbs
save_breadcrumb(frontend_realms_path)
set_admin_content_tabs 'frontend_realms'
load_backend_realms
respond_to do |format|
format.html
format.js { render :partial => 'list' }
format.xml { @provider_realm = @backend_realms.first if params[:provider_realm_id] }
end
end

Expand Down Expand Up @@ -126,6 +128,7 @@ def show
render :partial => @details_tab
end
format.json { render :json => @realm }
format.xml { render :show, :locals => { :frontend_realm => @realm } }
end
end

Expand Down
25 changes: 25 additions & 0 deletions src/app/helpers/frontend_realms_helper.rb
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
1 change: 1 addition & 0 deletions src/app/views/api/entrypoint/index.xml.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%catalogs{:href => api_catalogs_url}
%deployables{:href => api_deployables_url}
%deployments{:href => api_deployments_url}
%frontend_realms{:href => api_frontend_realms_url}
%images{:href => api_images_url}
%instances{:href => api_instances_url}
%pools{:href => api_pools_url}
Expand Down
11 changes: 11 additions & 0 deletions src/app/views/frontend_realms/_detail.xml.haml
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)}
4 changes: 4 additions & 0 deletions src/app/views/frontend_realms/_list.xml.haml
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
3 changes: 3 additions & 0 deletions src/app/views/frontend_realms/index.xml.haml
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)
2 changes: 2 additions & 0 deletions src/app/views/frontend_realms/show.xml.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!!! XML
=render 'detail', :frontend_realm => frontend_realm, :shallow => false
7 changes: 4 additions & 3 deletions src/app/views/provider_realms/_detail.xml.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
%provider_accounts
- @provider_accounts.each do |paccount|
%provider_account{:id => paccount.id, :href => api_provider_account_url(paccount)}
%frontend_realms
- @frontend_realms.each do |frontend_realm|
%frontend_realm{:id => frontend_realm.id}
=render '/frontend_realms/list',
:realms => provider_realm.frontend_realms,
:shallow => true,
:frontend_realms_href => api_provider_realm_frontend_realms_url(provider_realm)
%provider{:id => provider_realm.provider.id, :href => api_provider_url(provider_realm.provider)}
5 changes: 4 additions & 1 deletion src/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,11 @@
resources :instances, :only => [:index]
end
resources :deployables, :only => [:index, :show, :destroy]
resources :provider_realms, :only => [:index, :show]
resources :provider_realms, :only => [:index, :show] do
resources :frontend_realms, :only => [:index]
end
resources :instances, :only => [:index, :show]
resources :frontend_realms, :only => [:index, :show]
end

#match 'matching_profiles', :to => '/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller => 'hardware_profiles', :action => 'matching_profiles', :conditions => { :method => :get }, :as =>'matching_profiles'
Expand Down
3 changes: 2 additions & 1 deletion src/spec/controllers/api/entrypoint_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
api = resp['api']
api['builds']['href'].should == api_builds_url
api['catalogs']['href'].should == api_catalogs_url
api['deployments']['href'].should == api_deployments_url
api['deployables']['href'].should == api_deployables_url
api['deployments']['href'].should == api_deployments_url
api['frontend_realms']['href'].should == api_frontend_realms_url
api['images']['href'].should == api_images_url
api['instances']['href'].should == api_instances_url
api['pools']['href'].should == api_pools_url
Expand Down
89 changes: 89 additions & 0 deletions src/spec/requests/api/frontend_realms_spec.rb
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
6 changes: 6 additions & 0 deletions src/spec/requests/api/provider_realms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
text.should == api_provider_url(@provider)
xml.xpath("/provider_realm/provider_accounts/provider_account[@id='#{@provider_account.id}']/@href").
text.should == api_provider_account_url(@provider_account)

xml.xpath("/provider_realm/frontend_realms/@href").text.should == api_provider_realm_frontend_realms_url(provider_realm)
provider_realm.frontend_realms.size.should > 0
provider_realm.frontend_realms.each do |frealm|
xml.xpath("/provider_realm/frontend_realms/frontend_realm[@id='#{frealm.id}']/@href").text.should == api_frontend_realm_url(frealm)
end
end

it "show nonexistent provider realm" do
Expand Down

0 comments on commit 4417b74

Please sign in to comment.