deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 2/3] Initial API (black box) server tests for CIMI Networks collection
Date Mon, 05 Nov 2012 15:12:36 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 tests/cimi/networks_test.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tests/cimi/test_helper.rb   | 43 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 82 insertions(+), 5 deletions(-)
 create mode 100644 tests/cimi/networks_test.rb

diff --git a/tests/cimi/networks_test.rb b/tests/cimi/networks_test.rb
new file mode 100644
index 0000000..dc6a3cf
--- /dev/null
+++ b/tests/cimi/networks_test.rb
@@ -0,0 +1,44 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you 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.
+
+$:.unshift File.join(File.dirname(__FILE__))
+
+require "test_helper.rb"
+
+#def each_collection_member(collection, &block)
+#  res = get(collection)
+#  res.xml.xpath("/xmlns:Collection/xmlns:#{collection.camelize.singularize}").each do |member|
+#    yield member
+#  end
+#end
+
+NETWORKS = "/networks"
+test_collection = "networks"
+describe "CIMI Networks collection" do
+
+  include CIMI::Test::Methods
+  need_collection :networks
+
+  it "must advertise the Networks collection in API entrypoint" do
+    res = cep.xml #get(NETWORKS).xml
+    (res/"networks").wont_be_empty
+  end
+
+  #Run the common collection and member tests:
+  CommonCIMICollectionsTest::run_collection_and_member_tests_for("networks")
+
+
+end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 8fd850a..adee8c3 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -17,7 +17,7 @@
 require 'rubygems'
 require 'require_relative'
 require_relative '../helpers/common.rb'
-
+require_relative 'common_tests_cimi_collections.rb'
 require 'singleton'
 require_relative "../../server/lib/cimi/models"
 
@@ -37,8 +37,18 @@ module CIMI
         @cimi["cep"]
       end
 
+      def cimi_root
+        @cimi["cep"].sub("/cloudEntryPoint", "")
+      end
+
+      def basic_auth(u = nil, p = nil)
+        u ||= @cimi["user"]
+        p ||= @cimi["password"]
+        "Basic #{Base64.encode64("#{u}:#{p}")}"
+      end
+
       def collections
-        xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name }
+        xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name.to_sym }
       end
 
       def features
@@ -67,6 +77,14 @@ end
 module CIMI::Test::Methods
 
   module Global
+
+    def each_collection_member(collection, &block)
+      res = get(collection)
+      res.xml.xpath("/xmlns:Collection/xmlns:#{collection.camelize.singularize}").each do
|member|
+        yield member
+      end
+    end
+
     def api
       CIMI::Test::config
     end
@@ -76,18 +94,33 @@ module CIMI::Test::Methods
     end
 
     def get(path, params = {})
-      RestClient.get path, headers(params)
+      url, headers = url_headers(path, params)
+      RestClient.get url, headers
     end
 
     private
-    def headers(params)
+    def url_headers(path, params)
       headers = {}
+      unless params.delete(:noauth)
+        if params[:user]
+          u = params.delete(:user)
+          p = params.delete(:password)
+          headers['Authorization'] = api.basic_auth(u, p)
+        else
+          headers['Authorization'] = api.basic_auth
+        end
+      end
       if params[:accept]
         headers["Accept"] = "application/#{params.delete(:accept)}" if params[:accept]
       else #default to xml
         headers["Accept"] = "application/xml"
       end
-      headers
+      if path =~ /^https?:/
+        url = path
+      else
+        url = path.start_with?("/") ? api.cimi_root + path : api.cimi_root+"/#{path}"
+      end
+      [url, headers]
     end
   end
 
-- 
1.7.11.7


Mime
View raw message