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,19 @@
1
+ require 'coverage_reporter'
2
+ require "json"
3
+
4
+ module Minitest
5
+ def self.plugin_hammer_coverage_options(opts, options)
6
+ opts.on "-c", "--coverage", "Generate coverage reports for API endpoints" do
7
+ options[:coverage] = true
8
+ end
9
+ end
10
+
11
+ def self.plugin_hammer_coverage_init(options)
12
+ if options[:coverage]
13
+ Minitest.reporter.reporters.clear
14
+ Minitest.after_run do
15
+ Minitest::CoverageRunner.new("test/data/#{ FOREMAN_VERSION }/foreman_api.json").run_tests
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_helper')
4
+
5
+ describe 'architecture' do
6
+ describe 'list' do
7
+ before do
8
+ @cmd = %w[architecture list]
9
+ @architectures = [{
10
+ id: 1,
11
+ name: 'i386',
12
+ }]
13
+ end
14
+
15
+ it 'should return a list of architectures' do
16
+ api_expects(:architectures, :index, 'List architectures').returns(@architectures)
17
+
18
+ output = IndexMatcher.new([
19
+ %w[ID NAME],
20
+ %w[1 i386]
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(:architectures, :index, 'List architectures').returns(@architectures)
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
+
@@ -1,28 +1,28 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  describe 'audit' do
4
- describe 'audit-list' do
4
+ before do
5
+ @audit_changed = {
6
+ 'id' => 83,
7
+ 'created_at' => "2017-10-31 11:25:44 UTC",
8
+ 'remote_address' => '::1',
9
+ 'user_name' => "foreman_api_admin",
10
+ 'user_id' => 11,
11
+ 'action' => "update",
12
+ 'auditable_type' => "ProvisioningTemplate",
13
+ 'auditable_name' => "default_location_subscribed_hosts",
14
+ 'auditable_id' => 32,
15
+ 'audited_changes' => {
16
+ 'value' => [
17
+ nil,
18
+ "--- false\n..."
19
+ ]
20
+ }
21
+ }
22
+ end
23
+ describe 'audit-info' do
5
24
  let (:cmd) { ['audit', 'info'] }
6
25
  let(:params) { ['--id=83'] }
7
- let(:audit_changed) do
8
- {
9
- 'id' => 83,
10
- 'created_at' => "2017-10-31 11:25:44 UTC",
11
- 'remote_address' => '::1',
12
- 'user_name' => "foreman_api_admin",
13
- 'user_id' => 11,
14
- 'action' => "update",
15
- 'auditable_type' => "ProvisioningTemplate",
16
- 'auditable_name' => "default_location_subscribed_hosts",
17
- 'auditable_id' => 32,
18
- 'audited_changes' => {
19
- 'value' => [
20
- nil,
21
- "--- false\n..."
22
- ]
23
- }
24
- }
25
- end
26
26
  let(:audit_new) do
27
27
  {
28
28
  "user_id" => 1,
@@ -62,24 +62,26 @@ describe 'audit' do
62
62
  it 'shows audit information for changed records' do
63
63
  api_expects(:audits, :show, 'info')
64
64
  .with_params('id' => '83')
65
- .returns(audit_changed)
65
+ .returns(@audit_changed)
66
66
 
67
- output = OutputMatcher.new([
68
- 'Id: 83',
69
- 'At: 2017/10/31 11:25:44',
70
- 'IP: ::1',
71
- 'User: foreman_api_admin',
72
- 'Action: update',
73
- 'Audit type: ProvisioningTemplate',
74
- 'Audit record: default_location_subscribed_hosts',
75
- 'Audited changes:',
76
- ' 1) Attribute: value',
77
- ' Old:',
78
- '',
79
- ' New:',
80
- ' --- false',
81
- ' ...',
82
- ])
67
+ output = OutputMatcher.new(
68
+ [
69
+ 'Id: 83',
70
+ 'At: 2017/10/31 11:25:44',
71
+ 'IP: ::1',
72
+ 'User: foreman_api_admin',
73
+ 'Action: update',
74
+ 'Audit type: ProvisioningTemplate',
75
+ 'Audit record: default_location_subscribed_hosts',
76
+ 'Audited changes:',
77
+ ' 1) Attribute: value',
78
+ ' Old:',
79
+ '',
80
+ ' New:',
81
+ ' --- false',
82
+ ' ...',
83
+ ]
84
+ )
83
85
  expected_result = success_result(output)
84
86
 
85
87
  result = run_cmd(cmd + params)
@@ -91,36 +93,57 @@ describe 'audit' do
91
93
  .with_params('id' => '83')
92
94
  .returns(audit_new)
93
95
 
94
- output = OutputMatcher.new([
95
- 'Id: 63',
96
- 'At: 2017/10/09 23:42:44',
97
- 'IP: ::1',
98
- 'User: foreman_admin',
99
- 'Action: create',
100
- 'Audit type: User',
101
- 'Audit record: John Doe',
102
- 'Audited changes:',
103
- ' 1) Attribute: login',
104
- ' Value: john',
105
- ' 2) Attribute: firstname',
106
- ' Value: John',
107
- ' 3) Attribute: lastname',
108
- ' Value: Doe',
109
- ' 4) Attribute: mail',
110
- ' Value: john@ipa.test',
111
- ' 5) Attribute: admin',
112
- ' Value: false',
113
- ' 6) Attribute: auth_source_id',
114
- ' Value: 3',
115
- ' 7) Attribute: lower_login',
116
- ' Value: john',
117
- ' 8) Attribute: mail_enabled',
118
- ' Value: true',
119
- ])
96
+ output = OutputMatcher.new(
97
+ [
98
+ 'Id: 63',
99
+ 'At: 2017/10/09 23:42:44',
100
+ 'IP: ::1',
101
+ 'User: foreman_admin',
102
+ 'Action: create',
103
+ 'Audit type: User',
104
+ 'Audit record: John Doe',
105
+ 'Audited changes:',
106
+ ' 1) Attribute: login',
107
+ ' Value: john',
108
+ ' 2) Attribute: firstname',
109
+ ' Value: John',
110
+ ' 3) Attribute: lastname',
111
+ ' Value: Doe',
112
+ ' 4) Attribute: mail',
113
+ ' Value: john@ipa.test',
114
+ ' 5) Attribute: admin',
115
+ ' Value: false',
116
+ ' 6) Attribute: auth_source_id',
117
+ ' Value: 3',
118
+ ' 7) Attribute: lower_login',
119
+ ' Value: john',
120
+ ' 8) Attribute: mail_enabled',
121
+ ' Value: true',
122
+ ]
123
+ )
120
124
  expected_result = success_result(output)
121
125
 
122
126
  result = run_cmd(cmd + params)
123
127
  assert_cmd(expected_result, result)
124
128
  end
125
129
  end
130
+
131
+ describe 'audit-list' do
132
+ let(:cmd) { ['audit', 'list'] }
133
+ let(:audits) do
134
+ [@audit_changed]
135
+ end
136
+
137
+ it "should show index list" do
138
+ api_expects(:audits, :index).returns(audits)
139
+
140
+ output = IndexMatcher.new([
141
+ ['ID', 'AT', 'IP', 'USER', 'ACTION', 'AUDIT TYPE', 'AUDIT RECORD'],
142
+ ['83', '2017/10/31 11:25:44', '::1', 'foreman_api_admin', 'update', 'ProvisioningTemplate', 'default_location_subscribed_hosts']
143
+ ])
144
+
145
+ result = run_cmd(cmd)
146
+ assert_cmd(success_result(output), result)
147
+ end
148
+ end
126
149
  end
@@ -27,6 +27,26 @@ describe 'bookmark' do
27
27
  result = run_cmd(@cmd)
28
28
  assert_cmd(expected_result, result)
29
29
  end
30
+
31
+ it 'should run list command with defaults' do
32
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
33
+ defaults = HammerCLI::Defaults.new(
34
+ {
35
+ organization_id: {
36
+ provider: 'foreman'
37
+ },
38
+ location_id: {
39
+ provider: 'foreman'
40
+ }
41
+ }
42
+ )
43
+ defaults.stubs(:write_to_file).returns(true)
44
+ defaults.stubs(:providers).returns(providers)
45
+ api_expects(:bookmarks, :index, 'List bookmarks').returns(@bookmarks)
46
+
47
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
48
+ _(result.exit_code).must_equal HammerCLI::EX_OK
49
+ end
30
50
  end
31
51
 
32
52
  describe 'info' do
@@ -39,12 +39,12 @@ describe HammerCLIForeman::ListCommand do
39
39
 
40
40
  it 'shows search fields in help' do
41
41
  result = run_cmd(cmd + params)
42
- result.out.must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+name\s+string/)
42
+ _(result.out).must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+name\s+string/)
43
43
  end
44
44
 
45
45
  it 'formats enum values' do
46
46
  result = run_cmd(cmd + params)
47
- result.out.must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+managed\s+Values: true, false/)
47
+ _(result.out).must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+managed\s+Values: true, false/)
48
48
  end
49
49
  end
50
50
 
@@ -53,7 +53,7 @@ describe HammerCLIForeman::ListCommand do
53
53
  it "fetches only first page when there's not enough records" do
54
54
  expect_paged_call(1, 1000, 10)
55
55
  result = run_cmd([], {}, TestList)
56
- result.exit_code.must_equal HammerCLI::EX_OK
56
+ _(result.exit_code).must_equal HammerCLI::EX_OK
57
57
  end
58
58
 
59
59
  it "fetches all records" do
@@ -62,27 +62,27 @@ describe HammerCLIForeman::ListCommand do
62
62
  expect_paged_call(3, per_page_all, 10)
63
63
 
64
64
  result = run_cmd([], {}, TestList)
65
- result.exit_code.must_equal HammerCLI::EX_OK
65
+ _(result.exit_code).must_equal HammerCLI::EX_OK
66
66
  end
67
67
 
68
68
  it "uses --per-page value" do
69
69
  per_page = 10
70
70
  expect_paged_call(1, per_page, 10)
71
71
  result = run_cmd(["--per-page=#{per_page}"], {}, TestList)
72
- result.exit_code.must_equal HammerCLI::EX_OK
72
+ _(result.exit_code).must_equal HammerCLI::EX_OK
73
73
  end
74
74
 
75
75
  it "uses both --per-page and --page value" do
76
76
  per_page = 10
77
77
  expect_paged_call(2, per_page, 10)
78
78
  result = run_cmd(["--per-page=#{per_page}", '--page=2'], {}, TestList)
79
- result.exit_code.must_equal HammerCLI::EX_OK
79
+ _(result.exit_code).must_equal HammerCLI::EX_OK
80
80
  end
81
81
 
82
82
  it "sets per_page to 20 when only --page is used" do
83
83
  expect_paged_call(2, 20, 10)
84
84
  result = run_cmd(['--page=2'], {}, TestList)
85
- result.exit_code.must_equal HammerCLI::EX_OK
85
+ _(result.exit_code).must_equal HammerCLI::EX_OK
86
86
  end
87
87
  end
88
88
 
@@ -96,20 +96,20 @@ describe HammerCLIForeman::ListCommand do
96
96
  per_page = 10
97
97
  expect_paged_call(1, per_page, 10)
98
98
  result = run_cmd(["--per-page=#{per_page}"], {}, TestList)
99
- result.exit_code.must_equal HammerCLI::EX_OK
99
+ _(result.exit_code).must_equal HammerCLI::EX_OK
100
100
  end
101
101
 
102
102
  it "respects per_page setting when the adapter allows pagination by default" do
103
103
  expect_paged_call(1, per_page_in_settings, 30)
104
104
  result = run_cmd([], { :adapter => :base, :interactive => false }, TestList)
105
- result.exit_code.must_equal HammerCLI::EX_OK
105
+ _(result.exit_code).must_equal HammerCLI::EX_OK
106
106
  end
107
107
 
108
108
  it "fetches all records when the adapter doesn't allow pagination by default" do
109
109
  expect_paged_call(1, per_page_all, 1000)
110
110
  expect_paged_call(2, per_page_all, 10)
111
111
  result = run_cmd([], { :adapter => :csv, :interactive => false }, TestList)
112
- result.exit_code.must_equal HammerCLI::EX_OK
112
+ _(result.exit_code).must_equal HammerCLI::EX_OK
113
113
  end
114
114
  end
115
115
  end
@@ -128,7 +128,7 @@ describe HammerCLIForeman::ListCommand do
128
128
 
129
129
  result = run_cmd([], {}, TestListWithOutput)
130
130
  assert_cmd(expected_result, result)
131
- result.out.wont_match pagination_line_re
131
+ _(result.out).wont_match pagination_line_re
132
132
  end
133
133
 
134
134
  it 'prints one page when --per-page is used' do
@@ -33,8 +33,10 @@ describe "parameters" do
33
33
  }
34
34
  end
35
35
  it 'update compute profile name' do
36
- params = ['--id=1' ,'--new-name=profile2']
37
- api_expects(:compute_profiles, :update, 'Update the compute profile').with_params({"name" =>"profile2"}).returns(@compute_profile)
36
+ params = ['--id=1', '--new-name=profile2']
37
+ api_expects(:compute_profiles, :update, 'Update the compute profile').with_params(
38
+ { 'compute_profile' => { 'name' => 'profile2' } }
39
+ ).returns(@compute_profile)
38
40
  result = run_cmd(@cmd + params)
39
41
  assert_cmd(success_result("Compute profile updated.\n"), result)
40
42
  end
@@ -96,4 +98,47 @@ describe "parameters" do
96
98
  end
97
99
  end
98
100
 
101
+ describe 'list' do
102
+ before do
103
+ @cmd = %w[compute-profile list]
104
+ @compute_profiles = [{
105
+ id: 1,
106
+ name: '1-Small',
107
+ }]
108
+ end
109
+
110
+ it 'should return a list of compute profiles' do
111
+ api_expects(:compute_profiles, :index, 'List compute profiles').returns(@compute_profiles)
112
+
113
+ output = IndexMatcher.new([
114
+ %w[ID NAME],
115
+ %w[1 1-Small]
116
+ ])
117
+ expected_result = success_result(output)
118
+
119
+ result = run_cmd(@cmd)
120
+ assert_cmd(expected_result, result)
121
+ end
122
+
123
+ it 'should run list command with defaults' do
124
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
125
+ defaults = HammerCLI::Defaults.new(
126
+ {
127
+ organization_id: {
128
+ provider: 'foreman'
129
+ },
130
+ location_id: {
131
+ provider: 'foreman'
132
+ }
133
+ }
134
+ )
135
+ defaults.stubs(:write_to_file).returns(true)
136
+ defaults.stubs(:providers).returns(providers)
137
+ api_expects(:compute_profiles, :index, 'List compute profiles').returns(@compute_profiles)
138
+
139
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
140
+ _(result.exit_code).must_equal HammerCLI::EX_OK
141
+ end
142
+ end
143
+
99
144
  end