Sha256: a9dafee281c1ec511304e9b2454c27895fea16e25ee91a4a7d33b611c5c729c5

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 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; run_frontend; 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
    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

  it 'properly serialize attributes in JSON' do
    check_json_serialization_for :key, 'test-key'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deltacloud-core-1.1.1 tests/deltacloud/collections/keys_collection_test.rb
deltacloud-core-1.1.0 tests/deltacloud/collections/keys_collection_test.rb