[PATCH conductor 09/20] Feature for Providers API - create action

pblaho at redhat.com pblaho at redhat.com
Fri Jun 8 00:38:02 UTC 2012


From: Petr Blaho <pblaho at redhat.com>

https://www.aeolusproject.org/redmine/issues/3248

This commit contains cucumber feature and step
definitions

Also adds invalid_provider Factory definition
---
 src/features/provider_api.feature                  |   20 ++++----
 .../step_definitions/provider_api_steps.rb         |   46 ++++++++++++++++++++
 src/features/step_definitions/provider_steps.rb    |    8 +++
 src/spec/factories/provider.rb                     |    4 ++
 4 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/src/features/provider_api.feature b/src/features/provider_api.feature
index 66d4ac8..5f113b8 100644
--- a/src/features/provider_api.feature
+++ b/src/features/provider_api.feature
@@ -38,16 +38,16 @@ Feature: Manage Providers via API
     When I ask for details of non existing provider as XML
     Then I should recieve Not Found error
 
-#  Scenario: Create a new provider
-#    When I create provider with correct data
-#    Then I should recieve OK message
-#    And the provider should be created
-#
-#  Scenario: Create a new provider with bad request
-#    When I create provider with incorrect data
-#    Then I should recieve Bad Request message
-#    And the provider should not be created
-#
+  Scenario: Create a new provider
+    When I create provider with correct data via XML
+    Then I should recieve OK message
+    And the provider should be created
+
+  Scenario: Create a new provider with bad request
+    When I create provider with incorrect data via XML
+    Then I should recieve Bad Request message
+    And the provider should not be created
+
 #  Scenario: Update a provider
 #    Given there is a provider
 #    When I update that provider with correct data
diff --git a/src/features/step_definitions/provider_api_steps.rb b/src/features/step_definitions/provider_api_steps.rb
index f3a34f2..ec6058c 100644
--- a/src/features/step_definitions/provider_api_steps.rb
+++ b/src/features/step_definitions/provider_api_steps.rb
@@ -44,3 +44,49 @@ Then /^I should recieve Not Found error$/ do
   xml_body = Nokogiri::XML(response.body)
   xml_body.xpath('//error').size.should be_eql(1)
 end
+
+When /^I create provider with correct data via XML$/ do
+  header 'Accept', 'application/xml'
+  header 'Content-Type', 'application/xml'
+
+  @provider = FactoryGirl.build(:mock_provider)
+
+  xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+                    <provider>
+                    <name>#{@provider.name}</name>
+                    <url>#{@provider.url}</url>
+                    <provider_type_id>#{@provider.provider_type_id}</provider_type_id>
+                    </provider>
+                    ]
+
+  post api_providers_path, xml_provider
+end
+
+Then /^I should recieve OK message$/ do
+  response = last_response
+  response.headers['Content-Type'].should include('application/xml')
+  response.status.should be_eql(200)
+end
+
+When /^I create provider with incorrect data via XML$/ do
+  header 'Accept', 'application/xml'
+  header 'Content-Type', 'application/xml'
+
+  @provider = FactoryGirl.build(:invalid_provider)
+
+  xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+                    <provider>
+                    <name>#{@provider.name}</name>
+                    <url>#{@provider.url}</url>
+                    <provider_type_id>#{@provider.provider_type_id}</provider_type_id>
+                    </provider>
+                    ]
+
+  post api_providers_path, xml_provider
+end
+
+Then /^I should recieve Bad Request message$/ do
+  response = last_response
+  response.headers['Content-Type'].should include('application/xml')
+  response.status.should be_eql(400)
+end
diff --git a/src/features/step_definitions/provider_steps.rb b/src/features/step_definitions/provider_steps.rb
index c3d552b..37b686f 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -31,6 +31,14 @@ def stub_framework(bool)
   Provider.any_instance.stub(:valid_framework?).and_return(bool)
 end
 
+Then /^the provider should be created$/ do
+  Provider.find_by_name_and_url(@provider.name, @provider.url).should_not be_nil
+end
+
+Then /^the provider should not be created$/ do
+  Provider.find_by_name_and_url(@provider.name, @provider.url).should be_nil
+end
+
 Given /^there should not exist a provider named "([^\"]*)"$/ do |name|
   Provider.find_by_name(name).should be_nil
 end
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
index a85b73b..044e0ae 100644
--- a/src/spec/factories/provider.rb
+++ b/src/spec/factories/provider.rb
@@ -22,6 +22,10 @@ FactoryGirl.define do
     url { |p| "http://www." + p.name + ".com/api" }
   end
 
+  factory :invalid_provider, :parent => :mock_provider do
+    name { '' }
+  end
+
   factory :mock_provider, :parent => :provider do
     provider_type {ProviderType.find_by_deltacloud_driver("mock")}
     url 'http://localhost:3002/api'
-- 
1.7.7.6




More information about the aeolus-devel mailing list