1 |
611959a3
|
Tom McKay
|
require './test/csv_test_helper'
|
2 |
|
|
require './lib/hammer_cli_csv'
|
3 |
|
|
|
4 |
|
|
module Resources
|
5 |
400832c6
|
Tom McKay
|
class TestActivationKeys < MiniTest::Unit::TestCase
|
6 |
611959a3
|
Tom McKay
|
def test_usage
|
7 |
|
|
start_vcr
|
8 |
|
|
set_user 'admin'
|
9 |
|
|
|
10 |
|
|
stdout,stderr = capture {
|
11 |
f370cc85
|
Tom McKay
|
hammer.run(%W{--reload-cache csv activation-keys --help})
|
12 |
611959a3
|
Tom McKay
|
}
|
13 |
|
|
assert_equal '', stderr
|
14 |
|
|
assert_equal stdout, <<-HELP
|
15 |
|
|
Usage:
|
16 |
|
|
csv activation-keys [OPTIONS]
|
17 |
|
|
|
18 |
|
|
Options:
|
19 |
|
|
--continue-on-error Continue processing even if individual resource error
|
20 |
|
|
--export Export current data instead of importing
|
21 |
|
|
--file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required)
|
22 |
|
|
--itemized-subscriptions Export one subscription per row, only process update subscriptions on import
|
23 |
|
|
--organization ORGANIZATION Only process organization matching this name
|
24 |
|
|
-h, --help print help
|
25 |
|
|
-v, --verbose be verbose
|
26 |
|
|
HELP
|
27 |
|
|
stop_vcr
|
28 |
|
|
end
|
29 |
|
|
|
30 |
|
|
def test_create_and_update
|
31 |
|
|
start_vcr
|
32 |
|
|
set_user 'admin'
|
33 |
|
|
|
34 |
|
|
@name = "testakey1"
|
35 |
|
|
|
36 |
|
|
file = Tempfile.new('activation_keys_test')
|
37 |
|
|
file.write("Name,Organization,Description,Limit,Environment,Content View,Host Collections,Auto-Attach,Service Level,Release Version,Subscriptions\n")
|
38 |
|
|
file.write("#{@name},Test Corporation,,,,Default Organization View,"",No,,,\n")
|
39 |
|
|
file.rewind
|
40 |
|
|
|
41 |
|
|
stdout,stderr = capture {
|
42 |
f370cc85
|
Tom McKay
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
|
43 |
611959a3
|
Tom McKay
|
}
|
44 |
|
|
assert_equal '', stderr
|
45 |
|
|
assert_equal stdout[0..-2], "Creating activation key '#{@name}'...done"
|
46 |
|
|
|
47 |
|
|
file.rewind
|
48 |
|
|
|
49 |
|
|
stdout,stderr = capture {
|
50 |
f370cc85
|
Tom McKay
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file #{file.path}})
|
51 |
611959a3
|
Tom McKay
|
}
|
52 |
|
|
assert_equal '', stderr
|
53 |
|
|
assert_equal stdout[0..-2], "Updating activation key '#{@name}'...done"
|
54 |
|
|
file.unlink
|
55 |
|
|
|
56 |
|
|
stdout,stderr = capture {
|
57 |
f370cc85
|
Tom McKay
|
hammer.run(%W(--reload-cache activation-key list --organization Test\ Corporation --search name=#{@name}))
|
58 |
611959a3
|
Tom McKay
|
}
|
59 |
|
|
assert_equal '', stderr
|
60 |
|
|
assert_equal stdout.split("\n").length, 5
|
61 |
|
|
|
62 |
|
|
id = stdout.split("\n")[3].split(" ")[0]
|
63 |
|
|
stdout,stderr = capture {
|
64 |
f370cc85
|
Tom McKay
|
hammer.run(%W(--reload-cache activation-key delete --id #{id}))
|
65 |
611959a3
|
Tom McKay
|
}
|
66 |
|
|
|
67 |
|
|
stop_vcr
|
68 |
|
|
end
|
69 |
d76bdbc0
|
Andrew Kofink
|
|
70 |
|
|
def test_itemized_create_and_update
|
71 |
|
|
stdout,stderr = capture {
|
72 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file test/data/setup/activation-keys.csv})
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
start_vcr
|
76 |
|
|
set_user 'admin'
|
77 |
|
|
|
78 |
|
|
name = "ak1"
|
79 |
|
|
sub_name = "Red Hat Enterprise Linux Server, Premium (8 sockets) (Unlimited guests)"
|
80 |
|
|
quantity = 1
|
81 |
|
|
|
82 |
|
|
file = Tempfile.new('activation_keys_test')
|
83 |
|
|
file.write("Name,Organization,Description,Limit,Environment,Content View,Host\
|
84 |
|
|
Collections,Auto-Attach,Service Level,Release Version,Subscription\
|
85 |
|
|
Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription\
|
86 |
|
|
Contract,Subscription Account,Subscription Start,Subscription End\n")
|
87 |
|
|
file.write("#{name},Default Organization,,,,Default Organization View,\"\",Yes,,,\"#{sub_name}\",Red\
|
88 |
|
|
Hat,#{quantity},RH0105260,10855292,5535485,2016-01-05T05:00:00+00:00,2017-01-05T04:59:59+00:00")
|
89 |
|
|
|
90 |
|
|
file.rewind
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
stdout,stderr = capture {
|
94 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --itemized-subscriptions --file #{file.path}})
|
95 |
|
|
}
|
96 |
|
|
assert_equal '', stderr
|
97 |
|
|
assert_equal stdout[0..-2], "Updating subscriptions for activation key '#{name}'... attaching #{quantity} of '#{sub_name}'...done"
|
98 |
|
|
|
99 |
|
|
file.rewind
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
stdout,stderr = capture {
|
103 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --itemized-subscriptions --file #{file.path}})
|
104 |
|
|
}
|
105 |
|
|
assert_equal '', stderr
|
106 |
|
|
assert_equal stdout[0..-2], "Updating subscriptions for activation key '#{name}'... '#{sub_name}' already attached...done"
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
stdout,stderr = capture {
|
110 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file test/data/setup/activation-keys.csv})
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
file.rewind
|
114 |
|
|
|
115 |
|
|
file.write("Name,Organization,Description,Limit,Environment,Content View,Host\
|
116 |
|
|
Collections,Auto-Attach,Service Level,Release Version,Subscription\
|
117 |
|
|
Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription\
|
118 |
|
|
Contract,Subscription Account,Subscription Start,Subscription End\n")
|
119 |
|
|
file.write("#{name},Default Organization,,,,Default Organization View,\"\",Yes,,,\"#{sub_name}\",Red\
|
120 |
|
|
Hat,Automatic,RH0105260,10855292,5535485,2016-01-05T05:00:00+00:00,2017-01-05T04:59:59+00:00")
|
121 |
|
|
|
122 |
|
|
file.rewind
|
123 |
|
|
|
124 |
|
|
stdout,stderr = capture {
|
125 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --itemized-subscriptions --file #{file.path}})
|
126 |
|
|
}
|
127 |
|
|
assert_equal '', stderr
|
128 |
|
|
assert_equal stdout[0..-2], "Updating subscriptions for activation key '#{name}'... attaching -1 of '#{sub_name}'...done"
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
stdout,stderr = capture {
|
132 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file test/data/setup/activation-keys.csv})
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
file.rewind
|
136 |
|
|
|
137 |
|
|
file.write("Name,Organization,Description,Limit,Environment,Content View,Host\
|
138 |
|
|
Collections,Auto-Attach,Service Level,Release Version,Subscription\
|
139 |
|
|
Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription\
|
140 |
|
|
Contract,Subscription Account,Subscription Start,Subscription End\n")
|
141 |
|
|
file.write("#{name},Default Organization,,,,Default Organization View,\"\",Yes,,,\"#{sub_name}\",Red\
|
142 |
|
|
Hat,,RH0105260,10855292,5535485,2016-01-05T05:00:00+00:00,2017-01-05T04:59:59+00:00")
|
143 |
|
|
|
144 |
|
|
file.rewind
|
145 |
|
|
|
146 |
|
|
stdout,stderr = capture {
|
147 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --itemized-subscriptions --file #{file.path}})
|
148 |
|
|
}
|
149 |
|
|
assert_equal '', stderr
|
150 |
|
|
assert_equal stdout[0..-2], "Updating subscriptions for activation key '#{name}'... attaching -1 of '#{sub_name}'...done"
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
stdout,stderr = capture {
|
154 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --file test/data/setup/activation-keys.csv})
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
file.rewind
|
158 |
|
|
|
159 |
|
|
file.write("Name,Organization,Description,Limit,Environment,Content View,Host\
|
160 |
|
|
Collections,Auto-Attach,Service Level,Release Version,Subscription\
|
161 |
|
|
Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription\
|
162 |
|
|
Contract,Subscription Account,Subscription Start,Subscription End\n")
|
163 |
|
|
file.write("#{name},Default Organization,,,,Default Organization View,\"\",Yes,,,\"#{sub_name}\",Red\
|
164 |
|
|
Hat,\"\",RH0105260,10855292,5535485,2016-01-05T05:00:00+00:00,2017-01-05T04:59:59+00:00")
|
165 |
|
|
|
166 |
|
|
file.rewind
|
167 |
|
|
|
168 |
|
|
stdout,stderr = capture {
|
169 |
|
|
hammer.run(%W{--reload-cache csv activation-keys --verbose --itemized-subscriptions --file #{file.path}})
|
170 |
|
|
}
|
171 |
|
|
assert_equal '', stderr
|
172 |
|
|
assert_equal stdout[0..-2], "Updating subscriptions for activation key '#{name}'... attaching -1 of '#{sub_name}'...done"
|
173 |
|
|
|
174 |
|
|
file.unlink
|
175 |
|
|
|
176 |
|
|
stop_vcr
|
177 |
|
|
end
|
178 |
611959a3
|
Tom McKay
|
end
|
179 |
|
|
end |