deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/2] Core: Added tests for instances and hwp collections
Date Thu, 26 Jul 2012 12:21:20 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 .../hardware_profiles_collection_test.rb           |   51 +++++++++++++++++
 .../deltacloud/collections/keys_collection_test.rb |   60 ++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100644 server/tests/deltacloud/collections/hardware_profiles_collection_test.rb
 create mode 100644 server/tests/deltacloud/collections/keys_collection_test.rb

diff --git a/server/tests/deltacloud/collections/hardware_profiles_collection_test.rb b/server/tests/deltacloud/collections/hardware_profiles_collection_test.rb
new file mode 100644
index 0000000..6ba449a
--- /dev/null
+++ b/server/tests/deltacloud/collections/hardware_profiles_collection_test.rb
@@ -0,0 +1,51 @@
+require 'minitest/autorun'
+require_relative File.join('..', 'common.rb')
+
+describe Deltacloud::Collections::HardwareProfiles do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:hardware_profiles)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::HardwareProfilesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::HardwareProfilesCollection::ShowOperation
+  end
+
+  it 'returns list of hardware profiles in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/hardware_profiles'
+      status.must_equal 200
+    end
+  end
+
+  it 'returns details about hardware profile in various formats with show operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/hardware_profiles/m1-small'
+      status.must_equal 200
+    end
+  end
+
+  it 'returns details for various hardware profile configurations' do
+    get root_url + '/hardware_profiles'
+    status.must_equal 200
+    (xml/'hardware_profiles/hardware_profile').each do |hwp|
+      get root_url + '/hardware_profiles/' + hwp[:id]
+      status.must_equal 200
+      xml.root[:id].must_equal hwp[:id]
+    end
+  end
+
+  it 'reports 404 when querying non-existing hardware profile' do
+    get root_url + '/hardware_profiles/unknown'
+    status.must_equal 404
+  end
+
+end
diff --git a/server/tests/deltacloud/collections/keys_collection_test.rb b/server/tests/deltacloud/collections/keys_collection_test.rb
new file mode 100644
index 0000000..26b58c4
--- /dev/null
+++ b/server/tests/deltacloud/collections/keys_collection_test.rb
@@ -0,0 +1,60 @@
+require 'minitest/autorun'
+require_relative File.join('..', 'common.rb')
+
+describe Deltacloud::Collections::Keys do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:keys)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::KeysCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::KeysCollection::ShowOperation
+  end
+
+  it 'returns list of keys in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/keys'
+      status.must_equal 200
+    end
+  end
+
+  it 'returns details about key in various formats with show operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/keys/test-key'
+      status.must_equal 200
+    end
+  end
+
+  it 'provides URL to create new key' do
+    header 'Accept', 'text/html'
+    get root_url + '/keys/new'
+    status.must_equal 200
+    response_body.must_include 'Create new SSH key'
+  end
+
+  it 'must support creating and destroying keys' do
+    post root_url + '/keys', { :name => 'unit-test1' }
+    status.must_equal 201
+    xml.root.name.must_equal 'key'
+    xml.root[:id].must_equal 'unit-test1'
+    (xml/'key/pem').wont_be_empty
+    post root_url + '/keys', { :name => 'unit-test1' }
+    status.must_equal 403
+    delete root_url + '/keys/unit-test1'
+    status.must_equal 204
+  end
+
+  it 'reports 404 when querying non-existing key' do
+    get root_url + '/keys/unknown'
+    status.must_equal 404
+  end
+
+end
-- 
1.7.10.2


Mime
View raw message