deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [1/9] git commit: CIMI tests: make sure last_response is set correctly for cached requests
Date Fri, 09 Nov 2012 19:49:38 GMT
Updated Branches:
  refs/heads/master 34f04026c -> 5043e2814


CIMI tests: make sure last_response is set correctly for cached requests

We now cache responses, not model objects, so that we can set last_response
properly when looking up a cached value


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/433fa811
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/433fa811
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/433fa811

Branch: refs/heads/master
Commit: 433fa81152bab39956ac9c344dcc590726aeb63e
Parents: 41932b2
Author: David Lutterkort <lutter@redhat.com>
Authored: Thu Nov 8 16:59:35 2012 -0800
Committer: David Lutterkort <lutter@redhat.com>
Committed: Fri Nov 9 11:48:42 2012 -0800

----------------------------------------------------------------------
 tests/cimi/test_helper.rb |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/433fa811/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 303cce0..3d35aaa 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -166,7 +166,8 @@ class CIMI::Test::Spec < MiniTest::Spec
   end
 
   def fetch(uri, model_class)
-    fetch_model(uri, model_class) { |fmt| get(uri, :accept => fmt) }
+    resp = retrieve(uri, model_class) { |fmt| get(uri, :accept => fmt) }
+    model_class.parse(resp.body, @content_type)
   end
 
   def self.it desc = "anonymous", opts = {}, &block
@@ -191,15 +192,18 @@ class CIMI::Test::Spec < MiniTest::Spec
     define_method name do
       @_memoized ||= {}
       @@_cache ||= {}
-      @_memoized.fetch("#{name}_#{@format}") do |k|
+      resp = @_memoized.fetch("#{name}_#{@format}") do |k|
         if opts[:cache]
           @_memoized[k] = @@_cache.fetch(k) do |k|
-            @@_cache[k] = fetch_model(k, model_class, &block)
+            @@_cache[k] = retrieve(k, model_class, &block)
           end
         else
-          @_memoized[k] = fetch_model(k, model_class, &block)
+          @_memoized[k] = retrieve(k, model_class, &block)
         end
       end
+      @@_cache[:last_response] ||= {}
+      @@_cache[:last_response][@format] = resp
+      model_class.parse(resp.body, @content_type)
     end
   end
 
@@ -211,13 +215,11 @@ class CIMI::Test::Spec < MiniTest::Spec
 
   private
 
-  def fetch_model(k, model_class, &block)
+  def retrieve(k, model_class, &block)
     response = instance_exec(@format, &block)
-    @@_cache[:last_response] ||= {}
-    @@_cache[:last_response][@format] = response
     assert_equal @content_type, response.headers[:content_type]
     # FIXME: for XML check that the correct namespace is set
-    model_class.parse(response.body, @content_type)
+    response
   end
 end
 


Mime
View raw message