deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 5/5] CIMI: Added initial support for CIMI collections tests
Date Tue, 31 Jul 2012 12:33:29 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/Rakefile                                    |    2 +
 .../cimi/collections/cloud_entry_point_test.rb     |   43 ++++++++++++++++++++
 server/tests/cimi/collections/common.rb            |   22 ++++++++++
 .../tests/cimi/collections/machine_images_test.rb  |   42 +++++++++++++++++++
 server/tests/cimi/collections/machines_test.rb     |   39 ++++++++++++++++++
 5 files changed, 148 insertions(+)
 create mode 100644 server/tests/cimi/collections/cloud_entry_point_test.rb
 create mode 100644 server/tests/cimi/collections/common.rb
 create mode 100644 server/tests/cimi/collections/machine_images_test.rb
 create mode 100644 server/tests/cimi/collections/machines_test.rb

diff --git a/server/Rakefile b/server/Rakefile
index ec3984b..184fe6c 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -185,11 +185,13 @@ namespace :test do
   namespace :cimi do
     Rake::TestTask.new(:models) do |t|
       t.ruby_opts << '-r./tests/cimi/spec/spec_helper.rb'    # Load SimpleCov when
COVERAGE=1 is set
+      t.ruby_opts << '-r./tests/test_helper.rb'    # Load SimpleCov when COVERAGE=1
is set
       unless RUBY_VERSION < '1.9.0'
         t.loader = :testrb
       end
       t.test_files = FileList[
         'tests/cimi/spec/cimi/model/*spec.rb',        # CIMI frontend serialization API tests
+        'tests/cimi/collections/*test.rb',        # CIMI frontend API tests
       ]
     end
   end
diff --git a/server/tests/cimi/collections/cloud_entry_point_test.rb b/server/tests/cimi/collections/cloud_entry_point_test.rb
new file mode 100644
index 0000000..7603a3d
--- /dev/null
+++ b/server/tests/cimi/collections/cloud_entry_point_test.rb
@@ -0,0 +1,43 @@
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::CloudEntryPoint do
+
+  before do
+    def app; CIMI::API; end
+    @collection = CIMI::Collections.collection(:cloudEntryPoint)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::CloudentrypointCollection::IndexOperation
+  end
+
+  it 'set the CIMI-Version header' do
+    get root_url
+    headers['X-CIMI-Specification-Version'].wont_be_nil
+    headers['X-CIMI-Specification-Version'].must_equal '1.0.0'
+  end
+
+  it 'advertise CIMI collections in XML format' do
+    get root_url + '/cloudEntryPoint'
+    xml.root.name.must_equal 'CloudEntryPoint'
+    (xml.root/'description').first.text.wont_be_empty
+    (xml.root/'id').first.text.wont_be_empty
+  end
+
+  it 'advertise CIMI collections in JSON format' do
+    get root_url + '/cloudEntryPoint?format=json'
+    json.wont_be_empty
+    json['description'].wont_be_empty
+    json['id'].wont_be_empty
+  end
+
+  it 'allow to force authentication using force_auth parameter in URI' do
+    get root_url + '/cloudEntryPoint?force_auth=1'
+    status.must_equal 401
+    authorize 'mockuser', 'mockpassword'
+    get root_url + '/cloudEntryPoint?force_auth=1'
+    status.must_equal 200
+  end
+
+end
diff --git a/server/tests/cimi/collections/common.rb b/server/tests/cimi/collections/common.rb
new file mode 100644
index 0000000..f24e7b1
--- /dev/null
+++ b/server/tests/cimi/collections/common.rb
@@ -0,0 +1,22 @@
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud_rack.rb')
+
+# Set the default driver used for server API tests
+#
+ENV['API_DRIVER'] = 'mock'
+
+# Setup Deltacloud::API Sinatra instance
+#
+unless Deltacloud::config[:cimi]
+  Deltacloud::configure(:cimi) do |server|
+    server.root_url '/cimi'
+    server.version '1.0.0'
+    server.klass 'CIMI::API'
+    server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
+  end
+
+  Deltacloud.require_frontend!(:cimi)
+end
+
+def root_url(url=''); Deltacloud.config[:cimi].root_url + url; end
+def formats; [ 'application/xml', 'application/json' ]; end
+def json; JSON::parse(response_body); end
diff --git a/server/tests/cimi/collections/machine_images_test.rb b/server/tests/cimi/collections/machine_images_test.rb
new file mode 100644
index 0000000..f8df8b5
--- /dev/null
+++ b/server/tests/cimi/collections/machine_images_test.rb
@@ -0,0 +1,42 @@
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::MachineImages do
+
+  before do
+    def app; CIMI::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = CIMI::Collections.collection(:machine_images)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::MachineImagesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::MachineImagesCollection::ShowOperation
+  end
+
+  it 'returns list of images in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/machine_images'
+      status.must_equal 200
+    end
+  end
+
+  it 'should allow to retrieve the single image' do
+    get root_url '/machine_images/img1'
+    status.must_equal 200
+    xml.root.name.must_equal 'MachineImage'
+  end
+
+  it 'should allow to filter using CIMISelect' do
+    get root_url '/machine_images?CIMISelect=description'
+    status.must_equal 200
+    xml.root.name.must_equal 'MachineImageCollection'
+    (xml/'description').wont_be_empty
+    (xml/'id').must_be_empty
+  end
+
+end
diff --git a/server/tests/cimi/collections/machines_test.rb b/server/tests/cimi/collections/machines_test.rb
new file mode 100644
index 0000000..aa3360e
--- /dev/null
+++ b/server/tests/cimi/collections/machines_test.rb
@@ -0,0 +1,39 @@
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::Machines do
+
+  before do
+    def app; CIMI::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = CIMI::Collections.collection(:machines)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::MachinesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::MachinesCollection::ShowOperation
+  end
+
+  it 'returns list of machines in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/machines'
+      status.must_equal 200
+    end
+  end
+
+  it 'should allow to retrieve the single machine' do
+    get root_url '/machines/inst1'
+    status.must_equal 200
+    xml.root.name.must_equal 'Machine'
+  end
+
+  it 'should not return non-existing machine' do
+    get root_url '/machines/unknown-machine'
+    status.must_equal 404
+  end
+
+end
-- 
1.7.10.2


Mime
View raw message