hammer_cli_foreman 3.0.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/foreman.yml +4 -0
- data/doc/configuration.md +30 -0
- data/doc/release_notes.md +31 -0
- data/lib/hammer_cli_foreman/api/authenticator.rb +9 -0
- data/lib/hammer_cli_foreman/api/connection.rb +2 -0
- data/lib/hammer_cli_foreman/api/negotiate_auth.rb +36 -0
- data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +6 -2
- data/lib/hammer_cli_foreman/api.rb +2 -1
- data/lib/hammer_cli_foreman/auth.rb +13 -0
- data/lib/hammer_cli_foreman/command_extensions/domain.rb +20 -0
- data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
- data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
- data/lib/hammer_cli_foreman/command_extensions.rb +1 -0
- data/lib/hammer_cli_foreman/commands.rb +6 -3
- data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +4 -2
- data/lib/hammer_cli_foreman/compute_resource/vmware.rb +4 -2
- data/lib/hammer_cli_foreman/compute_resource.rb +1 -0
- data/lib/hammer_cli_foreman/domain.rb +5 -28
- data/lib/hammer_cli_foreman/exception_handler.rb +26 -0
- data/lib/hammer_cli_foreman/filter.rb +3 -3
- data/lib/hammer_cli_foreman/host.rb +1 -0
- data/lib/hammer_cli_foreman/hostgroup.rb +13 -6
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -7
- data/lib/hammer_cli_foreman/id_resolver.rb +7 -7
- data/lib/hammer_cli_foreman/option_builders.rb +65 -53
- data/lib/hammer_cli_foreman/option_sources/id_params.rb +21 -8
- data/lib/hammer_cli_foreman/option_sources/ids_params.rb +22 -9
- data/lib/hammer_cli_foreman/partition_table.rb +30 -0
- data/lib/hammer_cli_foreman/report_template.rb +15 -0
- data/lib/hammer_cli_foreman/smart_proxy.rb +18 -5
- data/lib/hammer_cli_foreman/template.rb +33 -15
- data/lib/hammer_cli_foreman/user.rb +5 -4
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/3.1/foreman_api.json +1 -0
- data/test/functional/compute_attribute_test.rb +20 -20
- data/test/functional/domain/create_test.rb +91 -0
- data/test/functional/domain/update_test.rb +90 -0
- data/test/functional/host_test.rb +34 -0
- data/test/functional/hostgroup/create_test.rb +11 -0
- data/test/functional/hostgroup/update_test.rb +11 -0
- data/test/functional/partition_table_test.rb +63 -0
- data/test/functional/personal_access_token_test.rb +4 -4
- data/test/functional/report_template_test.rb +24 -0
- data/test/functional/template_test.rb +134 -14
- data/test/functional/user_mail_notification_test.rb +3 -3
- data/test/test_helper.rb +1 -1
- data/test/unit/commands_test.rb +1 -2
- data/test/unit/option_builders_test.rb +88 -83
- data/test/unit/option_sources/id_params_test.rb +0 -9
- data/test/unit/option_sources/ids_params_test.rb +0 -9
- metadata +54 -44
@@ -11,11 +11,11 @@ describe "parameters" do
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'should print error on missing --compute-profile-id or --compute-profile' do
|
15
15
|
expected_result = common_error_result(
|
16
16
|
@cmd,
|
17
|
-
|
18
|
-
|
17
|
+
'Could not find compute_profile, please set one of options --compute-profile-id, --compute-profile.',
|
18
|
+
'Could not set the compute profile attributes'
|
19
19
|
)
|
20
20
|
|
21
21
|
api_expects_no_call
|
@@ -23,12 +23,12 @@ describe "parameters" do
|
|
23
23
|
assert_cmd(expected_result, result)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should print error on missing --compute-resource-id or --compute-resource' do
|
27
27
|
params = ['--compute-profile-id=1']
|
28
28
|
expected_result = common_error_result(
|
29
29
|
@cmd,
|
30
|
-
|
31
|
-
|
30
|
+
'Could not find compute_resource, please set one of options --compute-resource-id, --compute-resource.',
|
31
|
+
'Could not set the compute profile attributes'
|
32
32
|
)
|
33
33
|
|
34
34
|
api_expects_no_call
|
@@ -103,11 +103,11 @@ describe "parameters" do
|
|
103
103
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--compute-attributes', 'cores=1']
|
104
104
|
|
105
105
|
api_expects(:compute_profiles, :show) do |par|
|
106
|
-
par['id'] == 1
|
106
|
+
par['id'] == '1'
|
107
107
|
end.returns(@compute_profile)
|
108
108
|
|
109
109
|
api_expects(:compute_resources, :show) do |par|
|
110
|
-
par['id'] == 1
|
110
|
+
par['id'] == '1'
|
111
111
|
end.returns(@compute_resource)
|
112
112
|
|
113
113
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -177,7 +177,7 @@ describe "parameters" do
|
|
177
177
|
expected_result.expected_exit_code = HammerCLI::EX_USAGE
|
178
178
|
|
179
179
|
api_expects(:compute_profiles, :show) do |par|
|
180
|
-
par['id'] == 1
|
180
|
+
par['id'] == '1'
|
181
181
|
end.returns(@compute_profile)
|
182
182
|
|
183
183
|
result = run_cmd(@cmd + params)
|
@@ -189,7 +189,7 @@ describe "parameters" do
|
|
189
189
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume', 'size_gb=1']
|
190
190
|
|
191
191
|
api_expects(:compute_profiles, :show) do |par|
|
192
|
-
par['id'] == 1
|
192
|
+
par['id'] == '1'
|
193
193
|
end.returns(@compute_profile)
|
194
194
|
|
195
195
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -261,7 +261,7 @@ describe "parameters" do
|
|
261
261
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume-id=1', '--volume', 'size_gb=1']
|
262
262
|
|
263
263
|
api_expects(:compute_profiles, :show) do |par|
|
264
|
-
par['id'] == 1
|
264
|
+
par['id'] == '1'
|
265
265
|
end.returns(@compute_profile)
|
266
266
|
|
267
267
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -339,7 +339,7 @@ describe "parameters" do
|
|
339
339
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume-id=1']
|
340
340
|
|
341
341
|
api_expects(:compute_profiles, :show) do |par|
|
342
|
-
par['id'] == 1
|
342
|
+
par['id'] == '1'
|
343
343
|
end.returns(@compute_profile)
|
344
344
|
|
345
345
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -438,7 +438,7 @@ describe "parameters" do
|
|
438
438
|
expected_result.expected_exit_code = HammerCLI::EX_USAGE
|
439
439
|
|
440
440
|
api_expects(:compute_profiles, :show) do |par|
|
441
|
-
par['id'] == 1
|
441
|
+
par['id'] == '1'
|
442
442
|
end.returns(@compute_profile)
|
443
443
|
result = run_cmd(@cmd + params)
|
444
444
|
assert_cmd(expected_result, result)
|
@@ -455,7 +455,7 @@ describe "parameters" do
|
|
455
455
|
response = HammerCLIForeman.foreman_api.api.send(:create_fake_response, 404,
|
456
456
|
expected_message, "GET", "http://example.com/", {})
|
457
457
|
api_expects(:compute_profiles, :show) do |par|
|
458
|
-
par['id'] == 200
|
458
|
+
par['id'] == '200'
|
459
459
|
end.raises(RestClient::NotFound, response)
|
460
460
|
|
461
461
|
result = run_cmd(@cmd + params)
|
@@ -465,11 +465,11 @@ describe "parameters" do
|
|
465
465
|
it "should add interface" do
|
466
466
|
params = [ '--interface', 'name=eth0', '--compute-profile-id=1', '--compute-resource-id=1']
|
467
467
|
api_expects(:compute_profiles, :show) do |par|
|
468
|
-
par['id'] == 1
|
468
|
+
par['id'] == '1'
|
469
469
|
end.returns(@compute_profile)
|
470
470
|
|
471
471
|
api_expects(:compute_resources, :show) do |par|
|
472
|
-
par['id'] == 1
|
472
|
+
par['id'] == '1'
|
473
473
|
end.returns(@compute_resource)
|
474
474
|
|
475
475
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -548,11 +548,11 @@ describe "parameters" do
|
|
548
548
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--interface-id=1', '--interface', 'compute_name=eth0']
|
549
549
|
|
550
550
|
api_expects(:compute_profiles, :show) do |par|
|
551
|
-
par['id'] == 1
|
551
|
+
par['id'] == '1'
|
552
552
|
end.returns(@compute_profile)
|
553
553
|
|
554
554
|
api_expects(:compute_resources, :show) do |par|
|
555
|
-
par['id'] == 1
|
555
|
+
par['id'] == '1'
|
556
556
|
end.returns(@compute_resource)
|
557
557
|
|
558
558
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -637,11 +637,11 @@ describe "parameters" do
|
|
637
637
|
params = ['--compute-profile-id=1', '--compute-resource-id=1', '--interface-id=1']
|
638
638
|
|
639
639
|
api_expects(:compute_profiles, :show) do |par|
|
640
|
-
par['id'] == 1
|
640
|
+
par['id'] == '1'
|
641
641
|
end.returns(@compute_profile)
|
642
642
|
|
643
643
|
api_expects(:compute_resources, :show) do |par|
|
644
|
-
par['id'] == 1
|
644
|
+
par['id'] == '1'
|
645
645
|
end.returns(@compute_resource)
|
646
646
|
|
647
647
|
api_expects(:compute_attributes, :update) do |par|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe 'Domain' do
|
4
|
+
describe 'CreateCommand' do
|
5
|
+
let(:cmd) { %w[domain create] }
|
6
|
+
let(:minimal_params) { %w[--name=dom1.com] }
|
7
|
+
|
8
|
+
def domain_params(additional_params = {})
|
9
|
+
params = {
|
10
|
+
domain: {
|
11
|
+
name: 'dom1.com'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
params[:domain].merge!(additional_params)
|
15
|
+
params
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should print error on missing --name' do
|
19
|
+
expected_result = missing_args_error_result(cmd, '--name')
|
20
|
+
|
21
|
+
api_expects_no_call
|
22
|
+
|
23
|
+
result = run_cmd(cmd)
|
24
|
+
assert_cmd(expected_result, result)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'allows minimal options' do
|
28
|
+
api_expects(:domains, :create).with_params(domain_params)
|
29
|
+
|
30
|
+
run_cmd(cmd + minimal_params)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'allows description' do
|
34
|
+
params = %w[--description=shortdesc]
|
35
|
+
api_expects(:domains, :create).with_params(domain_params(fullname: 'shortdesc'))
|
36
|
+
|
37
|
+
run_cmd(cmd + minimal_params + params)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'allows dns id' do
|
41
|
+
params = %w[--dns-id=1]
|
42
|
+
api_expects(:domains, :create).with_params(domain_params(dns_id: 1))
|
43
|
+
|
44
|
+
run_cmd(cmd + minimal_params + params)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'allows dns name' do
|
48
|
+
params = %w[--dns=sp1]
|
49
|
+
api_expects_search(:smart_proxies, { name: 'sp1' }).returns(
|
50
|
+
index_response([{ 'id' => 1 }])
|
51
|
+
)
|
52
|
+
api_expects(:domains, :create).with_params(domain_params(dns_id: 1))
|
53
|
+
|
54
|
+
run_cmd(cmd + minimal_params + params)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'allows location ids' do
|
58
|
+
params = %w[--location-ids=1,4]
|
59
|
+
api_expects(:domains, :create).with_params(domain_params(location_ids: %w[1 4]))
|
60
|
+
|
61
|
+
run_cmd(cmd + minimal_params + params)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'allows location names' do
|
65
|
+
params = %w[--locations=loc1,loc2]
|
66
|
+
api_expects(:locations, :index) do |p|
|
67
|
+
p[:search] == 'name = "loc1" or name = "loc2"'
|
68
|
+
end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
|
69
|
+
api_expects(:domains, :create).with_params(domain_params(location_ids: [1, 2]))
|
70
|
+
|
71
|
+
run_cmd(cmd + minimal_params + params)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'allows organization ids' do
|
75
|
+
params = %w[--organization-ids=1,4]
|
76
|
+
api_expects(:domains, :create).with_params(domain_params(organization_ids: %w[1 4]))
|
77
|
+
|
78
|
+
run_cmd(cmd + minimal_params + params)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'allows organization names' do
|
82
|
+
params = %w[--organizations=org1,org2]
|
83
|
+
api_expects(:organizations, :index) do |p|
|
84
|
+
p[:search] == 'name = "org1" or name = "org2"'
|
85
|
+
end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
|
86
|
+
api_expects(:domains, :create).with_params(domain_params(organization_ids: [1, 2]))
|
87
|
+
|
88
|
+
run_cmd(cmd + minimal_params + params)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe 'Domain' do
|
4
|
+
describe 'UpdateCommand' do
|
5
|
+
let(:cmd) { %w[domain update] }
|
6
|
+
let(:minimal_params) { %w[--id=1] }
|
7
|
+
|
8
|
+
def domain_params(additional_params = {})
|
9
|
+
params = {
|
10
|
+
id: '1',
|
11
|
+
domain: {}
|
12
|
+
}
|
13
|
+
params[:domain].merge!(additional_params)
|
14
|
+
params
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should print error on missing --id' do
|
18
|
+
expected_result = missing_args_error_result(cmd, '--id')
|
19
|
+
|
20
|
+
api_expects_no_call
|
21
|
+
|
22
|
+
result = run_cmd(cmd)
|
23
|
+
assert_cmd(expected_result, result)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'allows minimal options' do
|
27
|
+
api_expects(:domains, :update).with_params(domain_params)
|
28
|
+
|
29
|
+
run_cmd(cmd + minimal_params)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'allows description' do
|
33
|
+
params = %w[--description=shortdesc]
|
34
|
+
api_expects(:domains, :update).with_params(domain_params(fullname: 'shortdesc'))
|
35
|
+
|
36
|
+
run_cmd(cmd + minimal_params + params)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'allows dns id' do
|
40
|
+
params = %w[--dns-id=1]
|
41
|
+
api_expects(:domains, :update).with_params(domain_params(dns_id: 1))
|
42
|
+
|
43
|
+
run_cmd(cmd + minimal_params + params)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'allows dns name' do
|
47
|
+
params = %w[--dns=sp1]
|
48
|
+
api_expects_search(:smart_proxies, { name: 'sp1' }).returns(
|
49
|
+
index_response([{ 'id' => 1 }])
|
50
|
+
)
|
51
|
+
api_expects(:domains, :update).with_params(domain_params(dns_id: 1))
|
52
|
+
|
53
|
+
run_cmd(cmd + minimal_params + params)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'allows location ids' do
|
57
|
+
params = %w[--location-ids=1,4]
|
58
|
+
api_expects(:domains, :update).with_params(domain_params(location_ids: %w[1 4]))
|
59
|
+
|
60
|
+
run_cmd(cmd + minimal_params + params)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'allows location names' do
|
64
|
+
params = %w[--locations=loc1,loc2]
|
65
|
+
api_expects(:locations, :index) do |p|
|
66
|
+
p[:search] == 'name = "loc1" or name = "loc2"'
|
67
|
+
end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
|
68
|
+
api_expects(:domains, :update).with_params(domain_params(location_ids: [1, 2]))
|
69
|
+
|
70
|
+
run_cmd(cmd + minimal_params + params)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'allows organization ids' do
|
74
|
+
params = %w[--organization-ids=1,4]
|
75
|
+
api_expects(:domains, :update).with_params(domain_params(organization_ids: %w[1 4]))
|
76
|
+
|
77
|
+
run_cmd(cmd + minimal_params + params)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'allows organization names' do
|
81
|
+
params = %w[--organizations=org1,org2]
|
82
|
+
api_expects(:organizations, :index) do |p|
|
83
|
+
p[:search] == 'name = "org1" or name = "org2"'
|
84
|
+
end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
|
85
|
+
api_expects(:domains, :update).with_params(domain_params(organization_ids: [1, 2]))
|
86
|
+
|
87
|
+
run_cmd(cmd + minimal_params + params)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -568,7 +568,41 @@ describe 'disassociate host from vm' do
|
|
568
568
|
end
|
569
569
|
end
|
570
570
|
|
571
|
+
describe 'defaults' do
|
572
|
+
let(:cmd) { %w[host list] }
|
573
|
+
let(:defaults) do
|
574
|
+
HammerCLI::Defaults.new(
|
575
|
+
{
|
576
|
+
organization_id: {
|
577
|
+
value: '1'
|
578
|
+
},
|
579
|
+
organization: {
|
580
|
+
value: 'Default Organization'
|
581
|
+
}
|
582
|
+
}
|
583
|
+
)
|
584
|
+
end
|
585
|
+
|
586
|
+
it 'works with default org name overridden via cli' do
|
587
|
+
params = %w[--organization=Org2]
|
571
588
|
|
589
|
+
api_expects_search(:organizations, name: 'Org2').returns(index_response([{ 'id' => '2' }]))
|
590
|
+
api_expects(:hosts, :index) do |p|
|
591
|
+
p['organization_id'] == '2'
|
592
|
+
end
|
593
|
+
|
594
|
+
run_cmd(cmd + params, { use_defaults: true, defaults: defaults })
|
595
|
+
end
|
596
|
+
it 'works with default org id overridden via cli' do
|
597
|
+
params = %w[--organization-id=2]
|
598
|
+
|
599
|
+
api_expects(:hosts, :index) do |p|
|
600
|
+
p['organization_id'] == '2'
|
601
|
+
end
|
602
|
+
|
603
|
+
run_cmd(cmd + params, { use_defaults: true, defaults: defaults })
|
604
|
+
end
|
605
|
+
end
|
572
606
|
|
573
607
|
describe 'list' do
|
574
608
|
before do
|
@@ -165,6 +165,17 @@ module HammerCLIForeman
|
|
165
165
|
run_cmd(%w(hostgroup create --name hg1 --parent parent_hg))
|
166
166
|
end
|
167
167
|
|
168
|
+
it 'allows parent hostgroup title' do
|
169
|
+
api_expects(:hostgroups, :index) do |p|
|
170
|
+
p[:search] = 'title = "parent_hg"'
|
171
|
+
end.returns(index_response([{ 'id' => 1 }]))
|
172
|
+
api_expects(:hostgroups, :create) do |p|
|
173
|
+
p['hostgroup']['parent_id'] == 1 &&
|
174
|
+
p['hostgroup']['name'] == 'hg1'
|
175
|
+
end
|
176
|
+
run_cmd(%w[hostgroup create --name hg1 --parent parent_hg])
|
177
|
+
end
|
178
|
+
|
168
179
|
it 'allows partition table id' do
|
169
180
|
api_expects(:hostgroups, :create) do |p|
|
170
181
|
p['hostgroup']['ptable_id'] == 1 &&
|
@@ -163,6 +163,17 @@ module HammerCLIForeman
|
|
163
163
|
run_cmd(%w(hostgroup update --id 1 --parent parent_hg))
|
164
164
|
end
|
165
165
|
|
166
|
+
it 'allows parent hostgroup title' do
|
167
|
+
api_expects(:hostgroups, :index) do |p|
|
168
|
+
p[:search] = 'title = "parent_hg"'
|
169
|
+
end.returns(index_response([{ 'id' => 1 }]))
|
170
|
+
api_expects(:hostgroups, :update) do |p|
|
171
|
+
p['hostgroup']['parent_id'] == 1 &&
|
172
|
+
p['id'] == '1'
|
173
|
+
end
|
174
|
+
run_cmd(%w[hostgroup update --id 1 --parent parent_hg])
|
175
|
+
end
|
176
|
+
|
166
177
|
it 'allows partition table id' do
|
167
178
|
api_expects(:hostgroups, :update) do |p|
|
168
179
|
p['hostgroup']['ptable_id'] == 1 &&
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'partition-table' do
|
4
|
+
describe 'import' do
|
5
|
+
let(:template) do
|
6
|
+
{
|
7
|
+
'id' => 1,
|
8
|
+
'template' => 'Template content'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
let(:cmd) { %w(partition-table import) }
|
12
|
+
let(:tempfile) { Tempfile.new('template') }
|
13
|
+
|
14
|
+
it 'requires --name and --file' do
|
15
|
+
params = ['--name=test']
|
16
|
+
api_expects_no_call
|
17
|
+
expected_result = usage_error_result(
|
18
|
+
cmd,
|
19
|
+
'Options --name, --file are required.',
|
20
|
+
'Could not import partition table template')
|
21
|
+
result = run_cmd(cmd + params)
|
22
|
+
assert_cmd(expected_result, result)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'import template' do
|
26
|
+
params = ['--name=test', "--file=#{tempfile.path}"]
|
27
|
+
tempfile.write('Template content')
|
28
|
+
tempfile.rewind
|
29
|
+
api_expects(:ptables, :import, 'Import partition table template').with_params(
|
30
|
+
'ptable' => {
|
31
|
+
'name' => 'test',
|
32
|
+
'template' => 'Template content'
|
33
|
+
}).returns(template)
|
34
|
+
|
35
|
+
result = run_cmd(cmd + params)
|
36
|
+
assert_cmd(success_result("Import partition table template succeeded.\n"), result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'export' do
|
41
|
+
let(:cmd) { %w(partition-table export) }
|
42
|
+
let(:tempfile) { Tempfile.new('template', '/tmp') }
|
43
|
+
let(:params) { ['--id=1', '--path=/tmp'] }
|
44
|
+
let(:template_response) do
|
45
|
+
response = mock('TemplateResponse')
|
46
|
+
response.stubs(:code).returns(200)
|
47
|
+
response.stubs(:body).returns('Template content')
|
48
|
+
response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
|
49
|
+
response
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'download template' do
|
53
|
+
api_expects(:ptables, :export, 'Export partition table template').with_params(
|
54
|
+
'id' => '1').returns(template_response)
|
55
|
+
|
56
|
+
output = OutputMatcher.new("The partition table template has been saved to #{tempfile.path}")
|
57
|
+
expected_result = success_result(output)
|
58
|
+
result = run_cmd(cmd + params)
|
59
|
+
assert_cmd(expected_result, result)
|
60
|
+
assert_equal('Template content', tempfile.read)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -37,7 +37,7 @@ describe 'personal_access_token' do
|
|
37
37
|
|
38
38
|
it 'lists all access tokens for a given user' do
|
39
39
|
api_expects(:personal_access_tokens, :index, 'List').with_params(
|
40
|
-
'user_id' => 1, 'page' => 1, 'per_page' => 1000
|
40
|
+
'user_id' => '1', 'page' => 1, 'per_page' => 1000
|
41
41
|
).returns(index_response([access_token, active_access_token]))
|
42
42
|
|
43
43
|
output = IndexMatcher.new([
|
@@ -67,7 +67,7 @@ describe 'personal_access_token' do
|
|
67
67
|
|
68
68
|
it 'creates an access token to a given user' do
|
69
69
|
api_expects(:personal_access_tokens, :create).with_params(
|
70
|
-
'user_id' => 1, 'personal_access_token' => {
|
70
|
+
'user_id' => '1', 'personal_access_token' => {
|
71
71
|
'expires_at' => '01/01/2048', 'name' => 'test'
|
72
72
|
}
|
73
73
|
).returns(access_token)
|
@@ -85,7 +85,7 @@ describe 'personal_access_token' do
|
|
85
85
|
|
86
86
|
it 'shows the personal access token' do
|
87
87
|
api_expects(:personal_access_tokens, :show, 'Show PAT').with_params(
|
88
|
-
'id' => '1', 'user_id' => 1
|
88
|
+
'id' => '1', 'user_id' => '1'
|
89
89
|
).returns(access_token)
|
90
90
|
|
91
91
|
output = OutputMatcher.new([
|
@@ -109,7 +109,7 @@ describe 'personal_access_token' do
|
|
109
109
|
let(:params) { ['--id=1', '--user-id=1'] }
|
110
110
|
it 'deletes an access token to a given user' do
|
111
111
|
api_expects(:personal_access_tokens, :destroy, 'Revoke PAT').with_params(
|
112
|
-
'id' => '1', 'user_id' => 1
|
112
|
+
'id' => '1', 'user_id' => '1'
|
113
113
|
).returns(access_token)
|
114
114
|
|
115
115
|
expected_result = success_result(
|
@@ -384,6 +384,30 @@ describe 'report-template' do
|
|
384
384
|
end
|
385
385
|
end
|
386
386
|
|
387
|
+
describe 'export' do
|
388
|
+
let(:cmd) { %w(report-template export) }
|
389
|
+
let(:tempfile) { Tempfile.new('template', '/tmp') }
|
390
|
+
let(:params) { ['--id=1', '--path=/tmp'] }
|
391
|
+
let(:template_response) do
|
392
|
+
response = mock('TemplateResponse')
|
393
|
+
response.stubs(:code).returns(200)
|
394
|
+
response.stubs(:body).returns('Template content')
|
395
|
+
response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
|
396
|
+
response
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'download template' do
|
400
|
+
api_expects(:report_templates, :export, 'Export report template').with_params(
|
401
|
+
'id' => '1').returns(template_response)
|
402
|
+
|
403
|
+
output = OutputMatcher.new("The report template has been saved to #{tempfile.path}")
|
404
|
+
expected_result = success_result(output)
|
405
|
+
result = run_cmd(cmd + params)
|
406
|
+
assert_cmd(expected_result, result)
|
407
|
+
assert_equal('Template content', tempfile.read)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
387
411
|
describe 'report-data' do
|
388
412
|
let(:cmd) { %w(report-template report-data) }
|
389
413
|
let(:tempfile) { Tempfile.new('template', '/tmp') }
|