Sha256: 8c96b0fc4a0887f036a51ef7f90418e257e6ae84df0bceaafbbad492d98b3e85

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require 'test_plugin_helper'

module Api
  module V2
    # Tests for the extra methods to play roles on a Host
    class HostsControllerTest < ActionController::TestCase
      setup do
        @host1 = FactoryBot.create(:host)
        @host2 = FactoryBot.create(:host)
      end

      test 'should return an not_found due to non-existent host_id' do
        post :play_roles, :params => { :id => 'non-existent' }
        response = JSON.parse(@response.body)
        refute_empty response
        assert_response :not_found
      end

      test 'should trigger task on host' do
        load File.join(ForemanAnsible::Engine.root,
                       '/db/seeds.d/75_job_templates.rb')
        ::JobInvocationComposer.any_instance.expects(:trigger!).returns(true)
        targets = @host1.id
        post :play_roles, :params => { :id => targets }
        response = JSON.parse(@response.body)
        assert_job_invocation_is_ok(response, targets)
      end

      test 'should trigger two host tasks' do
        load File.join(ForemanAnsible::Engine.root,
                       '/db/seeds.d/75_job_templates.rb')
        ::JobInvocationComposer.any_instance.expects(:trigger!).returns(true)
        targets = [@host1.id, @host2.id]

        post :multiple_play_roles, :params => { :id => targets }
        response = JSON.parse(@response.body)
        assert_job_invocation_is_ok(response, targets)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman_ansible-2.1.2 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.1.1 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.0.4 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.0.3 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.0.2 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.1.0 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.0.1 test/functional/api/v2/hosts_controller_test.rb
foreman_ansible-2.0.0 test/functional/api/v2/hosts_controller_test.rb