ACK Though, as Ladislav suggested, we probably should move to using routes instead of specifying controllers and actions directly.
On 10/14/2010 01:41 PM, [email protected] wrote: > From: martyntaylor<[email protected]> > > --- > src/app/controllers/cloud_accounts_controller.rb | 45 +++++++++++++------- > src/app/controllers/provider_controller.rb | 34 +++++++++++---- > src/app/views/provider/_form.haml | 5 +- > src/app/views/provider/accounts.haml | 14 ++---- > src/features/provider.feature | 49 > +++++++++++++++++++++- > src/features/support/custom.rb | 3 - > 6 files changed, 111 insertions(+), 39 deletions(-) > > diff --git a/src/app/controllers/cloud_accounts_controller.rb > b/src/app/controllers/cloud_accounts_controller.rb > index f1c55b6..9d75347 100644 > --- a/src/app/controllers/cloud_accounts_controller.rb > +++ b/src/app/controllers/cloud_accounts_controller.rb > @@ -31,30 +31,36 @@ class CloudAccountsController< ApplicationController > def create > @provider = Provider.find(params[:cloud_account][:provider_id]) > require_privilege(Privilege::ACCOUNT_MODIFY,@provider) > - if not params[:cloud_account][:x509_cert_priv_file].nil? > + if params[:cloud_account]&& > !params[:cloud_account][:x509_cert_priv_file].blank? > params[:cloud_account][:x509_cert_priv] = > params[:cloud_account][:x509_cert_priv_file].read > end > params[:cloud_account].delete :x509_cert_priv_file > - if not params[:cloud_account][:x509_cert_pub_file].nil? > + if params[:cloud_account]&& > !params[:cloud_account][:x509_cert_pub_file].blank? > params[:cloud_account][:x509_cert_pub] = > params[:cloud_account][:x509_cert_pub_file].read > end > params[:cloud_account].delete :x509_cert_pub_file > @cloud_account = CloudAccount.new(params[:cloud_account]) > - unless @cloud_account.valid_credentials? > - flash[:notice] = "The entered credential information is incorrect" > - redirect_to :controller => "provider", :action => "accounts", :id => > @provider > + > + if params[:test_account] > + test_account(@cloud_account) > + redirect_to :controller => "provider", :action => "accounts", :id => > @provider, :cloud_account => params[:cloud_account] > else > - quota = Quota.new > - quota.maximum_running_instances = > quota_from_string(params[:quota][:maximum_running_instances]) > - quota.save! > - @cloud_account.quota_id = quota.id > - @cloud_account.zones<< Zone.default > - @cloud_account.save! > - if request.post?&& @cloud_account.save&& > @cloud_account.populate_realms > - flash[:notice] = "Provider account added." > + unless @cloud_account.valid_credentials? > + flash[:notice] = "The entered credential information is incorrect" > + redirect_to :controller => "provider", :action => "accounts", :id > => @provider > + else > + quota = Quota.new > + quota.maximum_running_instances = > quota_from_string(params[:quota][:maximum_running_instances]) > + quota.save! > + @cloud_account.quota_id = quota.id > + @cloud_account.zones<< Zone.default > + @cloud_account.save! > + if request.post?&& @cloud_account.save&& > @cloud_account.populate_realms > + flash[:notice] = "Provider account added." > + end > + redirect_to :controller => "provider", :action => "accounts", :id > => @provider > + kick_condor > end > - redirect_to :controller => "provider", :action => "accounts", :id => > @provider > - kick_condor > end > end > > @@ -126,6 +132,15 @@ class CloudAccountsController< ApplicationController > redirect_to :controller => 'provider', :action => 'accounts', :id => > provider.id > end > > + def test_account(account) > + if account.valid_credentials? > + flash[:notice] = "Test Connection Success: Valid Account Details" > + else > + flash[:notice] = "Test Connection Failed: Invalid Account Details" > + end > + rescue > + flash[:notice] = "Test Connection Failed: Could not connect to provider" > + end > private > > def quota_from_string(quota_raw) > diff --git a/src/app/controllers/provider_controller.rb > b/src/app/controllers/provider_controller.rb > index 7e7f3e5..189c5cb 100644 > --- a/src/app/controllers/provider_controller.rb > +++ b/src/app/controllers/provider_controller.rb > @@ -54,15 +54,21 @@ class ProviderController< ApplicationController > require_privilege(Privilege::PROVIDER_MODIFY) > @providers = Provider.list_for_user(@current_user, > Privilege::PROVIDER_MODIFY) > @provider = Provider.new(params[:provider]) > - @provider.set_cloud_type! > - if @provider.save&& @provider.populate_hardware_profiles > + > + if params[:test_connection] > + test_connection(@provider) > + redirect_to :action => "new", :provider => {:name => > @provider.name, :url => @provider.url} > + else > + @provider.set_cloud_type! > + if @provider.save&& @provider.populate_hardware_profiles > flash[:notice] = "Provider added." > redirect_to :action => "show", :id => @provider > - else > - flash[:notice] = "Cannot add the provider." > - render :action => "new" > + else > + flash[:notice] = "Cannot add the provider." > + render :action => "new" > + end > + kick_condor > end > - kick_condor > end > > def update > @@ -71,8 +77,8 @@ class ProviderController< ApplicationController > @provider.name = params[:provider][:name] > > if @provider.save > - flash[:notice] = "Provider updated." > - redirect_to :action => "show", :id => @provider > + flash[:notice] = "Provider updated." > + redirect_to :action => "show", :id => @provider > else > render :action => "edit" > end > @@ -104,6 +110,10 @@ class ProviderController< ApplicationController > def accounts > @provider = Provider.find(:first, :conditions => {:id => params[:id]}) > require_privilege(Privilege::ACCOUNT_VIEW, @provider) > + if params[:cloud_account] > + @cloud_account = CloudAccount.new(params[:cloud_account]) > + @quota = Quota.new(params[:quota]) > + end > end > > def realms > @@ -119,6 +129,14 @@ class ProviderController< ApplicationController > def list > end > > + def test_connection(provider) > + if @provider.connect > + flash[:notice] = "Successfuly Connected to Provider" > + else > + flash[:notice] = "Failed to Connect to Provider" > + end > + end > + > protected > def load_providers > @providers = Provider.list_for_user(@current_user, > Privilege::PROVIDER_VIEW) > diff --git a/src/app/views/provider/_form.haml > b/src/app/views/provider/_form.haml > index d0d1464..6f03d7d 100644 > --- a/src/app/views/provider/_form.haml > +++ b/src/app/views/provider/_form.haml > @@ -28,9 +28,10 @@ > - if controller.action_name == 'edit': > = f.hidden_field :id, :value => @provider.id > .clear.prefix_4.grid_5.suffix_4.alpha.omega > - %span > + - if !Provider.exists?(@provider) > + %span > ( > - %a{ :href => ''}<> > + %button.linkbutton.nospace{ :type => 'submit', :value => > t('.test_connection'), :name => 'test_connection', :id => 'test_connection' > }<> > = t('.test_connection') > ) > - unless readonly > diff --git a/src/app/views/provider/accounts.haml > b/src/app/views/provider/accounts.haml > index d2b979e..509e727 100644 > --- a/src/app/views/provider/accounts.haml > +++ b/src/app/views/provider/accounts.haml > @@ -61,11 +61,6 @@ > .grid_3.omega > %a.button{ :href => remove_path, :name => > "remove_acc_#{acct.id}", :class => "tiny #{'disabled' unless remove_path}" } > = t(:remove) > - %span > - ( > - %a{ :href => '' }<> > - = t('.test_account') > - ) > %fieldset.clearfix.gap > = submit_tag t(:reset), :name => 'reset_form', :class => > "dialogbutton" unless @provider.cloud_accounts.empty? > = submit_tag t(:save), :name => 'update_cloud_accounts', :class => > "dialogbutton" unless @provider.cloud_accounts.empty? > @@ -117,11 +112,10 @@ > = file_field :cloud_account, :x509_cert_pub_file, :title => > t('.account_public_cert') > - remove_path = url_for :controller => 'cloud_accounts', :action => > 'destroy' > .grid_3.omega > - %span > - ( > - %a{ :href => '' }<> > - = t('.test_account') > - ) > + ( > + %button.linkbutton.nospace{ :type => 'submit', :value => > t('.test_account'), :name => 'test_account', :id => 'test_account' }<> > + = t('.test_account') > + ) > %fieldset.clearfix > .grid_13.alpha.omega > = submit_tag t(:add), :class => "ra nomargin dialogbutton" > diff --git a/src/features/provider.feature b/src/features/provider.feature > index a544361..c332667 100644 > --- a/src/features/provider.feature > +++ b/src/features/provider.feature > @@ -26,7 +26,6 @@ Feature: Manage Providers > When I follow "testprovider" > Then I should see "Provider Name" > And I should see "Provider URL" > - And I should see "Test Connection" > > Scenario: Create a new Provider > Given I am on the providers page > @@ -39,3 +38,51 @@ Feature: Manage Providers > Then I should be on the show provider page > And I should see "Provider added" > And I should have a provider named "testprovider" > + > + Scenario: Test Provider Connection Successful > + Given I am on the providers page > + When I press "Add" > + Then I should be on the new provider page > + When I fill in "provider[name]" with "testprovider" > + And I fill in "provider[url]" with "http://localhost:3001/api" > + And I press "test_connection" > + Then I should see "Successfuly Connected to Provider" > + > + Scenario: Test Provider Connection Failure > + Given I am on the providers page > + When I press "Add" > + Then I should be on the new provider page > + When I fill in "provider[name]" with "incorrect_provider" > + And I fill in "provider[url]" with "http://incorrecthost:3001/api" > + And I press "test_connection" > + Then I should see "Failed to Connect to Provider" > + > + Scenario: Test Account Connection Success > + Given I am on the homepage > + And there are these providers: > + | name | > + | provider1 | > + When I go to the providers page > + And I follow "provider1" > + And I follow "Provider Accounts" > + And I fill in "cloud_account[label]" with "MockAccount" > + And I fill in "cloud_account[username]" with "mockuser" > + And I fill in "cloud_account[password]" with "mockpassword" > + And I fill in "cloud_account[account_number]" with "12345678" > + And I press "test_account" > + Then I should see "Test Connection Success: Valid Account Details" > + > + Scenario: Test Account Connection Failure > + Given I am on the homepage > + And there are these providers: > + | name | > + | provider1 | > + When I go to the providers page > + And I follow "provider1" > + And I follow "Provider Accounts" > + And I fill in "cloud_account[label]" with "IncorrectAccount" > + And I fill in "cloud_account[username]" with "incorrect_user" > + And I fill in "cloud_account[password]" with "incorrect_password" > + And I fill in "cloud_account[account_number]" with "12345678" > + And I press "test_account" > + Then I should see "Test Connection Failed: Invalid Account Details" > \ No newline at end of file > diff --git a/src/features/support/custom.rb b/src/features/support/custom.rb > index 46c618e..6e4e1ef 100644 > --- a/src/features/support/custom.rb > +++ b/src/features/support/custom.rb > @@ -28,9 +28,6 @@ Provider.class_eval do > end > > CloudAccount.class_eval do > - def valid_credentials? > - true > - end > > alias :generate_cloud_account_key_original :generate_cloud_account_key > _______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
