You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/12/04 09:42:34 UTC

[PATCH 6/6] CIMI tests: use post helper instead of RestClient.post

From: David Lutterkort <lu...@redhat.com>

---
 tests/cimi/part2_test.rb  |    7 +++----
 tests/cimi/part3_test.rb  |    8 ++++----
 tests/cimi/part4_test.rb  |   20 ++++++++++----------
 tests/cimi/part5_test.rb  |    4 ++--
 tests/cimi/test_helper.rb |    4 ++--
 5 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb
index c273614..cc6041d 100644
--- a/tests/cimi/part2_test.rb
+++ b/tests/cimi/part2_test.rb
@@ -56,8 +56,8 @@ end
     cep_json = cep(:accept => :json)
     #discover the 'addURI' for creating Machine
     add_uri = discover_uri_for("add", "machines")
-    RestClient.post(add_uri,
-      "<Machine>" +
+    post(add_uri,
+      "<MachineCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
         "<name>cimi_machine_" + fmt.to_s() + "</name>" +
         "<machineTemplate>" +
           "<machineConfig " +
@@ -65,8 +65,7 @@ end
           "<machineImage " +
             "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
         "</machineTemplate>" +
-      "</Machine>",
-      {'Authorization' => api.basic_auth, :accept => fmt})
+      "</MachineCreate>", :content_type => :xml)
   end
 
   it "should add resource for cleanup" do
diff --git a/tests/cimi/part3_test.rb b/tests/cimi/part3_test.rb
index d7bb45b..9703618 100644
--- a/tests/cimi/part3_test.rb
+++ b/tests/cimi/part3_test.rb
@@ -39,7 +39,7 @@ class CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
   #create a machineTemplate for use in these tests:
   cep_json = cep(:accept => :json)
   mach_templ_add_uri = discover_uri_for("add", "machineTemplates")
-  mach_templ_created = RestClient.post(mach_templ_add_uri,
+  mach_templ_created = post(mach_templ_add_uri,
     "<MachineTemplateCreate>" +
       "<name>cimi_machineTemplate1</name>"+
       "<description>A CIMI MachineTemplate, created by part3_test.rb</description>"+
@@ -49,7 +49,7 @@ class CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
       "<machineImage " +
         "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
     "</MachineTemplateCreate>",
-    {'Authorization' => api.basic_auth, :accept => :json})
+    :accept => :json, :content_type => :xml)
 
   # 3.1: Query the CEP
   model :machineTemplate  do |fmt|
@@ -91,14 +91,14 @@ class CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
     cep_json = cep(:accept => :json)
     #discover the 'addURI' for creating Machine
     add_uri = discover_uri_for("add", "machines")
-    RestClient.post(add_uri,
+    post(add_uri,
       "<Machine>" +
         "<name>cimi_machine_from_template" + fmt.to_s() + "</name>" +
         "<description> Created machine from template" + fmt.to_s() + "</description>" +
         "<machineTemplate " +
           "href=\"" + get_a(cep_json, "machineTemplate")+ "\"/>" +
       "</Machine>",
-    {'Authorization' => api.basic_auth, :accept => fmt})
+         :accept => fmt, :content_type => :xml)
   end
 
   it "should add resource for cleanup" do
diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
index f065104..72f22af 100644
--- a/tests/cimi/part4_test.rb
+++ b/tests/cimi/part4_test.rb
@@ -53,8 +53,8 @@ class AddVolumeToMachine < CIMI::Test::Spec
 # Create a machine to attach the volume
    cep_json = cep(:accept => :json)
    machine_add_uri = discover_uri_for("add", "machines")
-   machine = RestClient.post(machine_add_uri,
-     "<Machine>" +
+   machine = post(machine_add_uri,
+     "<MachineCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
        "<name>cimi_machine</name>" +
        "<machineTemplate>" +
          "<machineConfig " +
@@ -62,13 +62,13 @@ class AddVolumeToMachine < CIMI::Test::Spec
          "<machineImage " +
            "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
        "</machineTemplate>" +
-     "</Machine>",
-     {'Authorization' => api.basic_auth, :accept => :json})
+     "</MachineCreate>",
+                  {:accept => :json, :content_type => :xml})
 
   # 4.3:  Create a new Volume
   model :volume do |fmt|
     volume_add_uri = discover_uri_for("add", "volumes")
-    RestClient.post(volume_add_uri,
+    post(volume_add_uri,
       "<Volume>" +
         "<name>cimi_volume_" + fmt.to_s() +"</name>" +
         "<description>volume for testing</description>" +
@@ -77,7 +77,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
           "</volumeConfig>" +
         "</volumeTemplate>" +
       "</Volume>",
-    {'Authorization' => api.basic_auth, :accept => fmt})
+         :accept => fmt, :content_type => :xml)
   end
 
   it "should add resource machine resource for cleanup", :only => :json do
@@ -105,7 +105,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
 
   log.info(machine.json["id"].to_s() + " is the machine id")
   volume_add_uri = discover_uri_for("add", "volumes")
-  volume = RestClient.post(volume_add_uri,
+  volume = post(volume_add_uri,
   "<Volume>" +
     "<name>cimi_volume_for_attach</name>" +
     "<description>volume for attach testing</description>" +
@@ -114,18 +114,18 @@ class AddVolumeToMachine < CIMI::Test::Spec
       "</volumeConfig>" +
     "</volumeTemplate>" +
   "</Volume>",
-{'Authorization' => api.basic_auth, :accept => :json})
+  :accept => :json, :content_type => :xml)
 
   log.info(volume.json["id"].to_s() + " is the volume id")
   # 4.4: Attach the new Volume to a Machine
   model :machineWithVolume, :only => :xml do
   attach_uri = discover_uri_for_subcollection("add", machine.json['id'], "volumes")
-    RestClient.post(attach_uri,
+    post(attach_uri,
     "<MachineVolume xmlns=\"http://schemas.dmtf.org/cimi/1/MachineVolume\">" +
     "<initialLocation>/dev/sdf</initialLocation>" +
     "<volume href=\"" + volume.json["id"] + "\"/>" +
     "</MachineVolume>",
-    {'Authorization' => api.basic_auth, :accept => :xml})
+    :accept => :xml, :content_type => :xml)
   end
 
   it "should have a response code equal to 201 for attaching a volume", :only => :xml do
diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb
index f1ce6c9..185668a 100644
--- a/tests/cimi/part5_test.rb
+++ b/tests/cimi/part5_test.rb
@@ -34,7 +34,7 @@ class ManipulateAMachine < CIMI::Test::Spec
   cep_json = cep(:accept => :json)
   #discover machine create URI:
   machine_add_uri = discover_uri_for("add", "machines")
-  machine_created = RestClient.post(machine_add_uri,
+  machine_created = post(machine_add_uri,
     "<Machine>" +
       "<name>cimi_machine_part5</name>" +
       "<machineTemplate>" +
@@ -44,7 +44,7 @@ class ManipulateAMachine < CIMI::Test::Spec
           "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
       "</machineTemplate>" +
     "</Machine>",
-    {'Authorization' => api.basic_auth, :accept => :json})
+    :accept => :json, :content_type => :xml)
 
   model :machine do |fmt|
     get machine_created.json["id"], :accept => fmt
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index e967e55..0d318bf 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -233,11 +233,11 @@ module CIMI::Test::Methods
 
     def machine_stop_start(machine, action, state)
       uri = discover_uri_for(action, "", machine.operations)
-      response = RestClient.post( uri,
+      response = post( uri,
             "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
               "<action> http://http://schemas.dmtf.org/cimi/1/action/" + action + "</action>" +
             "</Action>",
-            {'Authorization' => api.basic_auth, :accept => :xml })
+            :accept => :xml, :content_type => :xml)
       response.code.must_equal 202
       poll_state(machine(:refetch => true), state)
       machine(:refetch => true).state.upcase.must_equal state
-- 
1.7.7.6