Project

General

Profile

Download (1.49 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / test / roles_test.rb @ d9498f54

1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2
#require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
require 'stringio'
4
require 'tempfile'
5

    
6
describe 'roles tests' do
7

    
8
  extend CommandTestHelper
9

    
10

    
11
  #before :each do
12
  #  HammerCLI::Settings.load_from_file 'test/config'
13
  #end
14

    
15
  context 'roles' do
16

    
17
    it 'basic import' do
18
      set_user 'admin'
19

    
20
      rolename = "role#{rand(10000)}"
21

    
22
      file = Tempfile.new('roles_test')
23
      file.write("Name,Count,Resource,Search,Permissions,Organizations,Locations\n")
24
      file.write("#{rolename},1,ActivationKey,name = key_name,view_activation_keys,Mega Corporation,\n")
25
      file.rewind
26

    
27

    
28
      stdout,stderr = capture {
29
        hammer.run(%W{csv roles --verbose --csv-file #{file.path}})
30
      }
31
      stderr.must_equal ''
32
      stdout[0..-2].must_equal "Creating role '#{rolename}'... creating filter ActivationKey...done"
33
      file.unlink
34
    end
35

    
36
    it 'test role functionality' do
37
      set_user('damon.dials@megacorp.com', 'redhat')
38

    
39
      stdout,stderr = capture {
40
        hammer.run(%W{activation-key list --organization-label megacorp}).must_equal HammerCLI::EX_OK
41
      }
42
      lines = stdout.split("\n")
43
      lines.length.must_equal 5
44
      lines[3].must_match(/.*damon.dials@megacorp\.com.*/)
45

    
46
      id = lines[3].split(' ')[0]
47
      stdout,stderr = capture {
48
        hammer.run(%W{activation-key info --id #{id}}).must_equal HammerCLI::EX_OK
49
      }
50
      stdout.split("\n")[0].must_match(/.*damon.dials@megacorp.com/)
51
    end
52

    
53
  end
54

    
55
end