[PATCH conductor 1/3] Features for Provider Accounts API update action
pblaho at redhat.com
pblaho at redhat.com
Wed Aug 15 22:08:04 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 | 102 ++++++++++++++++++++
2 files changed, 119 insertions(+), 0 deletions(-)
diff --git a/src/features/provider_account_api.feature b/src/features/provider_account_api.feature
index a4098b3..ebad88b 100644
--- a/src/features/provider_account_api.feature
+++ b/src/features/provider_account_api.feature
@@ -29,3 +29,20 @@ Feature: Manage Provider Accounts via API
Scenario: Get details for non existing provider account
When I ask for details of non existing provider account
Then I should receive Not Found error
+
+ 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 4e2c682..b561544 100644
--- a/src/features/step_definitions/provider_account_api_steps.rb
+++ b/src/features/step_definitions/provider_account_api_steps.rb
@@ -46,3 +46,105 @@ When /^I ask for details of non existing provider account$/ do
provider_account.delete if provider_account
get api_provider_account_path(1)
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