[PATCH conductor 5/7] Features for Provider Accounts API create action
pblaho at redhat.com
pblaho at redhat.com
Wed Aug 15 17:11:28 UTC 2012
From: Petr Blaho <pblaho at redhat.com>
https://www.aeolusproject.org/redmine/issues/3652
This creates cucumber features and step definitions
for create action of Provider Accounts API
---
src/features/provider_account_api.feature | 10 ++++
.../step_definitions/provider_account_api_steps.rb | 52 ++++++++++++++++++++
.../step_definitions/provider_account_steps.rb | 9 +++
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/src/features/provider_account_api.feature b/src/features/provider_account_api.feature
index a4098b3..45b577f 100644
--- a/src/features/provider_account_api.feature
+++ b/src/features/provider_account_api.feature
@@ -29,3 +29,13 @@ 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: Create a new provider account
+ When I create provider account with correct data
+ Then I should receive OK message
+ And the provider account should be created
+
+ Scenario: Create a new provider account with bad request
+ When I create provider account with incorrect data
+ Then I should receive Bad Request message
+ And the provider account should not be created
diff --git a/src/features/step_definitions/provider_account_api_steps.rb b/src/features/step_definitions/provider_account_api_steps.rb
index 4e2c682..4c87bec 100644
--- a/src/features/step_definitions/provider_account_api_steps.rb
+++ b/src/features/step_definitions/provider_account_api_steps.rb
@@ -46,3 +46,55 @@ 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 create 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>
+ ]
+
+ post api_provider_provider_accounts_url(@provider), xml_provider_account
+end
+
+When /^I create provider account with incorrect 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
+
+ # 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>
+ ]
+
+ post api_provider_provider_accounts_url(@provider), xml_provider_account
+end
diff --git a/src/features/step_definitions/provider_account_steps.rb b/src/features/step_definitions/provider_account_steps.rb
index d758395..c6b6e2b 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -152,3 +152,12 @@ Given /^there are some provider accounts for that another provider$/ do
end
@another_provider.provider_accounts.size.should be_eql(3)
end
+
+
+Then /^the provider account should be created$/ do
+ ProviderAccount.find_by_label(@new_provider_account.label).should_not be_nil
+end
+
+Then /^the provider account should not be created$/ do
+ ProviderAccount.find_by_label(@new_provider_account.label).should be_nil
+end
--
1.7.7.6
More information about the aeolus-devel
mailing list