Revision 561a8ac9
Added by Thomas McKay over 8 years ago
test/roles_test.rb | ||
---|---|---|
3 | 3 |
require 'stringio' |
4 | 4 |
require 'tempfile' |
5 | 5 |
|
6 |
describe 'something' do
|
|
6 |
describe 'roles tests' do
|
|
7 | 7 |
|
8 | 8 |
extend CommandTestHelper |
9 | 9 |
|
10 | 10 |
|
11 |
before :each do |
|
12 |
HammerCLI::Settings.load_from_file 'test/config.yml' |
|
13 |
end |
|
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 |
|
14 | 26 |
|
15 |
context 'activation keys' do |
|
16 | 27 |
|
17 |
# Expected output of the form: |
|
18 |
# ID,Name,Consumed |
|
19 |
# 1,damon.dials@megacorp.com,0 of Unlimited |
|
20 |
it 'allows show' do |
|
21 |
set_user 'damon.dials@megacorp.com' |
|
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') |
|
22 | 38 |
|
23 | 39 |
stdout,stderr = capture { |
24 |
hammer.run(%W{activation-key list --organization-id megacorp}).must_equal HammerCLI::EX_OK
|
|
40 |
hammer.run(%W{activation-key list --organization-label megacorp}).must_equal HammerCLI::EX_OK
|
|
25 | 41 |
} |
26 | 42 |
lines = stdout.split("\n") |
27 |
lines.length.must_equal 2
|
|
28 |
lines[1].must_match /.*damon.dials@megacorp\.com.*/
|
|
43 |
lines.length.must_equal 5
|
|
44 |
lines[3].must_match /.*damon.dials@megacorp\.com.*/
|
|
29 | 45 |
|
30 |
id = lines[1].split(',')[0]
|
|
46 |
id = lines[3].split(' ')[0]
|
|
31 | 47 |
stdout,stderr = capture { |
32 | 48 |
hammer.run(%W{activation-key info --id #{id}}).must_equal HammerCLI::EX_OK |
33 | 49 |
} |
34 |
stdout.split("\n")[1].must_match /.*damon.dials@megacorp.com,[0-9]+,Individual account,Library,Default Organization View/
|
|
50 |
stdout.split("\n")[0].must_match /.*damon.dials@megacorp.com/
|
|
35 | 51 |
end |
36 | 52 |
|
37 | 53 |
end |
Also available in: Unified diff
update roles use of api with test and docs
Note: The roles test does not work completely since changing user is not working. Unsure how to accomplish this. Tests run as admin do work.