[PATCH conductor 1/3] Features for Provider Accounts API update action
pblaho at redhat.com
pblaho at redhat.com
Wed Aug 15 23:30:38 UTC 2012
From: Petr Blaho <pblaho at redhat.com>
https://www.aeolusproject.org/redmine/issues/3690
This creates cucumber features and step definitions
for update action of Provider Accounts API
---
src/features/provider_account_api.feature | 17 +++
.../step_definitions/provider_account_api_steps.rb | 129 ++++++++++++++++++--
2 files changed, 133 insertions(+), 13 deletions(-)
diff --git a/src/features/provider_account_api.feature b/src/features/provider_account_api.feature
index 45b577f..67105cc 100644
--- a/src/features/provider_account_api.feature
+++ b/src/features/provider_account_api.feature
@@ -39,3 +39,20 @@ Feature: Manage Provider Accounts via API
When I create provider account with incorrect data
Then I should receive Bad Request message
And the provider account should not be created
+
+ Scenario: Update a provider account
+ Given there is a provider account
+ When I update that provider account with correct data
+ Then I should receive OK message
+ And the provider account should be updated
+
+ Scenario: Update a provider account with bad request
+ Given there is a provider account
+ When I update that provider account with incorrect data
+ Then I should receive Bad Request message
+ And the provider account should not be updated
+
+ Scenario: Attempt to update non existing provider account
+ Given the specified provider account does not exist in the system
+ When I attempt to update the provider account
+ Then I should receive a Provider Account Not Found error
diff --git a/src/features/step_definitions/provider_account_api_steps.rb b/src/features/step_definitions/provider_account_api_steps.rb
index 4c87bec..7322ae8 100644
--- a/src/features/step_definitions/provider_account_api_steps.rb
+++ b/src/features/step_definitions/provider_account_api_steps.rb
@@ -62,13 +62,13 @@ When /^I create provider account with correct data$/ do
end
xml_provider_account = %Q[<?xml version="1.0" encoding="UTF-8"?>
- <provider_account>
- <label>#{@new_provider_account.label}</label>
- <credentials>
- #{credentials_hash}
- </credentials>
- </provider_account>
- ]
+ <provider_account>
+ <label>#{@new_provider_account.label}</label>
+ <credentials>
+ #{credentials_hash}
+ </credentials>
+ </provider_account>
+ ]
post api_provider_provider_accounts_url(@provider), xml_provider_account
end
@@ -89,12 +89,115 @@ When /^I create provider account with incorrect data$/ do
# missing label to achive incorrect data
xml_provider_account = %Q[<?xml version="1.0" encoding="UTF-8"?>
- <provider_account>
- <credentials>
- #{credentials_hash}
- </credentials>
- </provider_account>
- ]
+ <provider_account>
+ <credentials>
+ #{credentials_hash}
+ </credentials>
+ </provider_account>
+ ]
post api_provider_provider_accounts_url(@provider), xml_provider_account
end
+
+
+When /^I update that provider account with correct data$/ do
+ header 'Accept', 'application/xml'
+ header 'Content-Type', 'application/xml'
+
+ @new_provider_account = FactoryGirl.build(:mock_provider_account, :provider => @provider)
+
+ credentials_hash = ''
+
+ @new_provider_account.credentials.each do |credential|
+ label = credential.credential_definition.name
+ value = credential.value
+ credentials_hash += "<#{label}>#{value}</#{label}>"
+ end
+
+ xml_provider_account = %Q[<?xml version="1.0" encoding="UTF-8"?>
+ <provider_account>
+ <label>#{@new_provider_account.label}</label>
+ <credentials>
+ #{credentials_hash}
+ </credentials>
+ </provider_account>
+ ]
+
+ put api_provider_account_url(@provider_account), xml_provider_account
+end
+
+When /^I update that provider account with incorrect data$/ do
+ header 'Accept', 'application/xml'
+ header 'Content-Type', 'application/xml'
+
+ @other_provider_account = FactoryGirl.build(:mock_provider_account_seq, :provider => @provider)
+ @other_provider_account.stub(:validate_credentials).and_return(true)
+ @other_provider_account.save
+ @new_provider_account = FactoryGirl.build(:mock_provider_account_seq, :provider => @provider)
+
+ credentials_hash = ''
+
+ @new_provider_account.credentials.each do |credential|
+ label = credential.credential_definition.name
+ value = credential.value
+ credentials_hash += "<#{label}>#{value}</#{label}>"
+ end
+
+ xml_provider_account = %Q[<?xml version="1.0" encoding="UTF-8"?>
+ <provider_account>
+ <label>#{@other_provider_account.label}</label>
+ <credentials>
+ #{credentials_hash}
+ </credentials>
+ </provider_account>
+ ]
+
+ put api_provider_account_url(@provider_account), xml_provider_account
+end
+
+When /^I attempt to update the provider account$/ do
+ header 'Accept', 'application/xml'
+ header 'Content-Type', 'application/xml'
+
+ @new_provider_account = FactoryGirl.build(:mock_provider_account, :provider => @provider)
+
+ credentials_hash = ''
+
+ @new_provider_account.credentials.each do |credential|
+ label = credential.credential_definition.name
+ value = credential.value
+ credentials_hash += "<#{label}>#{value}</#{label}>"
+ end
+
+ xml_provider_account = %Q[<?xml version="1.0" encoding="UTF-8"?>
+ <provider_account>
+ <label>#{@new_provider_account.label}</label>
+ <credentials>
+ #{credentials_hash}
+ </credentials>
+ </provider_account>
+ ]
+
+ put api_provider_account_url(@provider_account), xml_provider_account
+end
+
+Then /^the provider account should be updated$/ do
+ orig_attrs, current_attrs, updating_attrs = [ @provider_account.dup, @provider_account.reload, @new_provider_account ].map do |pro|
+ pro.attributes.except("quota_id", "id", "lock_version", "updated_at", "created_at")
+ end
+ current_attrs.should be_eql(updating_attrs)
+ current_attrs.should_not be_eql(orig_attrs)
+end
+
+Then /^the provider account should not be updated$/ do
+ orig_attrs, current_attrs, updating_attrs = [ @provider_account.dup, @provider_account.reload, @new_provider_account ].map do |pro|
+ pro.attributes.except("quota_id", "id", "lock_version", "updated_at", "created_at")
+ end
+ current_attrs.should_not be_eql(updating_attrs)
+ current_attrs.should be_eql(orig_attrs)
+end
+
+Given /^the specified provider account does not exist in the system$/ do
+ @provider_account = FactoryGirl.create(:mock_provider_account)
+ ProviderAccount.delete(@provider_account.id)
+end
--
1.7.7.6
More information about the aeolus-devel
mailing list