This patch seems to cause some breakage in the spec suite, after 
applying it I get errors such as the following:

ActiveRecord::RecordInvalid in 'CloudAccountsController should allow 
users with account modify permission to update a cloud account'
Validation failed: Login Credentials are Invalid for this Provider
/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1090:in
 
`save_without_dirty!'
.....
./spec/controllers/cloud_accounts_controller_spec.rb:7:

I'm not sure what is causing this, does the mock core driver currently 
accept any credentials for a cloud account?  (both my aggregator and 
core checkouts are up to date against repo heads)

Some comments inline below

On 05/13/2010 06:07 AM, [email protected] wrote:
> From: martyntaylor<[email protected]>
>
> ---
>   src/app/controllers/provider_controller.rb         |   11 ++++++++---
>   src/app/models/cloud_account.rb                    |   17 +++++++++++++++++
>   src/features/step_definitions/pool_steps.rb        |    2 +-
>   .../controllers/cloud_accounts_controller_spec.rb  |   11 +++++++++--
>   src/spec/factories/cloud_account.rb                |    4 ++--
>   src/spec/models/cloud_account_spec.rb              |   11 +++++++++++
>   6 files changed, 48 insertions(+), 8 deletions(-)
>
> diff --git a/src/app/controllers/provider_controller.rb 
> b/src/app/controllers/provider_controller.rb
> index 23b5ba0..092054c 100644
> --- a/src/app/controllers/provider_controller.rb
> +++ b/src/app/controllers/provider_controller.rb
> @@ -76,8 +76,13 @@ class ProviderController<  ApplicationController
>        require_privilege(Privilege::ACCOUNT_MODIFY)
>        @acct = CloudAccount.find_or_create(params[:cloud_account])
>        @provider = Provider.find(params[:cloud_account][:provider_id])
> -     @provider.cloud_accounts<<  @acct
> -     redirect_to :action =>  'accounts', :id =>  @provider.id
> +     if @acct.save
> +       @provider.cloud_accounts<<  @acct
> +       redirect_to :action =>  'accounts', :id =>  @provider.id
> +     else
> +       flash[:notice] = @acct.errors.full_messages[0]
> +       redirect_to :action =>  'new_account', :id =>  @provider.id
> +     end
>     end
>
> -end
> +end
> \ No newline at end of file
> diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
> index 1d6b3e9..29677c1 100644
> --- a/src/app/models/cloud_account.rb
> +++ b/src/app/models/cloud_account.rb
> @@ -67,4 +67,21 @@ class CloudAccount<  ActiveRecord::Base
>     def name
>       username
>     end
> +
> +  protected
> +  def validate
> +    errors.add_to_base("Login Credentials are Invalid for this Provider") 
> unless valid_credentials?
> +  end
> +
> +  private
> +  def valid_credentials?
> +    begin
> +      deltacloud = DeltaCloud.new(username, password, provider.url)
> +      #TODO This should be replaced by a DeltaCloud.test_credentials type 
> method once/if it is implemented in the API
> +      deltacloud.instances
> +    rescue Exception =>  e
> +      return false
> +    end
> +    return true
> +  end
>   end
> diff --git a/src/features/step_definitions/pool_steps.rb 
> b/src/features/step_definitions/pool_steps.rb
> index bd764ae..3d97da6 100644
> --- a/src/features/step_definitions/pool_steps.rb
> +++ b/src/features/step_definitions/pool_steps.rb
> @@ -15,7 +15,7 @@ Given /^the Pool has the following Hardware Profiles:$/ do 
> |table|
>   end
>
>   Given /^the Pool has the following Realms named "([^\"]*)"$/ do |names|
> -  @cloud_account = Factory :cloud_account
> +  @cloud_account = Factory :mock_cloud_account
>     @provider = @cloud_account.provider
>
>     names.split(", ").each do |name|
> diff --git a/src/spec/controllers/cloud_accounts_controller_spec.rb 
> b/src/spec/controllers/cloud_accounts_controller_spec.rb
> index f1d4a0d..c5e520e 100644
> --- a/src/spec/controllers/cloud_accounts_controller_spec.rb
> +++ b/src/spec/controllers/cloud_accounts_controller_spec.rb
> @@ -23,9 +23,9 @@ describe CloudAccountsController do
>
>     it "should allow users with account modify permission to update a cloud 
> account" do
>       UserSession.create(@admin)
> -    post :update, :cloud_account =>  { :id =>  @cloud_account.id, :password 
> =>  'foobar' }
> +    post :update, :cloud_account =>  { :id =>  @cloud_account.id, :password 
> =>  'mockpassword' }
>       response.should 
> redirect_to("http://test.host/provider/accounts/#[email protected]}";)
> -    CloudAccount.find(@cloud_account.id).password.should == "foobar"
> +    CloudAccount.find(@cloud_account.id).password.should == "mockpassword"
>     end
>    

I'm not sure if I understand the change to this test case. This should 
make sure that when :update is called with a new cloud account password, 
the database entry is updated. By changing the password used to update 
the entry to the original password, we can't verify the change is 
actually made.

>
>     it "should allow users with account modify permission to delete a cloud 
> account" do
> @@ -48,4 +48,11 @@ describe CloudAccountsController do
>       response.should_not be_success
>     end
>
> +  it "should fail to create a cloud account if the provider credentials are 
> invalid" do
> +    cloud_account = Factory.build(:mock_cloud_account)
> +    cloud_account.stub!(:valid_credentials?).and_return(false)
> +    cloud_account.save.should == false
> +  end
> +
> +
>    

Unless I'm misunderstanding this, there is a discrepancy between this 
test case and the one below. Here you instantiate :mock_cloud_account 
and make sure valid_credentials/valid is false. Below you do the same 
and make sure it is true. Am I missing something or is this a mistake?

>   end
> diff --git a/src/spec/factories/cloud_account.rb 
> b/src/spec/factories/cloud_account.rb
> index f494b52..b623b43 100644
> --- a/src/spec/factories/cloud_account.rb
> +++ b/src/spec/factories/cloud_account.rb
> @@ -5,7 +5,7 @@ Factory.define :cloud_account do |f|
>   end
>
>   Factory.define :mock_cloud_account, :parent =>  :cloud_account do |f|
> -  f.sequence(:username) { |n| "testMockUser#(n)" }
> -  f.password "testMockPassword"
> +  f.username "mockuser"
> +  f.password "mockpassword"
>     f.provider { |p| p.association(:mock_provider) }
>   end
> diff --git a/src/spec/models/cloud_account_spec.rb 
> b/src/spec/models/cloud_account_spec.rb
> index 0afe5a3..ded33c2 100644
> --- a/src/spec/models/cloud_account_spec.rb
> +++ b/src/spec/models/cloud_account_spec.rb
> @@ -18,4 +18,15 @@ describe CloudAccount do
>       @cloud_account.destroy
>       CloudAccount.find(:first, :conditions =>  ['id = ?', 
> @cloud_account.id]).should be_nil
>     end
> +
> +  it "should check the validitiy of the cloud account login credentials" do
> +    mock_provider = Factory :mock_provider
> +
> +    invalid_cloud_account = Factory.build(:cloud_account, :username =>  
> "wrong_username", :password =>  "wrong_password", :provider =>  mock_provider)
> +    invalid_cloud_account.should_not be_valid
> +
> +    valid_cloud_account = Factory.build(:mock_cloud_account, :provider =>  
> mock_provider)
> +    valid_cloud_account.should be_valid
> +  end
> +
>   end
>    

     -Mo
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to