Sha256: 2d139e4acc41bb0333b12efc3de99b2bd74e4e4f15809f0b7c8770953319842d

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require 'rubygems'
require 'require_relative' if RUBY_VERSION < '1.9'

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
    Proc.new {
      post root_url + '/keys', { :name => 'unit-test1' }
    }.must_raise Deltacloud::ExceptionHandler::ProviderError, 'keyExist'
    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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deltacloud-core-1.0.3 tests/deltacloud/collections/keys_collection_test.rb
deltacloud-core-1.0.2 tests/deltacloud/collections/keys_collection_test.rb