From: Petr Blaho <pblaho(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/3421
Adds cucumber scenarios for Provider Accounts API - index action
---
src/features/provider_account_api.feature | 22 +++++++++++++++
.../step_definitions/provider_account_api_steps.rb | 28 ++++++++++++++++++++
.../step_definitions/provider_account_steps.rb | 20 ++++++++++++++
.../step_definitions/provider_api_steps.rb | 1 +
src/features/step_definitions/provider_steps.rb | 4 +++
5 files changed, 75 insertions(+), 0 deletions(-)
create mode 100644 src/features/provider_account_api.feature
create mode 100644 src/features/step_definitions/provider_account_api_steps.rb
diff --git a/src/features/provider_account_api.feature
b/src/features/provider_account_api.feature
new file mode 100644
index 0000000..adff4ef
--- /dev/null
+++ b/src/features/provider_account_api.feature
@@ -0,0 +1,22 @@
+@api
+Feature: Manage Provider Accounts via API
+ As a client of conductor,
+ In order to manage the full life cycle of provider accounts in the system
+ I want to be able to Create, Update and Delete provider accounts via a RESTful API
+
+ Background:
+ Given I am an authorised user
+ And I use my authentication credentials in each request
+ And there is a provider
+
+ Scenario: Get list of provider accounts for given provider as XML
+ Given there are some provider accounts for given provider
+ And there is another provider
+ And there are some provider accounts for that another provider
+ When I request a list of provider accounts for that provider returned as XML
+ Then I should receive list of provider accounts for that provider as XML
+
+ Scenario: Attempt to get list of provider accounts for non existing provider via XML
+ Given the specified provider does not exist in the system
+ When I request a list of provider accounts for that provider returned as XML
+ Then I should receive 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
new file mode 100644
index 0000000..ce9b6af
--- /dev/null
+++ b/src/features/step_definitions/provider_account_api_steps.rb
@@ -0,0 +1,28 @@
+#
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+When /^I request a list of provider accounts for that provider returned as XML$/ do
+ header 'Accept', 'application/xml'
+ get api_provider_provider_accounts_path(@provider)
+end
+
+Then /^I should receive list of provider accounts for that provider as XML$/ do
+ response = last_response
+ response.headers['Content-Type'].should include('application/xml')
+ response.status.should be_eql(200)
+ xml_body = Nokogiri::XML(response.body)
+ xml_body.xpath('//provider_accounts/provider_account').size.should be_eql(3)
+ # TODO: test that provider accounts listed is for that provider only
+end
diff --git a/src/features/step_definitions/provider_account_steps.rb
b/src/features/step_definitions/provider_account_steps.rb
index 01d44e3..e61e228 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -128,3 +128,23 @@ Then /^there should be these ec2 provider accounts:$/ do |table|
p[:provider_type].should == hash[:provider_type]
end
end
+
+Given /^there are some provider accounts for given provider$/ do
+ # FIXME: change 3 to constant
+ 3.times do
+ pa = FactoryGirl.build(:mock_provider_account_seq, :provider => @provider)
+ pa.stub!(:validate_credentials).and_return(true)
+ pa.save
+ end
+ @provider.provider_accounts.size.should be_eql(3)
+end
+
+Given /^there are some provider accounts for that another provider$/ do
+ # FIXME: change 3 to constant
+ 3.times do
+ pa = FactoryGirl.build(:mock_provider_account_seq, :provider =>
@another_provider)
+ pa.stub!(:validate_credentials).and_return(true)
+ pa.save
+ end
+ @another_provider.provider_accounts.size.should be_eql(3)
+end
diff --git a/src/features/step_definitions/provider_api_steps.rb
b/src/features/step_definitions/provider_api_steps.rb
index bd811ce..40eb3c3 100644
--- a/src/features/step_definitions/provider_api_steps.rb
+++ b/src/features/step_definitions/provider_api_steps.rb
@@ -1,5 +1,6 @@
World(Rack::Test::Methods)
+# TODO: move to some common file for API
Given /^I use my authentication credentials in each request$/ do
authorize((a)user.login, 'secret')
end
diff --git a/src/features/step_definitions/provider_steps.rb
b/src/features/step_definitions/provider_steps.rb
index 39c6f15..92d73ed 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -79,6 +79,10 @@ Given /^there is a provider$/ do
@provider = FactoryGirl.create(:mock_provider)
end
+Given /^there is another provider$/ do
+ @another_provider = FactoryGirl.create(:mock_provider)
+end
+
Given /^provider "([^"]*)" is not accessible$/ do |arg1|
stub_framework(false)
end
--
1.7.7.6