[PATCH conductor 3/3] Fix the pool families tests

tsedovic at redhat.com tsedovic at redhat.com
Thu Dec 8 13:05:03 UTC 2011


From: Tomas Sedovic <tomas at sedovic.cz>

This is the first step towards what seems a more sensible use of VCR: for every
cucumber feature we'll have a single casette. That casette is loaded exactly
once -- at the beginning of the test -- and contains only the communication
data needed for that particular test.
---
 src/app/controllers/pool_families_controller.rb    |    1 -
 src/features/pool_family.feature                   |    3 +-
 src/features/step_definitions/pool_family_steps.rb |    5 +
 src/features/support/vcr.rb                        |   11 +
 src/spec/vcr/cassettes/features/pool_families.yml  |  234 ++++++++++++++++++++
 src/spec/vcr_setup.rb                              |   17 ++
 6 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 src/spec/vcr/cassettes/features/pool_families.yml

diff --git a/src/app/controllers/pool_families_controller.rb b/src/app/controllers/pool_families_controller.rb
index 6355193..f400a1d 100644
--- a/src/app/controllers/pool_families_controller.rb
+++ b/src/app/controllers/pool_families_controller.rb
@@ -109,7 +109,6 @@ class PoolFamiliesController < ApplicationController
                              0 : @pool_family.provider_accounts.map(&:id))
 
     load_tab_captions_and_details_tab('provider_accounts')
-    load_pool_family_tabs
 
     added = []
     not_added = []
diff --git a/src/features/pool_family.feature b/src/features/pool_family.feature
index a14767b..5e96ca3 100644
--- a/src/features/pool_family.feature
+++ b/src/features/pool_family.feature
@@ -6,6 +6,7 @@ Feature: Pool Families
   Background:
     Given I am an authorised user
     And I am logged in
+    And I'm connected to the warehouse
 
   Scenario: List pool families
     Given I am on the homepage
@@ -87,7 +88,7 @@ Feature: Pool Families
     And I am on the pool family provider accounts page
     Then I should see "Account Name"
     When I follow "Add Account"
-    When I check the "testaccount" account
+    And I check the "testaccount" account
     And I press "Add Account"
     Then there should be 1 provider accounts assigned to "testpoolfamily"
     And I should see "testaccount"
diff --git a/src/features/step_definitions/pool_family_steps.rb b/src/features/step_definitions/pool_family_steps.rb
index 48de421..70bb207 100644
--- a/src/features/step_definitions/pool_family_steps.rb
+++ b/src/features/step_definitions/pool_family_steps.rb
@@ -13,6 +13,11 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 #
+
+Given /I'm connected to the warehouse/ do
+  use_casette('pool_families')
+end
+
 Given /^there are these pool families:$/ do |table|
   table.hashes.each do |hash|
     FactoryGirl.create(:pool_family, :name => hash['name'])
diff --git a/src/features/support/vcr.rb b/src/features/support/vcr.rb
index 84bc1d8..fed2072 100644
--- a/src/features/support/vcr.rb
+++ b/src/features/support/vcr.rb
@@ -19,3 +19,14 @@ if ENV['VCR_RECORD']
 else
   require File.expand_path(File.dirname(__FILE__) + '../../../spec/vcr_setup_norec.rb')
 end
+
+def use_casette(casette)
+  path = "#{::Rails.root.to_s}/spec/vcr/cassettes/features/#{casette}.yml"
+  VCR.config do |c|
+    c.cassette_library_dir = File.dirname(path)
+    c.stub_with :webmock
+    c.allow_http_connections_when_no_cassette = true
+  end
+
+  VCR::Cassette.new(File.basename(path, '.yml'), :record => :none)
+end
diff --git a/src/spec/vcr/cassettes/features/pool_families.yml b/src/spec/vcr/cassettes/features/pool_families.yml
new file mode 100644
index 0000000..699208b
--- /dev/null
+++ b/src/spec/vcr/cassettes/features/pool_families.yml
@@ -0,0 +1,234 @@
+--- 
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="pBIf0kWGxScw4npq1Gf2OzXpYQKrdtXCfLlXTbQRQo", oauth_signature="qLKooszQvguJ2itBPh7bVU3%2BRps%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343693", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:13 GMT
+      transfer-encoding: 
+      - chunked
+    body: |
+      <objects>
+      	<object>
+      		<bucket>images</bucket>
+      		<key>fb0c1ad8-2020-11e1-a84d-001f161d4fcc</key>
+      	</object>
+      </objects>
+
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :post
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc
+    body: op=parts
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_body_hash="2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D", oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="83KVRgb21tJqZUiMgVULTaoV9UgmAuzCcuRLg1ujpXI", oauth_signature="sD6797%2B40XhsxZTt6ciax%2BfwEEU%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343693", oauth_version="1.0"
+      content-length: 
+      - "8"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:13 GMT
+      transfer-encoding: 
+      - chunked
+    body: |
+      <object>
+      	<object_body path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc"/>
+      	<object_attr_list path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/_attrs"/>
+      	<object_attr name="latest_build" path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/latest_build"/>
+      	<object_attr name="latest_unpushed" path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/latest_unpushed"/>
+      	<object_attr name="object_type" path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/object_type"/>
+      	<object_attr name="template" path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/template"/>
+      	<object_attr name="uuid" path="http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/uuid"/>
+      </object>
+
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/latest_build
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="9ym1ybsYS7qLQDSKbSsSN0NziFcSnTP9pEhzNuZlqM", oauth_signature="5K6E%2Fksa%2Fn73qL0s9buFynoJ6U0%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343693", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:13 GMT
+      content-length: 
+      - "36"
+    body: 3f9a1de7-444f-49cf-b1cc-e8ea2557287e
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/latest_unpushed
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="gtirZvcwzCzv7FlzeyOeS9KZCOTaWNgJshof2zpVn7s", oauth_signature="pCcAIj%2F58UpHjW4mRvAWk8JIfoI%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343693", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:14 GMT
+      content-length: 
+      - "4"
+    body: None
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/object_type
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="9y2gl7q8fvJKolk2GUlIxR6gS1s7HZFcq2RXoLYBmw", oauth_signature="6hrxehBRbjR8gRdnGll8HMtmh68%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343694", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:14 GMT
+      content-length: 
+      - "5"
+    body: image
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/template
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="I130Hkva9C1CNdhbOx27PEjbQSwlLmYWzvt5yCZNs", oauth_signature="JslF%2FRmestcpWZTmjx8gu18H9Vc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343694", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:14 GMT
+      content-length: 
+      - "36"
+    body: facba9d0-2020-11e1-a84d-001f161d4fcc
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc/uuid
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="jZZ2nPU70jPoQRSkPr4tubXvuwG27oIeLOnViACTiw", oauth_signature="dF%2ByrycX3ZuPyVm3nwe0VOVOIzg%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343694", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:14 GMT
+      content-length: 
+      - "36"
+    body: fb0c1ad8-2020-11e1-a84d-001f161d4fcc
+    http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :get
+    uri: http://localhost:9090/images/fb0c1ad8-2020-11e1-a84d-001f161d4fcc
+    body: 
+    headers: 
+      accept: 
+      - "*/*; q=0.5, application/xml"
+      user-agent: 
+      - OAuth gem v0.4.4
+      accept-encoding: 
+      - gzip, deflate
+      authorization: 
+      - OAuth oauth_consumer_key="Bd7BOggYyK3AV64tRQcU9rxFtrebCLtt", oauth_nonce="sXp2JRrtMzOLmIMcyUKsB3Sb4wFU5UmbpAEuWOeWXKw", oauth_signature="uTd%2FBg%2ByPza3qcu4iZ89QlKyOd8%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1323343695", oauth_version="1.0"
+      content-length: 
+      - "0"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 200
+      message: OK
+    headers: 
+      date: 
+      - Thu, 08 Dec 2011 11:28:15 GMT
+      transfer-encoding: 
+      - chunked
+    body: <image><name>Fedora</name></image>
+    http_version: "1.1"
diff --git a/src/spec/vcr_setup.rb b/src/spec/vcr_setup.rb
index 3953d1f..251ddbd 100644
--- a/src/spec/vcr_setup.rb
+++ b/src/spec/vcr_setup.rb
@@ -42,6 +42,23 @@ Warehouse::Connection.class_eval do
   end
 end
 
+Aeolus::Image::Warehouse::Connection.class_eval do
+  def do_request(path = '', opts={})
+    opts[:method]  ||= :get
+    opts[:content] ||= ''
+    opts[:plain]   ||= false
+    opts[:headers] ||= {}
+    result=nil
+    VCR.use_cassette('aeolus_image_warehouse_connection', :record => :new_episodes) do
+      result = RestClient::Request.execute :method => opts[:method], :url => @uri + path, :payload => opts[:content], :headers => opts[:headers]
+    end
+
+    return Nokogiri::XML result unless opts[:plain]
+    return result
+  end
+end
+
+
 # Mock request for deployable xml
 DeployableXML.class_eval do
   def self.import_xml_from_url(url)
-- 
1.7.6.4




More information about the aeolus-devel mailing list