[PATCH aeolus-image-rubygem] Resolve VCR problem with matching requests

Petr Blaho pblaho at redhat.com
Wed Feb 22 15:31:57 UTC 2012


Refactored some tests code to bypass VCR request matching problem

https://bugzilla.redhat.com/show_bug.cgi?id=791216
---
 spec/models/factory/base.rb                |   82 ------------------------
 spec/models/factory/base_spec.rb           |   94 ++++++++++++++++++++++++++++
 spec/models/factory/builder.rb             |   31 ---------
 spec/models/factory/builder_spec.rb        |   31 +++++++++
 spec/models/factory/provider_image.rb      |   21 ------
 spec/models/factory/provider_image_spec.rb |   21 ++++++
 spec/models/factory/target_image.rb        |   21 ------
 spec/models/factory/target_image_spec.rb   |   21 ++++++
 spec/spec_helper.rb                        |    1 +
 spec/vcr/cassettes/oauth.yml               |   80 -----------------------
 spec/vcr/cassettes/oauth_fail_invalid.yml  |   30 +++++++++
 spec/vcr/cassettes/oauth_fail_no.yml       |   22 +++++++
 spec/vcr/cassettes/oauth_success_valid.yml |   30 +++++++++
 spec/vcr_setup.rb                          |   16 +++---
 14 files changed, 258 insertions(+), 243 deletions(-)
 delete mode 100644 spec/models/factory/base.rb
 create mode 100644 spec/models/factory/base_spec.rb
 delete mode 100644 spec/models/factory/builder.rb
 create mode 100644 spec/models/factory/builder_spec.rb
 delete mode 100644 spec/models/factory/provider_image.rb
 create mode 100644 spec/models/factory/provider_image_spec.rb
 delete mode 100644 spec/models/factory/target_image.rb
 create mode 100644 spec/models/factory/target_image_spec.rb
 delete mode 100644 spec/vcr/cassettes/oauth.yml
 create mode 100644 spec/vcr/cassettes/oauth_fail_invalid.yml
 create mode 100644 spec/vcr/cassettes/oauth_fail_no.yml
 create mode 100644 spec/vcr/cassettes/oauth_success_valid.yml

diff --git a/spec/models/factory/base.rb b/spec/models/factory/base.rb
deleted file mode 100644
index 86b8a70..0000000
--- a/spec/models/factory/base.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-#
-#   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.
-#
-require 'spec_helper'
-require 'timecop'
-
-describe Aeolus::Image::Factory::Base do
-
-  before(:each) do
-    Timecop.travel(Time.local(2011, 10, 17, 13, 38, 20))
-  end
-
-  after(:each) do
-    Timecop.return
-  end
-
-  it "should not use_oauth? if configuration is missing" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory'
-    }
-    Aeolus::Image::Factory::Base.use_oauth?.should be_false
-  end
-
-  it "should use_oauth? if configuration is present" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory',
-      :consumer_key => 'something',
-      :consumer_secret => 'anything'
-    }
-    Aeolus::Image::Factory::Base.use_oauth?.should be_true
-  end
-
-  it "should succeed with valid OAuth credentials" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory',
-      :consumer_key => 'mock-key',
-      :consumer_secret => 'mock-secret'
-    }
-    template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
-    img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
-    img.save!.should be_true
-  end
-
-  it "should fail with invalid OAuth credentials" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory',
-      :consumer_key => 'mock-key',
-      :consumer_secret => 'wrong-secret'
-    }
-    template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora 2</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
-    img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
-    lambda {
-      img.save!
-    }.should raise_error(ActiveResource::UnauthorizedAccess)
-  end
-
-  it "should fail with no OAuth credentials" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory'
-    }
-    template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora 3</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
-    img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
-    # ServerError is actually not what _should_ be returned, but a bug means that's what we get at the moment.
-    # When the bug is fixed, we need to update to test for that.
-    lambda {
-      img.save!.should be_false
-    }.should raise_error(ActiveResource::ServerError)
-  end
-
-end
diff --git a/spec/models/factory/base_spec.rb b/spec/models/factory/base_spec.rb
new file mode 100644
index 0000000..7dadc1a
--- /dev/null
+++ b/spec/models/factory/base_spec.rb
@@ -0,0 +1,94 @@
+#
+#   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.
+#
+require 'spec_helper'
+require 'timecop'
+
+describe Aeolus::Image::Factory::Base do
+
+  before(:each) do
+    Timecop.travel(Time.local(2011, 10, 17, 13, 38, 20))
+  end
+
+  after(:each) do
+    Timecop.return
+  end
+
+  it "should not use_oauth? if configuration is missing" do
+    Aeolus::Image::Factory::Base.config = {
+      :site => 'http://127.0.0.1:8075/imagefactory'
+    }
+    Aeolus::Image::Factory::Base.use_oauth?.should be_false
+  end
+
+  it "should use_oauth? if configuration is present" do
+    Aeolus::Image::Factory::Base.config = {
+      :site => 'http://127.0.0.1:8075/imagefactory',
+      :consumer_key => 'something',
+      :consumer_secret => 'anything'
+    }
+    Aeolus::Image::Factory::Base.use_oauth?.should be_true
+  end
+
+  context do
+    use_vcr_cassette "oauth_success_valid"
+
+    it "should succeed with valid OAuth credentials" do
+      Aeolus::Image::Factory::Base.config = {
+        :site => 'http://127.0.0.1:8075/imagefactory',
+        :consumer_key => 'mock-key',
+        :consumer_secret => 'mock-secret'
+      }
+      template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
+      img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
+      img.save!.should be_true
+    end
+  end
+
+  context do
+    use_vcr_cassette "oauth_fail_invalid"
+
+    it "should fail with invalid OAuth credentials" do
+      Aeolus::Image::Factory::Base.config = {
+        :site => 'http://127.0.0.1:8075/imagefactory',
+        :consumer_key => 'mock-key',
+        :consumer_secret => 'wrong-secret'
+      }
+      template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora 2</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
+      img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
+      lambda {
+        img.save!
+      }.should raise_error(ActiveResource::UnauthorizedAccess)
+    end
+  end
+
+  context do
+    use_vcr_cassette "oauth_fail_no"
+
+    it "should fail with no OAuth credentials" do
+      Aeolus::Image::Factory::Base.config = {
+        :site => 'http://127.0.0.1:8075/imagefactory'
+      }
+      template = "<template>\n  <name>f14jeos</name>\n  <os>\n    <name>Fedora 3</name>\n    <version>14</version>\n    <arch>x86_64</arch>\n    <install type='url'>\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\n    </install>\n  </os>\n  <description>Fedora 14</description>\n</template>\n"
+      img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template => template)
+      # ServerError is actually not what _should_ be returned, but a bug means that's what we get at the moment.
+      # When the bug is fixed, we need to update to test for that.
+      lambda {
+        img.save!.should be_false
+      }.should raise_error(ActiveResource::ServerError)
+    end
+  end
+
+end
diff --git a/spec/models/factory/builder.rb b/spec/models/factory/builder.rb
deleted file mode 100644
index 8714244..0000000
--- a/spec/models/factory/builder.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#   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.
-#
-require 'spec_helper'
-require 'timecop'
-
-describe Aeolus::Image::Factory::Builder do
-  VCR::Cassette.new 'builder', :record => :new_episodes, :match_requests_on => [:method, :uri, :body]
-  it "should get builder object" do
-    Aeolus::Image::Factory::Base.config = {
-      :site => 'http://127.0.0.1:8075/imagefactory'
-    }
-    builder = Aeolus::Image::Factory::Builder.first
-    builder.builders.should_not be_empty
-    build = builder.builders.first
-    builder.find_active_build(build.build_id, build.target).should_not be_nil
-    builder.find_active_build(build.build_id, 'invalid_target').should be_nil
-  end
-end
diff --git a/spec/models/factory/builder_spec.rb b/spec/models/factory/builder_spec.rb
new file mode 100644
index 0000000..8714244
--- /dev/null
+++ b/spec/models/factory/builder_spec.rb
@@ -0,0 +1,31 @@
+#
+#   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.
+#
+require 'spec_helper'
+require 'timecop'
+
+describe Aeolus::Image::Factory::Builder do
+  VCR::Cassette.new 'builder', :record => :new_episodes, :match_requests_on => [:method, :uri, :body]
+  it "should get builder object" do
+    Aeolus::Image::Factory::Base.config = {
+      :site => 'http://127.0.0.1:8075/imagefactory'
+    }
+    builder = Aeolus::Image::Factory::Builder.first
+    builder.builders.should_not be_empty
+    build = builder.builders.first
+    builder.find_active_build(build.build_id, build.target).should_not be_nil
+    builder.find_active_build(build.build_id, 'invalid_target').should be_nil
+  end
+end
diff --git a/spec/models/factory/provider_image.rb b/spec/models/factory/provider_image.rb
deleted file mode 100644
index 98983be..0000000
--- a/spec/models/factory/provider_image.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'spec_helper'
-
-module Aeolus
-  module Image
-    module Factory
-      describe ProviderImage do
-        it "should return nil when a builder is found but operation is build" do
-          @builder = mock(Builder, :operation => "build", :status => "PUSHING")
-          Builder.stub!(:find).and_return(@builder)
-          ProviderImage.status("1234").should == nil
-        end
-
-        it "should return a builder when a builder is found and operation is push" do
-          @builder = mock(Builder, :operation => "push", :status => "PUSHING")
-          Builder.stub!(:find).and_return(@builder)
-          ProviderImage.status("1234").should == "PUSHING"
-        end
-      end
-    end
-  end
-end
\ No newline at end of file
diff --git a/spec/models/factory/provider_image_spec.rb b/spec/models/factory/provider_image_spec.rb
new file mode 100644
index 0000000..98983be
--- /dev/null
+++ b/spec/models/factory/provider_image_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+module Aeolus
+  module Image
+    module Factory
+      describe ProviderImage do
+        it "should return nil when a builder is found but operation is build" do
+          @builder = mock(Builder, :operation => "build", :status => "PUSHING")
+          Builder.stub!(:find).and_return(@builder)
+          ProviderImage.status("1234").should == nil
+        end
+
+        it "should return a builder when a builder is found and operation is push" do
+          @builder = mock(Builder, :operation => "push", :status => "PUSHING")
+          Builder.stub!(:find).and_return(@builder)
+          ProviderImage.status("1234").should == "PUSHING"
+        end
+      end
+    end
+  end
+end
\ No newline at end of file
diff --git a/spec/models/factory/target_image.rb b/spec/models/factory/target_image.rb
deleted file mode 100644
index c88295c..0000000
--- a/spec/models/factory/target_image.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'spec_helper'
-
-module Aeolus
-  module Image
-    module Factory
-      describe TargetImage do
-        it "should return nil when a builder is found but operation is push" do
-          @builder = mock(Builder, :operation => "push")
-          Builder.stub!(:find).and_return(@builder)
-          TargetImage.status("1234").should == nil
-        end
-
-        it "should return a builder when a builder is found and operation is build" do
-          @builder = mock(Builder, :operation => "build", :status => "BUILDING")
-          Builder.stub!(:find).and_return(@builder)
-          TargetImage.status("1234").should == "BUILDING"
-        end
-      end
-    end
-  end
-end
\ No newline at end of file
diff --git a/spec/models/factory/target_image_spec.rb b/spec/models/factory/target_image_spec.rb
new file mode 100644
index 0000000..c88295c
--- /dev/null
+++ b/spec/models/factory/target_image_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+module Aeolus
+  module Image
+    module Factory
+      describe TargetImage do
+        it "should return nil when a builder is found but operation is push" do
+          @builder = mock(Builder, :operation => "push")
+          Builder.stub!(:find).and_return(@builder)
+          TargetImage.status("1234").should == nil
+        end
+
+        it "should return a builder when a builder is found and operation is build" do
+          @builder = mock(Builder, :operation => "build", :status => "BUILDING")
+          Builder.stub!(:find).and_return(@builder)
+          TargetImage.status("1234").should == "BUILDING"
+        end
+      end
+    end
+  end
+end
\ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index bd4a318..7761ead 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -28,6 +28,7 @@ require 'warehouse/provider_image'
 require 'warehouse/template'
 
 RSpec.configure do |config|
+  config.extend VCR::RSpec::Macros
   config.before(:all) do
 #    Aeolus::Image::BaseCommand.class_eval do
 #      def load_config
diff --git a/spec/vcr/cassettes/oauth.yml b/spec/vcr/cassettes/oauth.yml
deleted file mode 100644
index 9f8c7fa..0000000
--- a/spec/vcr/cassettes/oauth.yml
+++ /dev/null
@@ -1,80 +0,0 @@
---- 
-- !ruby/struct:VCR::HTTPInteraction 
-  request: !ruby/struct:VCR::Request 
-    method: :post
-    uri: http://127.0.0.1:8075/imagefactory/images
-    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
-    headers: 
-      user-agent: 
-      - OAuth gem v0.4.4
-      content-type: 
-      - application/json
-      authorization: 
-      - OAuth oauth_body_hash="iLFFmVptnUF4tv9PvDNdNxK%2FSOs%3D", oauth_consumer_key="mock-key", oauth_nonce="dESbWyTyKA0UTHekLdt7DOSOFh6tYU39Mw7LpFkts", oauth_signature="ydhBMjipuQ7ARZT5xfOrvShZfHI%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100", oauth_version="1.0"
-      content-length: 
-      - "365"
-  response: !ruby/struct:VCR::Response 
-    status: !ruby/struct:VCR::ResponseStatus 
-      code: 202
-      message: Accepted
-    headers: 
-      content-type: 
-      - application/json
-      server: 
-      - PasteWSGIServer/0.5 Python/2.7.1
-      date: 
-      - Mon, 17 Oct 2011 17:38:15 GMT
-      content-length: 
-      - "640"
-    body: "{\"_type\": \"image\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\", \"id\": \"18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\", \"build\": {\"target_images\": [{\"_type\": \"target_image\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252/target_images/dd9c27c5-0bdb-4670-b172-46a3cf2101a6\", \"id\": \"dd9c27c5-0bdb-4670-b172-46a3cf2101a6\"}], \"_type\": \"build\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252\", \"id\": \"6d715c2f-8dc5-46eb-86ad-509366e64252\"}}"
-    http_version: "1.1"
-- !ruby/struct:VCR::HTTPInteraction 
-  request: !ruby/struct:VCR::Request 
-    method: :post
-    uri: http://127.0.0.1:8075/imagefactory/images
-    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora 2</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
-    headers: 
-      content-type: 
-      - application/json
-      user-agent: 
-      - OAuth gem v0.4.4
-      authorization: 
-      - OAuth oauth_body_hash="tEAlC3IwCGiB%2FNSQRUOwBifTHmY%3D", oauth_consumer_key="mock-key", oauth_nonce="jeQp5OlYxoCbbflwdM9nfg306BUVfmidPYKV7qPOs", oauth_signature="ERZpwVUR4qdBjfeBTJQtem%2FnKTo%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100", oauth_version="1.0"
-      content-length: 
-      - "367"
-  response: !ruby/struct:VCR::Response 
-    status: !ruby/struct:VCR::ResponseStatus 
-      code: 401
-      message: Unauthorized
-    headers: 
-      content-type: 
-      - text/html; charset=UTF-8
-      date: 
-      - Mon, 17 Oct 2011 17:38:15 GMT
-      server: 
-      - PasteWSGIServer/0.5 Python/2.7.1
-      content-length: 
-      - "0"
-    body: 
-    http_version: "1.1"
-- !ruby/struct:VCR::HTTPInteraction 
-  request: !ruby/struct:VCR::Request 
-    method: :post
-    uri: http://127.0.0.1:8075/imagefactory/images
-    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora 3</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
-    headers: 
-      content-type: 
-      - application/json
-  response: !ruby/struct:VCR::Response 
-    status: !ruby/struct:VCR::ResponseStatus 
-      code: 500
-      message: Internal Server Error
-    headers: 
-      content-type: 
-      - text/html; charset=UTF-8
-      server: 
-      - PasteWSGIServer/0.5 Python/2.7.1
-      date: 
-      - Mon, 17 Oct 2011 17:38:15 GMT
-    body: "'NoneType' object has no attribute '_get_timestamp_nonce'"
-    http_version: "1.1"
diff --git a/spec/vcr/cassettes/oauth_fail_invalid.yml b/spec/vcr/cassettes/oauth_fail_invalid.yml
new file mode 100644
index 0000000..d7488e4
--- /dev/null
+++ b/spec/vcr/cassettes/oauth_fail_invalid.yml
@@ -0,0 +1,30 @@
+--- 
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :post
+    uri: http://127.0.0.1:8075/imagefactory/images
+    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora 2</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
+    headers: 
+      content-type: 
+      - application/json
+      user-agent: 
+      - OAuth gem v0.4.4
+      authorization: 
+      - OAuth oauth_body_hash="tEAlC3IwCGiB%2FNSQRUOwBifTHmY%3D", oauth_consumer_key="mock-key", oauth_nonce="jeQp5OlYxoCbbflwdM9nfg306BUVfmidPYKV7qPOs", oauth_signature="ERZpwVUR4qdBjfeBTJQtem%2FnKTo%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100", oauth_version="1.0"
+      content-length: 
+      - "367"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 401
+      message: Unauthorized
+    headers: 
+      content-type: 
+      - text/html; charset=UTF-8
+      date: 
+      - Mon, 17 Oct 2011 17:38:15 GMT
+      server: 
+      - PasteWSGIServer/0.5 Python/2.7.1
+      content-length: 
+      - "0"
+    body: 
+    http_version: "1.1"
diff --git a/spec/vcr/cassettes/oauth_fail_no.yml b/spec/vcr/cassettes/oauth_fail_no.yml
new file mode 100644
index 0000000..3490391
--- /dev/null
+++ b/spec/vcr/cassettes/oauth_fail_no.yml
@@ -0,0 +1,22 @@
+--- 
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :post
+    uri: http://127.0.0.1:8075/imagefactory/images
+    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora 3</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
+    headers: 
+      content-type: 
+      - application/json
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 500
+      message: Internal Server Error
+    headers: 
+      content-type: 
+      - text/html; charset=UTF-8
+      server: 
+      - PasteWSGIServer/0.5 Python/2.7.1
+      date: 
+      - Mon, 17 Oct 2011 17:38:15 GMT
+    body: "'NoneType' object has no attribute '_get_timestamp_nonce'"
+    http_version: "1.1"
diff --git a/spec/vcr/cassettes/oauth_success_valid.yml b/spec/vcr/cassettes/oauth_success_valid.yml
new file mode 100644
index 0000000..17da22d
--- /dev/null
+++ b/spec/vcr/cassettes/oauth_success_valid.yml
@@ -0,0 +1,30 @@
+--- 
+- !ruby/struct:VCR::HTTPInteraction 
+  request: !ruby/struct:VCR::Request 
+    method: :post
+    uri: http://127.0.0.1:8075/imagefactory/images
+    body: "{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n  <name>f14jeos</name>\\n  <os>\\n    <name>Fedora</name>\\n    <version>14</version>\\n    <arch>x86_64</arch>\\n    <install type='url'>\\n      <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>\\n    </install>\\n  </os>\\n  <description>Fedora 14</description>\\n</template>\\n\"}}"
+    headers: 
+      user-agent: 
+      - OAuth gem v0.4.4
+      content-type: 
+      - application/json
+      authorization: 
+      - OAuth oauth_body_hash="iLFFmVptnUF4tv9PvDNdNxK%2FSOs%3D", oauth_consumer_key="mock-key", oauth_nonce="dESbWyTyKA0UTHekLdt7DOSOFh6tYU39Mw7LpFkts", oauth_signature="ydhBMjipuQ7ARZT5xfOrvShZfHI%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100", oauth_version="1.0"
+      content-length: 
+      - "365"
+  response: !ruby/struct:VCR::Response 
+    status: !ruby/struct:VCR::ResponseStatus 
+      code: 202
+      message: Accepted
+    headers: 
+      content-type: 
+      - application/json
+      server: 
+      - PasteWSGIServer/0.5 Python/2.7.1
+      date: 
+      - Mon, 17 Oct 2011 17:38:15 GMT
+      content-length: 
+      - "640"
+    body: "{\"_type\": \"image\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\", \"id\": \"18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\", \"build\": {\"target_images\": [{\"_type\": \"target_image\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252/target_images/dd9c27c5-0bdb-4670-b172-46a3cf2101a6\", \"id\": \"dd9c27c5-0bdb-4670-b172-46a3cf2101a6\"}], \"_type\": \"build\", \"href\": \"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252\", \"id\": \"6d715c2f-8dc5-46eb-86ad-509366e64252\"}}"
+    http_version: "1.1"
diff --git a/spec/vcr_setup.rb b/spec/vcr_setup.rb
index 0216c9b..5c5ce62 100644
--- a/spec/vcr_setup.rb
+++ b/spec/vcr_setup.rb
@@ -24,11 +24,11 @@ VCR.config do |config|
   config.allow_http_connections_when_no_cassette = true
 end
 
-ActiveResource::Connection.class_eval do
-  def request(method, path, *args)
-    # We want to add :body, but not :headers because they're too fickle with OAuth
-    VCR.use_cassette('oauth', :record => :new_episodes, :match_requests_on => [:method, :uri, :body]) do
-      request_with_oauth(method, path, *args)
-    end
-  end
-end
+# ActiveResource::Connection.class_eval do
+#   def request(method, path, *args)
+#     # We want to add :body, but not :headers because they're too fickle with OAuth
+#     VCR.use_cassette('oauth', :record => :new_episodes, :match_requests_on => [:method, :uri, :body]) do
+#       request_with_oauth(method, path, *args)
+#     end
+#   end
+# end
-- 
1.7.7.6




More information about the aeolus-devel mailing list