[PATCH conductor 18/20] Feature for Providers API - update action

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


From: Petr Blaho <pblaho at redhat.com>

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

This commit adds cucumber feature and step definitions
---
 src/features/provider_api.feature                  |   28 ++++++----
 .../step_definitions/provider_api_steps.rb         |   52 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 11 deletions(-)

diff --git a/src/features/provider_api.feature b/src/features/provider_api.feature
index 9db07e5..703b022 100644
--- a/src/features/provider_api.feature
+++ b/src/features/provider_api.feature
@@ -48,17 +48,23 @@ Feature: Manage Providers via API
     Then I should receive 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
-#    Then I should receive OK message
-#    And the provider should be updated
-#
-#  Scenario: Update a provider with bad request
-#    Given there is a provider
-#    When I update that provider with incorrect data
-#    Then I should receive Bad Request message
-#    And the provider should not be updated
+  Scenario: Update a provider
+    Given there is a provider
+    When I update that provider with correct data via XML
+    Then I should receive OK message
+    And the provider should be updated
+
+  Scenario: Update a provider with bad request
+    Given there is a provider
+    When I update that provider with incorrect data via XML
+    Then I should receive Bad Request message
+    And the provider should not be updated
+
+  Scenario: Attempt to update non existing provider
+    Given the specified provider does not exist in the system
+    When I attempt to update the provider
+    Then I should receive a Provider Not Found error
+    And the provider should not be updated
 
   Scenario: Delete Provider
     Given there is a provider
diff --git a/src/features/step_definitions/provider_api_steps.rb b/src/features/step_definitions/provider_api_steps.rb
index 0ac4ec5..bd811ce 100644
--- a/src/features/step_definitions/provider_api_steps.rb
+++ b/src/features/step_definitions/provider_api_steps.rb
@@ -108,3 +108,55 @@ Then /^I should receive a Provider Not Found error$/ do
   response.headers['Content-Type'].should include('application/xml')
   response.status.should be_eql(404)
 end
+
+When /^I update that provider with correct data via XML$/ do
+  header 'Accept', 'application/xml'
+  header 'Content-Type', 'application/xml'
+
+  @provider = FactoryGirl.create(:mock_provider)
+  @new_provider = FactoryGirl.build(:mock_provider)
+
+  xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+                    <provider>
+                    <name>#{@new_provider.name}</name>
+                    <url>#{@new_provider.url}</url>
+                    <provider_type id="#{@new_provider.provider_type_id}" />
+                    </provider>
+                    ]
+
+  put api_provider_path(@provider), xml_provider
+end
+
+Then /^the provider should be updated$/ do
+  orig_attrs, current_attrs, updating_attrs  = [ @provider.dup, @provider.reload, @new_provider ].map do |pro|
+    pro.attributes.except("id", "lock_version", "updated_at", "created_at")
+  end
+  current_attrs.should be_eql(updating_attrs)
+  current_attrs.should_not be_eql(orig_attrs)
+end
+
+When /^I update that provider with incorrect data via XML$/ do
+  header 'Accept', 'application/xml'
+  header 'Content-Type', 'application/xml'
+
+  @provider = FactoryGirl.create(:mock_provider)
+  other_provider = FactoryGirl.create(:mock_provider)
+  @new_provider = FactoryGirl.build(:invalid_provider, :name => other_provider.name)
+
+  xml_provider = %Q[<?xml version="1.0" encoding="UTF-8"?>
+                    <provider>
+                    <name>#{@new_provider.name}</name>
+                    <provider_type id="#{@new_provider.provider_type_id}" />
+                    </provider>
+                    ]
+
+  put api_provider_path(@provider), xml_provider
+end
+
+Then /^the provider should not be updated$/ do
+  orig_attrs, current_attrs, updating_attrs  = [ @provider.dup, @provider.reload, @new_provider ].map do |pro|
+    pro.attributes.except("id", "lock_version", "updated_at", "created_at")
+  end
+  current_attrs.should_not be_eql(updating_attrs)
+  current_attrs.should be_eql(orig_attrs)
+end
-- 
1.7.7.6




More information about the aeolus-devel mailing list