Sha256: 74c786d97ba65786e4196cb5d2447123078b7c545c4ff23beed9c1c3e7f688e5

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

require 'tests/deltacloud_test'

class RealmsTest < Test::Unit::TestCase

  def initialize(*args)
    @collection = 'realms'
    @operations = [:index, :show]
    @options = [:id, :name, :state]
    @params = {}
    super(*args)
  end

  def test_if_realms_are_not_empty
    get '/api/realms.xml', @params, rack_headers
    doc = Nokogiri::XML.parse(last_response.body)
    assert_not_equal 0, doc.xpath('/realms/realm').size
  end

  [:id, :name, :state].each do |option|
    method_name = :"test_if_realms_index_contain_#{option}"
    send :define_method, method_name do
      get '/api/realms.xml', @params, rack_headers
      doc = Nokogiri::XML.parse(last_response.body)
      realm = doc.xpath('/realms/realm[1]').first
      assert_not_nil realm.xpath(option.to_s).first
    end
  end

  [:id, :name, :state].each do |option|
    method_name = :"test_if_realm_show_contain_#{option}"
    send :define_method, method_name do
      get '/api/realms/us.xml', @params, rack_headers
      doc = Nokogiri::XML.parse(last_response.body)
      realm = doc.xpath('/realm').first
      assert_not_nil realm.xpath(option.to_s).first
    end
  end

  def test_realms_filtering_by_state
    @params[:state] = 'AVAILABLE'
    get '/api/realms.xml', @params, rack_headers
    doc = Nokogiri::XML.parse(last_response.body)
    assert_equal 2, doc.xpath('/realms/realm').size
    assert_equal @params[:state], doc.xpath('/realms/realm/state').first.text
  end

  def test_realms_filtering_by_id
    get '/api/realms.xml', { :id => 'us'}, rack_headers
    doc = Nokogiri::XML.parse(last_response.body)
    assert_equal 1, doc.xpath('/realms/realm').size
    assert_equal 'us', doc.xpath('/realms/realm/id').first.text
  end

  include DeltacloudTest

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
bbrowning-deltacloud-core-0.0.1.1 tests/realms_test.rb
deltacloud-core-0.0.2 tests/realms_test.rb
deltacloud-core-0.0.1 tests/realms_test.rb