hammer_cli_foreman 2.1.2 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +35 -4
  3. data/doc/testing.md +13 -0
  4. data/lib/hammer_cli_foreman.rb +0 -4
  5. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  6. data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
  7. data/lib/hammer_cli_foreman/auth.rb +4 -4
  8. data/lib/hammer_cli_foreman/bookmark.rb +6 -6
  9. data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
  10. data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
  11. data/lib/hammer_cli_foreman/commands.rb +3 -1
  12. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  13. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
  14. data/lib/hammer_cli_foreman/config_group.rb +5 -5
  15. data/lib/hammer_cli_foreman/host.rb +3 -2
  16. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +17 -10
  17. data/lib/hammer_cli_foreman/location.rb +2 -0
  18. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  19. data/lib/hammer_cli_foreman/model.rb +5 -5
  20. data/lib/hammer_cli_foreman/operating_system.rb +10 -9
  21. data/lib/hammer_cli_foreman/organization.rb +2 -0
  22. data/lib/hammer_cli_foreman/output/fields.rb +1 -1
  23. data/lib/hammer_cli_foreman/output/formatters.rb +1 -1
  24. data/lib/hammer_cli_foreman/ping.rb +20 -11
  25. data/lib/hammer_cli_foreman/references.rb +16 -0
  26. data/lib/hammer_cli_foreman/settings.rb +16 -2
  27. data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -0
  28. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  29. data/lib/hammer_cli_foreman/version.rb +1 -1
  30. data/lib/minitest/coverage_reporter.rb +94 -0
  31. data/lib/minitest/hammer_coverage_plugin.rb +19 -0
  32. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/test/functional/architecture_test.rb +49 -0
  46. data/test/functional/audit_test.rb +86 -63
  47. data/test/functional/bookmark_test.rb +20 -0
  48. data/test/functional/commands/list_test.rb +11 -11
  49. data/test/functional/compute_profile_test.rb +47 -2
  50. data/test/functional/config_group_test.rb +50 -0
  51. data/test/functional/filter_test.rb +114 -47
  52. data/test/functional/host_test.rb +105 -19
  53. data/test/functional/location_test.rb +134 -0
  54. data/test/functional/mail_notification_test.rb +20 -0
  55. data/test/functional/media_test.rb +130 -0
  56. data/test/functional/model_test.rb +50 -0
  57. data/test/functional/operating_system_test.rb +51 -0
  58. data/test/functional/organization_test.rb +52 -0
  59. data/test/functional/realm_test.rb +103 -0
  60. data/test/functional/role_test.rb +9 -12
  61. data/test/functional/settings_test.rb +78 -1
  62. data/test/functional/status_test.rb +79 -13
  63. data/test/functional/user_test.rb +39 -0
  64. data/test/functional/usergroup_test.rb +51 -0
  65. data/test/test_helper.rb +5 -2
  66. data/test/unit/api/interactive_basic_auth_test.rb +3 -1
  67. data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +2 -2
  68. data/test/unit/api/oauth/oauth_password_grant_test.rb +2 -2
  69. data/test/unit/api_test.rb +3 -4
  70. data/test/unit/apipie_resource_mock.rb +25 -4
  71. data/test/unit/architecture_test.rb +10 -1
  72. data/test/unit/bookmark_test.rb +99 -0
  73. data/test/unit/commands_test.rb +19 -19
  74. data/test/unit/common_parameter_test.rb +1 -1
  75. data/test/unit/compute_profile_test.rb +87 -0
  76. data/test/unit/config_group_test.rb +10 -0
  77. data/test/unit/dependency_resolver_test.rb +4 -4
  78. data/test/unit/exception_handler_test.rb +13 -13
  79. data/test/unit/helpers/command.rb +5 -5
  80. data/test/unit/helpers/resource_disabled.rb +2 -2
  81. data/test/unit/host_test.rb +1 -24
  82. data/test/unit/id_resolver_test.rb +23 -23
  83. data/test/unit/mail_notification_test.rb +53 -0
  84. data/test/unit/media_test.rb +1 -1
  85. data/test/unit/model_test.rb +10 -0
  86. data/test/unit/operating_system_test.rb +14 -1
  87. data/test/unit/option_builders_test.rb +49 -49
  88. data/test/unit/option_sources/id_params_test.rb +2 -2
  89. data/test/unit/option_sources/ids_params_test.rb +2 -2
  90. data/test/unit/output/formatters_test.rb +21 -21
  91. data/test/unit/param_filters_test.rb +17 -17
  92. data/test/unit/partition_table_test.rb +2 -2
  93. data/test/unit/role_test.rb +2 -2
  94. data/test/unit/sessions_test.rb +24 -24
  95. data/test/unit/settings_test.rb +4 -0
  96. data/test/unit/template_test.rb +1 -1
  97. data/test/unit/usergroup_test.rb +10 -0
  98. metadata +26 -7
  99. data/lib/hammer_cli_foreman/trend.rb +0 -47
  100. data/test/functional/trend_test.rb +0 -22
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_helper')
4
+
5
+ describe 'config_group' do
6
+ describe 'list' do
7
+ before do
8
+ @cmd = %w[config-group list]
9
+ @config_groups = [{
10
+ id: 1,
11
+ name: 'config-group-test',
12
+ }]
13
+ end
14
+
15
+ it 'should return a list of config groups' do
16
+ api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
17
+
18
+ output = IndexMatcher.new([
19
+ %w[ID NAME],
20
+ %w[1 config-group-test]
21
+ ])
22
+ expected_result = success_result(output)
23
+
24
+ result = run_cmd(@cmd)
25
+ assert_cmd(expected_result, result)
26
+ end
27
+
28
+ it 'should run list command with defaults' do
29
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
30
+ defaults = HammerCLI::Defaults.new(
31
+ {
32
+ organization_id: {
33
+ provider: 'foreman'
34
+ },
35
+ location_id: {
36
+ provider: 'foreman'
37
+ }
38
+ }
39
+ )
40
+ defaults.stubs(:write_to_file).returns(true)
41
+ defaults.stubs(:providers).returns(providers)
42
+ api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
43
+
44
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
45
+ _(result.exit_code).must_equal HammerCLI::EX_OK
46
+ end
47
+ end
48
+ end
49
+
50
+
@@ -1,18 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.join(File.dirname(__FILE__), 'test_helper')
2
4
 
3
5
  describe 'filter' do
4
6
  def api_expects_filter_info(options)
5
7
  override = !!options[:override]
6
- api_expects(:filters, :show, 'Get filter info').with_params({
7
- :id => '1'
8
- }).returns(@filter.merge('override?' => override))
8
+ api_expects(:filters, :show, 'Get filter info').with_params(
9
+ id: '1'
10
+ ).returns(@filter.merge('override?' => override))
9
11
  end
10
12
 
11
13
  def taxonomy_usage_error(action, cmd)
12
14
  usage_error_result(
13
15
  cmd,
14
16
  'Organizations and locations can be set only for overriding filters.',
15
- "Could not #{action} the permission filter")
17
+ "Could not #{action} the permission filter"
18
+ )
16
19
  end
17
20
 
18
21
  def assert_update_success(result)
@@ -21,7 +24,7 @@ describe 'filter' do
21
24
 
22
25
  describe 'create' do
23
26
  before do
24
- @cmd = %w(filter create)
27
+ @cmd = %w[filter create]
25
28
  end
26
29
 
27
30
  it 'prints error when taxonomies are used for a not-overriding filter' do
@@ -32,41 +35,105 @@ describe 'filter' do
32
35
  result = run_cmd(@cmd + params)
33
36
  assert_cmd(taxonomy_usage_error('create', @cmd), result)
34
37
  end
38
+
39
+ it 'should create a filter' do
40
+ params = ['--role-id=1', '--permission-ids=[1]']
41
+
42
+ api_expects(:filters, :create) do |params|
43
+ (params['filter']['role_id'] == 1)
44
+ (params['filter']['permission_ids'] == [1])
45
+ end
46
+
47
+ result = run_cmd(@cmd + params)
48
+ assert_cmd(success_result("Permission filter for [%<resource_type>s] created.\n"), result)
49
+ end
50
+ end
51
+
52
+ describe 'list' do
53
+ before do
54
+ @cmd = %w[filter list]
55
+ @filters = [{
56
+ id: 1,
57
+ resource_type: 'Architecture',
58
+ search: 'none',
59
+ unlimited?: true,
60
+ override?: false,
61
+ role: { name: 'Manager', id: 2, description: 'Role granting all available permissions.', origin: 'foreman' },
62
+ permissions: 'view_architectures'
63
+ }]
64
+ end
65
+
66
+ it 'should return a list of filters' do
67
+ api_expects(:filters, :index, 'List filters').returns(@filters)
68
+
69
+ output = IndexMatcher.new([
70
+ ['ID', 'RESOURCE TYPE', 'SEARCH', 'UNLIMITED?', 'OVERRIDE?', 'ROLE', 'PERMISSIONS'],
71
+ ['1', 'Architecture', 'none', 'yes', 'no', 'Manager', 'view_architectures']
72
+ ])
73
+ expected_result = success_result(output)
74
+
75
+ result = run_cmd(@cmd)
76
+ assert_cmd(expected_result, result)
77
+ end
78
+ end
79
+
80
+ describe 'delete' do
81
+ before do
82
+ @cmd = %w(filter delete)
83
+ end
84
+
85
+ it 'should print error missing argument id' do
86
+ expected_result = "Could not delete the permission filter:\n Missing arguments for '--id'.\n"
87
+
88
+ api_expects_no_call
89
+
90
+ result = run_cmd(@cmd)
91
+ assert_match(expected_result, result.err)
92
+ end
93
+
94
+ it 'should delete a filter' do
95
+ params = ['--id=1']
96
+
97
+ api_expects(:filters, :destroy, 'Delete a filter').with_params(id: '1')
98
+
99
+ result = run_cmd(@cmd + params)
100
+ assert_cmd(success_result("Permission filter deleted.\n"), result)
101
+ end
35
102
  end
36
103
 
37
104
  describe 'update' do
38
105
  before do
39
- @cmd = %w(filter update)
106
+ @cmd = %w[filter update]
40
107
  @filter = {
41
- "search" => nil,
42
- "resource_type" => "User",
43
- "unlimited?" => false,
44
- "created_at" => "2017-07-18 14:34:09 UTC",
45
- "updated_at" => "2017-07-18 14:34:09 UTC",
46
- "override?" => true,
47
- "id" => 404,
48
- "role" => {
49
- "name" => "Some Role",
50
- "id" => 28,
51
- "description" => "Description\nof the new\nrole",
52
- "origin" => nil
108
+ 'search' => nil,
109
+ 'resource_type' => 'User',
110
+ 'unlimited?' => false,
111
+ 'created_at' => '2017-07-18 14:34:09 UTC',
112
+ 'updated_at' => '2017-07-18 14:34:09 UTC',
113
+ 'override?' => true,
114
+ 'id' => 404,
115
+ 'role' => {
116
+ 'name' => 'Some Role',
117
+ 'id' => 28,
118
+ 'description' => "Description\nof the new\nrole",
119
+ 'origin' => nil
53
120
  },
54
- "permissions" => [{
55
- "name" => "view_users",
56
- "id" => 164,
57
- "resource_type" => "User"
121
+ 'permissions' => [{
122
+ 'name' => 'view_users',
123
+ 'id' => 164,
124
+ 'resource_type' => 'User'
58
125
  }],
59
- "locations" => [{
60
- "id" => 28,
61
- "name" => "location74",
62
- "title" => "location74",
63
- "description" => nil
126
+ 'locations' => [{
127
+ 'id' => 28,
128
+ 'name' => 'location74',
129
+ 'title' => 'location74',
130
+ 'description' => nil
64
131
  }],
65
- "organizations" => [{
66
- "id" => 27,
67
- "name" => "organization74",
68
- "title" => "organization74",
69
- "description" => nil
132
+ 'organizations' => [{
133
+ 'id' => 27,
134
+ 'name' => 'organization74',
135
+ 'title' => 'organization74',
136
+ 'description' => nil
70
137
  }]
71
138
  }
72
139
  end
@@ -74,13 +141,13 @@ describe 'filter' do
74
141
  it 'resets taxonomies when a filter is not-overriding' do
75
142
  params = ['--id=1']
76
143
 
77
- api_expects_filter_info(:override => false)
78
- api_expects(:filters, :update, 'Update the filter').with_params({
144
+ api_expects_filter_info(override: false)
145
+ api_expects(:filters, :update, 'Update the filter').with_params(
79
146
  'filter' => {
80
147
  'organization_ids' => [],
81
148
  'location_ids' => []
82
149
  }
83
- }).returns(@filter)
150
+ ).returns(@filter)
84
151
 
85
152
  assert_update_success(run_cmd(@cmd + params))
86
153
  end
@@ -88,12 +155,12 @@ describe 'filter' do
88
155
  it 'resets taxonomies when switching a filter to not-overriding' do
89
156
  params = ['--id=1', '--override=false']
90
157
 
91
- api_expects(:filters, :update, 'Update the filter').with_params({
158
+ api_expects(:filters, :update, 'Update the filter').with_params(
92
159
  'filter' => {
93
160
  'organization_ids' => [],
94
161
  'location_ids' => []
95
162
  }
96
- }).returns(@filter)
163
+ ).returns(@filter)
97
164
 
98
165
  assert_update_success(run_cmd(@cmd + params))
99
166
  end
@@ -101,13 +168,13 @@ describe 'filter' do
101
168
  it 'can add taxonomies when a filter is overriding' do
102
169
  params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
103
170
 
104
- api_expects_filter_info(:override => true)
105
- api_expects(:filters, :update, 'Update the filter').with_params({
171
+ api_expects_filter_info(override: true)
172
+ api_expects(:filters, :update, 'Update the filter').with_params(
106
173
  'filter' => {
107
- 'organization_ids' => ['1', '2'],
108
- 'location_ids' => ['3', '4']
174
+ 'organization_ids' => %w[1 2],
175
+ 'location_ids' => %w[3 4]
109
176
  }
110
- }).returns(@filter)
177
+ ).returns(@filter)
111
178
 
112
179
  assert_update_success(run_cmd(@cmd + params))
113
180
  end
@@ -115,12 +182,12 @@ describe 'filter' do
115
182
  it 'can add taxonomies when switching a filter to overriding' do
116
183
  params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4', '--override=true']
117
184
 
118
- api_expects(:filters, :update, 'Update the filter').with_params({
185
+ api_expects(:filters, :update, 'Update the filter').with_params(
119
186
  'filter' => {
120
- 'organization_ids' => ['1', '2'],
121
- 'location_ids' => ['3', '4']
187
+ 'organization_ids' => %w[1 2],
188
+ 'location_ids' => %w[3 4]
122
189
  }
123
- }).returns(@filter)
190
+ ).returns(@filter)
124
191
 
125
192
  assert_update_success(run_cmd(@cmd + params))
126
193
  end
@@ -128,7 +195,7 @@ describe 'filter' do
128
195
  it 'prints error when taxonomies are used on not-overriding' do
129
196
  params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
130
197
 
131
- api_expects_filter_info(:override => false)
198
+ api_expects_filter_info(override: false)
132
199
 
133
200
  result = run_cmd(@cmd + params)
134
201
  assert_cmd(taxonomy_usage_error('update', @cmd), result)
@@ -297,6 +297,21 @@ describe "host create" do
297
297
  assert_cmd(expected_result, result)
298
298
  end
299
299
 
300
+ it 'should create a host with an owner' do
301
+ params = ['--owner-id=1']
302
+
303
+ api_expects(:hosts, :create, 'Create a host with an owner').with_params(
304
+ 'location_id' => 1, 'organization_id' => 1, 'host' => {
305
+ 'owner_id' => '1', 'name' => 'test'
306
+ }
307
+ ).returns(results: { 'owner_id' => '1', 'name' => 'test' })
308
+
309
+ expected_result = success_result("Host created.\n")
310
+
311
+ result = run_cmd(cmd + minimal_params_without_hostgroup + params)
312
+
313
+ assert_cmd(expected_result, result)
314
+ end
300
315
  end
301
316
 
302
317
  describe 'host update' do
@@ -315,6 +330,26 @@ describe 'host update' do
315
330
  }
316
331
  end
317
332
 
333
+ it 'updates with passed options only' do
334
+ params = ['--new-name=new-name']
335
+ expected_result = success_result("Host updated.\n")
336
+
337
+ api_expects(:hosts, :update, 'Update host name only').with_params(
338
+ 'id' => '1', 'organization_id' => 1, 'location_id' => 1,
339
+ 'host' => { 'name' => 'new-name' }
340
+ ).returns(
341
+ {
342
+ 'id' => '1',
343
+ 'name' => 'new-name',
344
+ 'organization_id' => '1',
345
+ 'location_id' => '1'
346
+ }
347
+ )
348
+
349
+ result = run_cmd(cmd + minimal_params + params)
350
+ assert_cmd(expected_result, result)
351
+ end
352
+
318
353
  it 'ensures helper methods are invoked' do
319
354
  params = ['--image-id=1']
320
355
  expected_result = success_result("Host updated.\n")
@@ -350,12 +385,9 @@ describe 'host update' do
350
385
  )
351
386
  api_expects(:hosts, :update, 'Update host with new org').with_params(
352
387
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
353
- 'organization_id' => '5', 'compute_attributes' => {}
354
- }
388
+ 'organization_id' => '5' }
355
389
  ) do |par|
356
- par['id'] == '1' &&
357
- par['host']['organization_id'] == '5' &&
358
- par['host']['compute_attributes'] == {}
390
+ par['id'] == '1' && par['host']['organization_id'] == '5'
359
391
  end.returns(updated_host)
360
392
 
361
393
  expected_result = success_result("Host updated.\n")
@@ -373,12 +405,9 @@ describe 'host update' do
373
405
  )
374
406
  api_expects(:hosts, :update, 'Update host with new loc').with_params(
375
407
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
376
- 'location_id' => '5', 'compute_attributes' => {}
377
- }
408
+ 'location_id' => '5' }
378
409
  ) do |par|
379
- par['id'] == '1' &&
380
- par['host']['location_id'] == '5' &&
381
- par['host']['compute_attributes'] == {}
410
+ par['id'] == '1' && par['host']['location_id'] == '5'
382
411
  end.returns(updated_host)
383
412
 
384
413
  expected_result = success_result("Host updated.\n")
@@ -396,12 +425,27 @@ describe 'host update' do
396
425
  )
397
426
  api_expects(:hosts, :update, 'Update host with new owner').with_params(
398
427
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
399
- 'owner_id' => '1', 'compute_attributes' => {}
400
- }
428
+ 'owner_id' => '1' }
429
+ ) do |par|
430
+ par['id'] == '1' && par['host']['owner_id'] == '1'
431
+ end.returns(updated_host)
432
+
433
+ expected_result = success_result("Host updated.\n")
434
+
435
+ result = run_cmd(cmd + minimal_params + params)
436
+
437
+ assert_cmd(expected_result, result)
438
+ end
439
+
440
+ it 'should update the host owner with id' do
441
+ params = ['--owner-id=1']
442
+
443
+ api_expects(:hosts, :update, 'Update host with new owner').with_params(
444
+ 'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
445
+ 'owner_id' => '1'
446
+ }
401
447
  ) do |par|
402
- par['id'] == '1' &&
403
- par['host']['owner_id'] == '1' &&
404
- par['host']['compute_attributes'] == {}
448
+ par['id'] == '1' && par['host']['owner_id'] == '1'
405
449
  end.returns(updated_host)
406
450
 
407
451
  expected_result = success_result("Host updated.\n")
@@ -415,7 +459,7 @@ end
415
459
  describe 'host config reports' do
416
460
  let(:report15) do
417
461
  {
418
- "id" => 15,
462
+ "id" => 15,
419
463
  "host_id" => 1,
420
464
  "host_name" => "host.example.com",
421
465
  "reported_at" => "2017-11-13 03:04:53 UTC",
@@ -428,7 +472,7 @@ describe 'host config reports' do
428
472
  end.returns(index_response([report15]))
429
473
 
430
474
  result = run_cmd(['host', 'config-reports', '--id=1'])
431
- result.exit_code.must_equal HammerCLI::EX_OK
475
+ _(result.exit_code).must_equal HammerCLI::EX_OK
432
476
  end
433
477
 
434
478
  it 'filters reports by --name' do
@@ -437,7 +481,7 @@ describe 'host config reports' do
437
481
  end.returns(index_response([report15]))
438
482
 
439
483
  result = run_cmd(['host', 'config-reports', '--name=host.example.com'])
440
- result.exit_code.must_equal HammerCLI::EX_OK
484
+ _(result.exit_code).must_equal HammerCLI::EX_OK
441
485
  end
442
486
 
443
487
  it 'prints error or missing --id and --name' do
@@ -462,7 +506,7 @@ describe 'host config reports' do
462
506
  end.returns(index_response([report15]))
463
507
 
464
508
  result = run_cmd(['host', 'config-reports', '--name=host.example.com', '--search=reported > "2 hour ago"'])
465
- result.exit_code.must_equal HammerCLI::EX_OK
509
+ _(result.exit_code).must_equal HammerCLI::EX_OK
466
510
  end
467
511
  end
468
512
  describe 'disassociate host from vm' do
@@ -491,3 +535,45 @@ describe 'disassociate host from vm' do
491
535
  assert_cmd(expected_result, result)
492
536
  end
493
537
  end
538
+
539
+ describe 'run puppetrun for host' do
540
+ let(:cmd) { ['host', 'puppetrun'] }
541
+ let(:params) { ['--id=1'] }
542
+
543
+ it "does nothing for puppetrun" do
544
+ expected_result = CommandExpectation.new
545
+ expected_result.expected_err = "The puppetrun feature has been removed, however you can use the Remote Execution Plugin to run Puppet commands\n"
546
+ expected_result.expected_exit_code = HammerCLI::EX_SOFTWARE
547
+
548
+ result = run_cmd(cmd)
549
+ assert_cmd(expected_result, result)
550
+ end
551
+ end
552
+
553
+ describe 'list' do
554
+ before do
555
+ @cmd = %w[host list]
556
+ end
557
+
558
+ it 'should run list command with defaults' do
559
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
560
+ defaults = HammerCLI::Defaults.new(
561
+ {
562
+ organization_id: {
563
+ provider: 'foreman'
564
+ },
565
+ location_id: {
566
+ provider: 'foreman'
567
+ }
568
+ }
569
+ )
570
+ defaults.stubs(:write_to_file).returns(true)
571
+ defaults.stubs(:providers).returns(providers)
572
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
573
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
574
+ api_expects(:hosts, :index, 'List hosts').returns(index_response([{ 'id' => '42' }]))
575
+
576
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
577
+ _(result.exit_code).must_equal HammerCLI::EX_OK
578
+ end
579
+ end