hammer_cli_katello 1.1.3 → 1.2.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.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  3. data/lib/hammer_cli_katello/host_collection.rb +6 -0
  4. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  5. data/lib/hammer_cli_katello/repository.rb +0 -27
  6. data/lib/hammer_cli_katello/version.rb +1 -1
  7. data/test/data/2.5/foreman_api.json +1 -0
  8. data/test/data/3.0/foreman_api.json +1 -0
  9. data/test/data/3.10/foreman_api.json +1 -0
  10. data/test/data/3.11/foreman_api.json +1 -0
  11. data/test/data/3.12/foreman_api.json +1 -0
  12. data/test/data/3.13/foreman_api.json +1 -0
  13. data/test/data/3.14/foreman_api.json +1 -0
  14. data/test/data/3.15/foreman_api.json +1 -0
  15. data/test/data/3.16/foreman_api.json +1 -0
  16. data/test/data/3.17/foreman_api.json +1 -0
  17. data/test/data/3.18/foreman_api.json +1 -0
  18. data/test/data/3.19/foreman_api.json +1 -0
  19. data/test/data/3.2/foreman_api.json +1 -0
  20. data/test/data/3.4/foreman_api.json +1 -0
  21. data/test/data/3.5/foreman_api.json +1 -0
  22. data/test/data/3.6/foreman_api.json +1 -0
  23. data/test/data/3.7/foreman_api.json +1 -0
  24. data/test/data/3.8/foreman_api.json +1 -0
  25. data/test/data/3.9/foreman_api.json +1 -0
  26. data/test/data/4.0/foreman_api.json +1 -0
  27. data/test/data/4.1/foreman_api.json +1 -0
  28. data/test/data/Readme.md +5 -0
  29. data/test/functional/activation_key/add_host_collection_test.rb +62 -0
  30. data/test/functional/activation_key/content_override_test.rb +92 -0
  31. data/test/functional/activation_key/create_test.rb +33 -0
  32. data/test/functional/activation_key/data/activation_key.json +17 -0
  33. data/test/functional/activation_key/info_test.rb +29 -0
  34. data/test/functional/activation_key/list_test.rb +68 -0
  35. data/test/functional/activation_key/product_content_test.rb +23 -0
  36. data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
  37. data/test/functional/activation_key/subscriptions_test.rb +74 -0
  38. data/test/functional/activation_key/update_test.rb +26 -0
  39. data/test/functional/apipie_helper_test.rb +31 -0
  40. data/test/functional/capsule/capsule_helpers.rb +13 -0
  41. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
  42. data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
  43. data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
  44. data/test/functional/capsule/content/data/library_env.json +47 -0
  45. data/test/functional/capsule/content/data/sync_status.json +6 -0
  46. data/test/functional/capsule/content/data/sync_tasks.json +62 -0
  47. data/test/functional/capsule/content/info_test.rb +61 -0
  48. data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
  49. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
  50. data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
  51. data/test/functional/capsule/info_test.rb +25 -0
  52. data/test/functional/capsule/list_test.rb +24 -0
  53. data/test/functional/content_credentials/create_test.rb +32 -0
  54. data/test/functional/content_credentials/data/test_cert.json +43 -0
  55. data/test/functional/content_credentials/info_test.rb +50 -0
  56. data/test/functional/content_credentials/list_test.rb +66 -0
  57. data/test/functional/content_export/complete/library_test.rb +155 -0
  58. data/test/functional/content_export/complete/version_test.rb +252 -0
  59. data/test/functional/content_export/content_export_helpers.rb +26 -0
  60. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  61. data/test/functional/content_export/incremental/library_test.rb +172 -0
  62. data/test/functional/content_export/incremental/version_test.rb +268 -0
  63. data/test/functional/content_export/list_test.rb +64 -0
  64. data/test/functional/content_import/library_test.rb +85 -0
  65. data/test/functional/content_import/list_test.rb +65 -0
  66. data/test/functional/content_import/metadata.json +1 -0
  67. data/test/functional/content_import/version_test.rb +85 -0
  68. data/test/functional/content_view/add_content_view_version_test.rb +88 -0
  69. data/test/functional/content_view/add_repository_test.rb +21 -0
  70. data/test/functional/content_view/component/add_test.rb +177 -0
  71. data/test/functional/content_view/component/list_test.rb +55 -0
  72. data/test/functional/content_view/component/remove_test.rb +107 -0
  73. data/test/functional/content_view/component/update_test.rb +134 -0
  74. data/test/functional/content_view/content_view_helpers.rb +20 -0
  75. data/test/functional/content_view/copy_test.rb +53 -0
  76. data/test/functional/content_view/create_test.rb +34 -0
  77. data/test/functional/content_view/delete_test.rb +62 -0
  78. data/test/functional/content_view/filter/create_test.rb +57 -0
  79. data/test/functional/content_view/filter/delete_test.rb +90 -0
  80. data/test/functional/content_view/filter/info_test.rb +89 -0
  81. data/test/functional/content_view/filter/list_test.rb +98 -0
  82. data/test/functional/content_view/filter/update_test.rb +91 -0
  83. data/test/functional/content_view/list_test.rb +68 -0
  84. data/test/functional/content_view/publish_test.rb +24 -0
  85. data/test/functional/content_view/purge_test.rb +97 -0
  86. data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
  87. data/test/functional/content_view/remove_test.rb +79 -0
  88. data/test/functional/content_view/update_test.rb +53 -0
  89. data/test/functional/content_view/version/incremental_update_test.rb +108 -0
  90. data/test/functional/content_view/version/list_test.rb +44 -0
  91. data/test/functional/content_view/version/promote_test.rb +34 -0
  92. data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
  93. data/test/functional/content_view/version/update_test.rb +48 -0
  94. data/test/functional/erratum/erratum_helpers.rb +91 -0
  95. data/test/functional/erratum/info_test.rb +29 -0
  96. data/test/functional/erratum/list_test.rb +108 -0
  97. data/test/functional/file/file_helpers.rb +13 -0
  98. data/test/functional/file/info_test.rb +162 -0
  99. data/test/functional/file/list_test.rb +112 -0
  100. data/test/functional/filter_rule/create_test.rb +99 -0
  101. data/test/functional/filter_rule/delete_test.rb +104 -0
  102. data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
  103. data/test/functional/filter_rule/info_test.rb +104 -0
  104. data/test/functional/filter_rule/list_test.rb +91 -0
  105. data/test/functional/filter_rule/update_test.rb +104 -0
  106. data/test/functional/host/errata/apply_test.rb +45 -0
  107. data/test/functional/host/errata/info_test.rb +27 -0
  108. data/test/functional/host/errata/list_test.rb +49 -0
  109. data/test/functional/host/errata/recalculate_test.rb +40 -0
  110. data/test/functional/host/extensions/create_test.rb +95 -0
  111. data/test/functional/host/extensions/data/host.json +320 -0
  112. data/test/functional/host/extensions/data/host_list.json +117 -0
  113. data/test/functional/host/extensions/info_test.rb +35 -0
  114. data/test/functional/host/extensions/list_test.rb +21 -0
  115. data/test/functional/host/extensions/update_test.rb +70 -0
  116. data/test/functional/host/host_helpers.rb +8 -0
  117. data/test/functional/host/subscription/attach_test.rb +54 -0
  118. data/test/functional/host/subscription/auto_attach_test.rb +35 -0
  119. data/test/functional/host/subscription/content_override_test.rb +96 -0
  120. data/test/functional/host/subscription/product_content_test.rb +27 -0
  121. data/test/functional/host/subscription/register_test.rb +53 -0
  122. data/test/functional/host/subscription/remove_test.rb +52 -0
  123. data/test/functional/host/subscription/unregister_test.rb +37 -0
  124. data/test/functional/host/traces/list_test.rb +37 -0
  125. data/test/functional/host/traces/resolve_test.rb +31 -0
  126. data/test/functional/host_collection/add_host_test.rb +90 -0
  127. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  128. data/test/functional/host_collection/content_install_test.rb +62 -0
  129. data/test/functional/host_collection/content_remove_test.rb +37 -0
  130. data/test/functional/host_collection/content_update_test.rb +37 -0
  131. data/test/functional/host_collection/copy_test.rb +64 -0
  132. data/test/functional/host_collection/create_test.rb +54 -0
  133. data/test/functional/host_collection/delete_test.rb +57 -0
  134. data/test/functional/host_collection/hosts_test.rb +39 -0
  135. data/test/functional/host_collection/info_test.rb +57 -0
  136. data/test/functional/host_collection/list_test.rb +63 -0
  137. data/test/functional/host_collection/remove_host_test.rb +90 -0
  138. data/test/functional/host_collection/update_test.rb +57 -0
  139. data/test/functional/hostgroup/create_test.rb +112 -0
  140. data/test/functional/hostgroup/data/hostgroup.json +50 -0
  141. data/test/functional/hostgroup/info_test.rb +33 -0
  142. data/test/functional/hostgroup/update_test.rb +120 -0
  143. data/test/functional/lifecycle_environment/create_test.rb +14 -0
  144. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
  145. data/test/functional/lifecycle_environment/list_test.rb +38 -0
  146. data/test/functional/lifecycle_environment/update_test.rb +14 -0
  147. data/test/functional/local_helper_test.rb +30 -0
  148. data/test/functional/module_stream/info_test.rb +58 -0
  149. data/test/functional/module_stream/list_test.rb +53 -0
  150. data/test/functional/organization/delete_test.rb +26 -0
  151. data/test/functional/organization/info_test.rb +22 -0
  152. data/test/functional/organization/organization_helpers.rb +10 -0
  153. data/test/functional/package/list_test.rb +158 -0
  154. data/test/functional/package_group/list_test.rb +38 -0
  155. data/test/functional/ping_test.rb +59 -0
  156. data/test/functional/product/create_test.rb +54 -0
  157. data/test/functional/product/delete_test.rb +41 -0
  158. data/test/functional/product/info_test.rb +33 -0
  159. data/test/functional/product/list_test.rb +58 -0
  160. data/test/functional/product/product_helpers.rb +24 -0
  161. data/test/functional/product/remove_sync_plan_test.rb +35 -0
  162. data/test/functional/product/set_sync_plan_test.rb +49 -0
  163. data/test/functional/product/update_proxy.rb +48 -0
  164. data/test/functional/product/update_test.rb +46 -0
  165. data/test/functional/repository/create_test.rb +21 -0
  166. data/test/functional/repository/delete_test.rb +95 -0
  167. data/test/functional/repository/info_test.rb +156 -0
  168. data/test/functional/repository/list_test.rb +68 -0
  169. data/test/functional/repository/remove_content_test.rb +108 -0
  170. data/test/functional/repository/repository_helpers.rb +18 -0
  171. data/test/functional/repository/synchronize_test.rb +57 -0
  172. data/test/functional/repository/update_test.rb +149 -0
  173. data/test/functional/repository/upload_test.rb +345 -0
  174. data/test/functional/repository_set/available_repositories_test.rb +18 -0
  175. data/test/functional/repository_set/disable_test.rb +42 -0
  176. data/test/functional/repository_set/enable_test.rb +42 -0
  177. data/test/functional/repository_set/info_test.rb +17 -0
  178. data/test/functional/repository_set/list_test.rb +18 -0
  179. data/test/functional/repository_set/repository_set_helpers.rb +20 -0
  180. data/test/functional/search_helpers.rb +17 -0
  181. data/test/functional/simple_content_access/disable_test.rb +48 -0
  182. data/test/functional/simple_content_access/enable_test.rb +46 -0
  183. data/test/functional/srpm/list_test.rb +92 -0
  184. data/test/functional/subscription/list_test.rb +86 -0
  185. data/test/functional/sync_plan/create_test.rb +60 -0
  186. data/test/functional/sync_plan/delete_test.rb +46 -0
  187. data/test/functional/sync_plan/info_test.rb +37 -0
  188. data/test/functional/sync_plan/list_test.rb +31 -0
  189. data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
  190. data/test/functional/sync_plan/update_test.rb +44 -0
  191. data/test/functional/test_helper.rb +24 -0
  192. data/test/task_helper.rb +7 -0
  193. data/test/test_helper.rb +38 -0
  194. data/test/unit/id_name_options_validator_test.rb +96 -0
  195. data/test/unit/id_resolver_test.rb +58 -0
  196. data/test/unit/messages_test.rb +7 -0
  197. data/test/unit/search_options_creators_test.rb +145 -0
  198. metadata +388 -6
@@ -0,0 +1,268 @@
1
+ require_relative '../../test_helper'
2
+ require 'hammer_cli_katello/content_export'
3
+ require_relative '../../lifecycle_environment/lifecycle_environment_helpers'
4
+ require_relative '../../content_view/content_view_helpers'
5
+ require_relative '../content_export_helpers'
6
+
7
+ describe 'content-export incremental version' do
8
+ include ForemanTaskHelpers
9
+ include ContentExportHelpers
10
+ include ContentViewHelpers
11
+ include LifecycleEnvironmentHelpers
12
+
13
+ before do
14
+ @cmd = %w(content-export incremental version)
15
+ end
16
+
17
+ let(:task_id) { '5' }
18
+ let(:response) do
19
+ {
20
+ 'id' => task_id,
21
+ 'state' => 'planned',
22
+ 'output' => {
23
+ 'export_history_id' => 2
24
+ }
25
+ }
26
+ end
27
+
28
+ let(:export_history_id) { 1000 }
29
+
30
+ let(:export_history) do
31
+ {
32
+ "id": export_history_id,
33
+ "path": "/tmp",
34
+ "metadata": {}
35
+ }
36
+ end
37
+
38
+ let(:content_view_id) { '77' }
39
+ let(:content_view_version_id) { 100 }
40
+
41
+ let(:version) { '10.0' }
42
+ let(:destination_server) { "dream.example.com" }
43
+
44
+ it "performs export with required options and async" do
45
+ params = [
46
+ "--id=#{content_view_version_id}",
47
+ '--destination-server=foo',
48
+ '--async'
49
+ ]
50
+ expects_repositories_in_version(content_view_version_id)
51
+
52
+ ex = api_expects(:content_export_incrementals, :version)
53
+ ex.returns(response)
54
+
55
+ result = run_cmd(@cmd + params)
56
+
57
+ assert_equal("Content view version is being exported in task #{task_id}.\n"\
58
+ + "Once the task completes the export metadata must be generated with the "\
59
+ + "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
60
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
61
+ end
62
+
63
+ it "performs export with required options" do
64
+ params = [
65
+ "--id=#{content_view_version_id}",
66
+ '--destination-server=foo'
67
+ ]
68
+
69
+ expects_repositories_in_version(content_view_version_id)
70
+ ex = api_expects(:content_export_incrementals, :version)
71
+ ex.returns(response)
72
+
73
+ expect_foreman_task(task_id).at_least_once
74
+
75
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
76
+ any_instance.
77
+ expects(:fetch_export_history).
78
+ returns(export_history)
79
+
80
+ result = run_cmd(@cmd + params)
81
+ assert_match(/Generated .*metadata.*json/, result.out)
82
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
83
+ end
84
+
85
+ it "performs export with history id" do
86
+ params = [
87
+ "--id=#{content_view_version_id}",
88
+ "--destination-server=#{destination_server}",
89
+ "--from-history-id=#{export_history_id}"
90
+ ]
91
+ expects_repositories_in_version(content_view_version_id)
92
+ api_expects(:content_export_incrementals, :version)
93
+ .with_params('id' => content_view_version_id,
94
+ 'destination_server' => destination_server,
95
+ 'from_history_id' => export_history_id)
96
+ .returns(response)
97
+
98
+ expect_foreman_task(task_id).at_least_once
99
+
100
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
101
+ any_instance.
102
+ expects(:fetch_export_history).
103
+ returns(export_history)
104
+
105
+ result = run_cmd(@cmd + params)
106
+ assert_match(/Generated .*metadata.*json/, result.out)
107
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
108
+ end
109
+
110
+ it 'fails on missing required params' do
111
+ params = [
112
+ '--boo-id=2'
113
+ ]
114
+
115
+ result = run_cmd(@cmd + params)
116
+ expected_error = "Could not export the content view version:\n"
117
+
118
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
119
+ assert_equal(result.err[/#{expected_error}/], expected_error)
120
+ end
121
+
122
+ it 'correctly resolves content-view-id and content view version number' do
123
+ params = ["--content-view-id=#{content_view_id}",
124
+ "--version=#{version}",
125
+ "--destination-server=#{destination_server}",
126
+ "--async"]
127
+ expects_repositories_in_version(content_view_version_id)
128
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
129
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
130
+ assert_equal p["version"], version
131
+ end
132
+
133
+ cvv_expect.at_least_once.
134
+ returns(index_response([{'id' => content_view_version_id}]))
135
+
136
+ ex = api_expects(:content_export_incrementals, :version) do |p|
137
+ assert_equal p['id'], content_view_version_id
138
+ assert_equal p["destination_server"], destination_server
139
+ end
140
+ ex.returns(response)
141
+
142
+ run_cmd(@cmd + params)
143
+ end
144
+
145
+ it 'fails on missing content-view name/id' do
146
+ params = []
147
+
148
+ result = run_cmd(@cmd + params)
149
+ expected_error = " At least one of options --id, --content-view, --content-view-id is required"
150
+
151
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
152
+ assert_match(/#{expected_error}/, result.err)
153
+ end
154
+
155
+ it 'fails on missing content-view version' do
156
+ params = ["--content-view-id=2"]
157
+ result = run_cmd(@cmd + params)
158
+
159
+ expected_error = "--version, --lifecycle-environment-id, --lifecycle-environment is required."
160
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
161
+ assert_match(/#{expected_error}/, result.err)
162
+ end
163
+
164
+ it 'fails on missing content-view missing org' do
165
+ params = ["--content-view=lol", "--version=4.0"]
166
+ result = run_cmd(@cmd + params)
167
+ expected_error = "At least one of options --organization-id, "\
168
+ "--organization, --organization-label is required."
169
+
170
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
171
+ assert_match(/#{expected_error}/, result.err)
172
+ end
173
+
174
+ it 'correctly resolves content-view-id and content view version number' do
175
+ params = ["--content-view-id=#{content_view_id}",
176
+ "--version=#{version}",
177
+ "--destination-server=#{destination_server}",
178
+ "--async"]
179
+
180
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
181
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
182
+ assert_equal p["version"], version
183
+ end
184
+
185
+ cvv_expect.at_least_once.
186
+ returns(index_response([{'id' => content_view_version_id}]))
187
+
188
+ api_expects(:content_export_incrementals, :version)
189
+ .with_params('id' => content_view_version_id)
190
+ .returns(response)
191
+
192
+ expects_repositories_in_version(content_view_version_id)
193
+ run_cmd(@cmd + params)
194
+ end
195
+
196
+ it 'warns of lazy repositories' do
197
+ params = ["--id=#{content_view_version_id}"]
198
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
199
+
200
+ api_expects(:content_export_incrementals, :version)
201
+ .with_params('id' => content_view_version_id)
202
+ .returns(response)
203
+
204
+ expect_foreman_task(task_id).at_least_once
205
+
206
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
207
+ any_instance.
208
+ expects(:fetch_export_history).
209
+ returns(export_history)
210
+
211
+ result = run_cmd(@cmd + params)
212
+ assert_match(/Unable to fully export this version because/, result.out)
213
+ assert_match(/200/, result.out)
214
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
215
+ end
216
+
217
+ it 'Errors out on lazy repositories if --fail-on-missing-content' do
218
+ params = ["--id=#{content_view_version_id}",
219
+ "--fail-on-missing-content"]
220
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
221
+
222
+ ex = api_expects(:content_export_incrementals, :version)
223
+ ex.returns(response)
224
+
225
+ expect_foreman_task(task_id).at_least_once
226
+
227
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
228
+ any_instance.
229
+ expects(:fetch_export_history).
230
+ returns(export_history)
231
+
232
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
233
+ any_instance.
234
+ expects(:exit).with(HammerCLI::EX_SOFTWARE)
235
+
236
+ result = run_cmd(@cmd + params)
237
+ assert_match(/Unable to fully export this version because/, result.out)
238
+ assert_match(/200/, result.out)
239
+ end
240
+
241
+ it 'should accept content view and lifecycle environment and get the right version' do
242
+ env = "foo"
243
+ org_id = '100'
244
+ env_id = '223'
245
+ params = ["--content-view-id=#{content_view_id}",
246
+ "--lifecycle-environment=#{env}",
247
+ "--organization-id=#{org_id}"]
248
+ expect_lifecycle_environment_search(org_id, env, env_id)
249
+ expect_content_view_version_search({'environment_id' => env_id,
250
+ 'content_view_id' => content_view_id},
251
+ 'id' => content_view_version_id).at_least_once
252
+
253
+ expects_repositories_in_version(content_view_version_id)
254
+ ex = api_expects(:content_export_incrementals, :version)
255
+ ex.returns(response)
256
+
257
+ expect_foreman_task(task_id).at_least_once
258
+
259
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
260
+ any_instance.
261
+ expects(:fetch_export_history).
262
+ returns(export_history)
263
+
264
+ result = run_cmd(@cmd + params)
265
+ assert_match(/Generated .*metadata.*json/, result.out)
266
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
267
+ end
268
+ end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_export'
3
+
4
+ describe 'content-export list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_exports, :index)
23
+
24
+ ex.returns(empty_response)
25
+ # rubocop:disable LineLength
26
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
27
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
28
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
29
+ ')
30
+ # rubocop:enable LineLength
31
+ result = run_cmd(%w(content-export list))
32
+ assert_cmd(expected_result, result)
33
+ end
34
+
35
+ it 'works with content-view-id only' do
36
+ api_expects(:content_view_versions, :index).returns(empty_response)
37
+
38
+ ex = api_expects(:content_exports, :index)
39
+
40
+ ex.returns(empty_response)
41
+ # rubocop:disable LineLength
42
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
43
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
44
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
45
+ ')
46
+ # rubocop:enable LineLength
47
+ result = run_cmd(%w(content-export list --content-view-id=1))
48
+ assert_cmd(expected_result, result)
49
+ end
50
+
51
+ it 'works with content-view-version-id only' do
52
+ ex = api_expects(:content_exports, :index)
53
+
54
+ ex.returns(empty_response)
55
+ # rubocop:disable LineLength
56
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
57
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
58
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
59
+ ')
60
+ # rubocop:enable LineLength
61
+ result = run_cmd(%w(content-export list --content-view-version-id=1))
62
+ assert_cmd(expected_result, result)
63
+ end
64
+ end
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import library' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import library)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :library)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :library)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -0,0 +1,65 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_imports, :index)
23
+
24
+ ex.returns(empty_response)
25
+
26
+ # rubocop:disable LineLength
27
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
28
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
29
+ ---|------|------|----------------------|-------------------------|------------|-----------
30
+ ')
31
+ # rubocop:enable LineLength
32
+ result = run_cmd(%w(content-import list))
33
+ assert_cmd(expected_result, result)
34
+ end
35
+
36
+ it 'works with content-view-id only' do
37
+ api_expects(:content_view_versions, :index).returns(empty_response)
38
+
39
+ ex = api_expects(:content_imports, :index)
40
+
41
+ ex.returns(empty_response)
42
+ # rubocop:disable LineLength
43
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
44
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
45
+ ---|------|------|----------------------|-------------------------|------------|-----------
46
+ ')
47
+ # rubocop:enable LineLength
48
+ result = run_cmd(%w(content-import list --content-view-id=1))
49
+ assert_cmd(expected_result, result)
50
+ end
51
+
52
+ it 'works with content-view-version-id only' do
53
+ ex = api_expects(:content_imports, :index)
54
+
55
+ ex.returns(empty_response)
56
+ # rubocop:disable LineLength
57
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
58
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
59
+ ---|------|------|----------------------|-------------------------|------------|-----------
60
+ ')
61
+ # rubocop:enable LineLength
62
+ result = run_cmd(%w(content-import list --content-view-version-id=1))
63
+ assert_cmd(expected_result, result)
64
+ end
65
+ end
@@ -0,0 +1 @@
1
+ {"organization":"export-9697","repository_mapping":{"katello-15062":{"repository":"katello","product":"prod","redhat":false},"misc-28137":{"repository":"misc","product":"prod","redhat":false},"candlepin-37918":{"repository":"candlepin","product":"prod","redhat":false}},"content_view":"view","content_view_version":{"major":1,"minor":0},"incremental":false,"toc":"export-24d91ced-3d11-4fa2-b5ea-19a41f7b97a5-20201118_1523-toc.json"}
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import version' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import version)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :version)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :version)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -0,0 +1,88 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
4
+ require 'hammer_cli_katello/content_view'
5
+
6
+ module HammerCLIKatello
7
+ describe ContentView::AddContentViewVersionCommand do
8
+ include OrganizationHelpers
9
+ include ContentViewHelpers
10
+
11
+ it 'allows minimal options' do
12
+ ex = api_expects(:content_views, :show) do |p|
13
+ p[:id] == '1'
14
+ end
15
+ ex.returns('id' => 1, 'component_ids' => [1, 3])
16
+ api_expects(:content_views, :update) do |p|
17
+ p['id'] == '1' && p['component_ids'] == %w(1 3 6)
18
+ end
19
+ run_cmd(%w(content-view add-version --id 1 --content-view-version-id 6))
20
+ end
21
+
22
+ it 'resolves content view version ID' do
23
+ ex = api_expects(:content_view_versions, :index) do |p|
24
+ p['content_view_id'] == 3 && p['version'] == '2.1'
25
+ end
26
+ ex.returns(index_response([{'id' => 6}]))
27
+ ex.returns('id' => 1, 'component_ids' => [1, 3])
28
+ ex = api_expects(:content_views, :show) do |p|
29
+ p[:id] == '1'
30
+ end
31
+ ex.returns('id' => 1, 'component_ids' => [1, 3])
32
+ api_expects(:content_views, :update) do |p|
33
+ p['id'] == '1' && p['component_ids'] == %w(1 3 6)
34
+ end
35
+ run_cmd(%w(content-view add-version --id 1 --content-view-id 3 --content-view-version 2.1))
36
+ end
37
+
38
+ describe 'OrganizationOptions' do
39
+ it 'requires organization if content view name is supplied' do
40
+ api_expects_no_call
41
+ result = run_cmd(%w(content-view add-version --name cv1))
42
+ assert(result.err[/--organization-id, --organization, --organization-label is required/],
43
+ "Organization option requirements are validated")
44
+ end
45
+
46
+ it 'allows organization id' do
47
+ expect_content_view_search('1', 'cv2', 2)
48
+ ex = api_expects(:content_views, :show) do |p|
49
+ p[:id] == 2
50
+ end
51
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
52
+ api_expects(:content_views, :update) do |p|
53
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
54
+ end
55
+ run_cmd(%w(content-view add-version --name cv2 --organization-id 1
56
+ --content-view-version-id 3))
57
+ end
58
+
59
+ it 'allows organization name' do
60
+ expect_organization_search('org1', 1)
61
+ expect_content_view_search(1, 'cv2', 2)
62
+ ex = api_expects(:content_views, :show) do |p|
63
+ p[:id] == 2
64
+ end
65
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
66
+ api_expects(:content_views, :update) do |p|
67
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
68
+ end
69
+ run_cmd(%w(content-view add-version --name cv2 --organization org1
70
+ --content-view-version-id 3))
71
+ end
72
+
73
+ it 'allows organization label' do
74
+ expect_organization_search('org1', 1, field: 'label')
75
+ expect_content_view_search(1, 'cv2', 2)
76
+ ex = api_expects(:content_views, :show) do |p|
77
+ p[:id] == 2
78
+ end
79
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
80
+ api_expects(:content_views, :update) do |p|
81
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
82
+ end
83
+ run_cmd(%w(content-view add-version --name cv2 --organization-label org1
84
+ --content-view-version-id 3))
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/content_view'
3
+
4
+ module HammerCLIKatello
5
+ describe ContentView do
6
+ describe 'AddRepositoryCommand' do
7
+ it 'allows adding a repository by ID' do
8
+ ex = api_expects(:organizations, :index) do |p|
9
+ p[:search] == "name = \"org1\""
10
+ end
11
+ ex.returns(index_response([{'id' => 1}]))
12
+
13
+ api_expects(:content_views, :index) do |p|
14
+ p['name'] == 'cv' && p['organization_id'] == 1
15
+ end
16
+
17
+ run_cmd(%w(content-view add-repository --organization org1 --name cv --repository-id 1))
18
+ end
19
+ end
20
+ end
21
+ end