Sha256: 99274d3840f70ab782fa60f72d24fa25b3e2fbb954c24699f3799bbe51b67814

Contents?: true

Size: 1.41 KB

Versions: 65

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'test_plugin_helper'
# unit tests for ApiRolesImporter
class ApiRolesImporterTest < ActiveSupport::TestCase
  setup do
    @importer = ForemanAnsible::ApiRolesImporter.new
    first_name = 'test_user.test_name'
    second_name = 'some_user.some_role'
    @test_roles = [AnsibleRole.new(:name => first_name),
                   AnsibleRole.new(:name => second_name)]
  end

  test 'should import roles' do
    @importer.stubs(:prepare_ansible_import_rows).returns(
      [{
        :name => 'test_user.test_name',
        :id => nil,
        :role_action => 'Import Role',
        :variables => 'Add: 7',
        :hosts_count => '',
        :hostgroup_count => '',
        :kind => 'new'
      },
       {
         :name => 'some_user.some_role',
         :id => nil,
         :role_action => 'Import Role',
         :variables => 'Add: 3',
         :hosts_count => '',
         :hostgroup_count => '',
         :kind => 'new'
       }]
    )
    res = @importer.import!([@test_roles.first.name, @test_roles.last.name])
    assert_equal 2, res['changed']['new'].count
  end

  test 'should obsolete roles' do
    @importer.stubs(:import_role_names).returns(:obsolete => @test_roles)
    @test_roles.map(&:save)
    res = @importer.obsolete!
    assert_equal 2, res.count
    refute AnsibleRole.find_by :name => @test_roles.first.name
    refute AnsibleRole.find_by :name => @test_roles.last.name
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 test/unit/services/api_roles_importer_test.rb
foreman_ansible-15.0.1 test/unit/services/api_roles_importer_test.rb
foreman_ansible-15.0.0 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.2.2 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.2.1 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.7 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.2.0 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.1.1 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.1.0 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.5 test/unit/services/api_roles_importer_test.rb
foreman_ansible-14.0.0 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.4 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.3 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.2 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.1 test/unit/services/api_roles_importer_test.rb
foreman_ansible-13.0.0 test/unit/services/api_roles_importer_test.rb
foreman_ansible-12.0.7 test/unit/services/api_roles_importer_test.rb
foreman_ansible-10.4.4 test/unit/services/api_roles_importer_test.rb
foreman_ansible-7.1.8 test/unit/services/api_roles_importer_test.rb
foreman_ansible-12.0.6 test/unit/services/api_roles_importer_test.rb