hammer_cli_katello 0.0.26 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/activation_key.rb +23 -43
  3. data/lib/hammer_cli_katello/associating_commands.rb +3 -5
  4. data/lib/hammer_cli_katello/capsule.rb +1 -3
  5. data/lib/hammer_cli_katello/commands.rb +1 -7
  6. data/lib/hammer_cli_katello/content_view.rb +6 -3
  7. data/lib/hammer_cli_katello/content_view_name_resolvable.rb +21 -0
  8. data/lib/hammer_cli_katello/content_view_puppet_module.rb +11 -7
  9. data/lib/hammer_cli_katello/content_view_version.rb +30 -29
  10. data/lib/hammer_cli_katello/erratum.rb +0 -1
  11. data/lib/hammer_cli_katello/exception_handler.rb +0 -2
  12. data/lib/hammer_cli_katello/filter.rb +11 -3
  13. data/lib/hammer_cli_katello/filter_rule.rb +8 -2
  14. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +71 -0
  15. data/lib/hammer_cli_katello/gpg_key.rb +0 -5
  16. data/lib/hammer_cli_katello/host.rb +1 -0
  17. data/lib/hammer_cli_katello/host_collection.rb +48 -16
  18. data/lib/hammer_cli_katello/host_errata.rb +0 -1
  19. data/lib/hammer_cli_katello/host_extensions.rb +56 -0
  20. data/lib/hammer_cli_katello/host_package.rb +0 -3
  21. data/lib/hammer_cli_katello/host_package_group.rb +0 -3
  22. data/lib/hammer_cli_katello/host_subscription.rb +67 -1
  23. data/lib/hammer_cli_katello/hostgroup.rb +2 -0
  24. data/lib/hammer_cli_katello/hostgroup_extensions.rb +48 -0
  25. data/lib/hammer_cli_katello/i18n.rb +0 -3
  26. data/lib/hammer_cli_katello/id_resolver.rb +25 -16
  27. data/lib/hammer_cli_katello/katello_environment_name_resolvable.rb +4 -3
  28. data/lib/hammer_cli_katello/lifecycle_environment.rb +0 -3
  29. data/lib/hammer_cli_katello/lifecycle_environment_name_resolvable.rb +4 -3
  30. data/lib/hammer_cli_katello/organization.rb +0 -3
  31. data/lib/hammer_cli_katello/organization_options.rb +12 -0
  32. data/lib/hammer_cli_katello/ostree_branch.rb +0 -1
  33. data/lib/hammer_cli_katello/output/fields.rb +0 -2
  34. data/lib/hammer_cli_katello/output/formatters.rb +0 -4
  35. data/lib/hammer_cli_katello/package.rb +0 -1
  36. data/lib/hammer_cli_katello/package_group.rb +0 -1
  37. data/lib/hammer_cli_katello/ping.rb +0 -6
  38. data/lib/hammer_cli_katello/product.rb +1 -7
  39. data/lib/hammer_cli_katello/puppet_module.rb +0 -1
  40. data/lib/hammer_cli_katello/repository.rb +36 -35
  41. data/lib/hammer_cli_katello/repository_scoped_to_product.rb +0 -4
  42. data/lib/hammer_cli_katello/repository_set.rb +0 -3
  43. data/lib/hammer_cli_katello/search_options_creators.rb +40 -18
  44. data/lib/hammer_cli_katello/subscription.rb +20 -13
  45. data/lib/hammer_cli_katello/sync_plan.rb +4 -8
  46. data/lib/hammer_cli_katello/version.rb +1 -1
  47. data/lib/hammer_cli_katello.rb +21 -26
  48. data/test/data/3.0/foreman_api.json +1 -1
  49. data/test/data/3.2/foreman_api.json +1 -0
  50. data/test/data/Readme.md +5 -0
  51. data/test/functional/activaton_key/add_host_collection_test.rb +62 -0
  52. data/test/functional/activaton_key/create_test.rb +33 -0
  53. data/test/functional/activaton_key/list_test.rb +15 -16
  54. data/test/functional/activaton_key/product_content_test.rb +23 -0
  55. data/test/functional/activaton_key/remove_host_collection_test.rb +62 -0
  56. data/test/functional/activaton_key/subscriptions_test.rb +57 -0
  57. data/test/functional/activaton_key/update_test.rb +26 -0
  58. data/test/functional/capsule/content/cancel_synchronization_test.rb +1 -1
  59. data/test/functional/capsule/content/capsule_content_helpers.rb +0 -2
  60. data/test/functional/content_view/add_content_view_version_test.rb +34 -0
  61. data/test/functional/content_view/add_repository_test.rb +20 -0
  62. data/test/functional/content_view/content_view_helpers.rb +0 -2
  63. data/test/functional/content_view/create_test.rb +3 -3
  64. data/test/functional/content_view/filter/create_test.rb +63 -0
  65. data/test/functional/content_view/list_test.rb +23 -20
  66. data/test/functional/content_view/publish_test.rb +23 -0
  67. data/test/functional/content_view/puppet_module/add_test.rb +23 -0
  68. data/test/functional/content_view/remove_content_view_version_test.rb +34 -0
  69. data/test/functional/content_view/version/incremental_update_test.rb +4 -4
  70. data/test/functional/content_view/version/list_test.rb +44 -0
  71. data/test/functional/content_view/version/promote_test.rb +35 -0
  72. data/test/functional/filter_rule/create_test.rb +20 -0
  73. data/test/functional/host/errata/apply_test.rb +5 -4
  74. data/test/functional/host/extensions/data/host.json +310 -0
  75. data/test/functional/host/extensions/data/host_list.json +115 -0
  76. data/test/functional/host/extensions/info_test.rb +27 -0
  77. data/test/functional/host/extensions/list_test.rb +21 -0
  78. data/test/functional/host/host_helpers.rb +0 -2
  79. data/test/functional/host/subscription/attach_test.rb +54 -0
  80. data/test/functional/host/subscription/auto_attach_test.rb +35 -0
  81. data/test/functional/host/subscription/register_test.rb +2 -2
  82. data/test/functional/host/subscription/remove_test.rb +52 -0
  83. data/test/functional/host_collection/add_host_test.rb +57 -0
  84. data/test/functional/host_collection/copy_test.rb +64 -0
  85. data/test/functional/host_collection/create_test.rb +43 -0
  86. data/test/functional/host_collection/delete_test.rb +57 -0
  87. data/test/functional/host_collection/hosts_test.rb +40 -0
  88. data/test/functional/host_collection/info_test.rb +57 -0
  89. data/test/functional/host_collection/list_test.rb +42 -0
  90. data/test/functional/host_collection/remove_host_test.rb +57 -0
  91. data/test/functional/host_collection/update_test.rb +57 -0
  92. data/test/functional/hostgroup/create_test.rb +55 -0
  93. data/test/functional/hostgroup/data/hostgroup.json +48 -0
  94. data/test/functional/hostgroup/info_test.rb +30 -0
  95. data/test/functional/hostgroup/update_test.rb +55 -0
  96. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +0 -2
  97. data/test/functional/organization/organization_helpers.rb +0 -2
  98. data/test/functional/product/create_test.rb +54 -0
  99. data/test/functional/product/delete_test.rb +41 -0
  100. data/test/functional/product/info_test.rb +33 -0
  101. data/test/functional/product/list_test.rb +58 -0
  102. data/test/functional/product/product_helpers.rb +14 -0
  103. data/test/functional/product/remove_sync_plan_test.rb +35 -0
  104. data/test/functional/product/set_sync_plan_test.rb +49 -0
  105. data/test/functional/product/update_test.rb +46 -0
  106. data/test/functional/repository/info_test.rb +3 -3
  107. data/test/functional/repository/list_test.rb +14 -13
  108. data/test/functional/repository/remove_content_test.rb +18 -0
  109. data/test/functional/repository/repository_helpers.rb +9 -3
  110. data/test/functional/repository/synchronize_test.rb +3 -3
  111. data/test/functional/repository/upload_test.rb +17 -5
  112. data/test/functional/subscription/list_test.rb +92 -0
  113. data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
  114. data/test/test_helper.rb +3 -3
  115. data/test/unit/id_resolver_test.rb +17 -2
  116. data/test/unit/search_options_creators_test.rb +49 -12
  117. metadata +105 -7
  118. data/lib/hammer_cli_katello/content_host.rb +0 -111
@@ -0,0 +1,55 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/hostgroup'
3
+
4
+ module HammerCLIForeman
5
+ describe Hostgroup do
6
+ # These tests are only for the extensions Katello adds to the hostgroup command
7
+ # See hammer-cli-foreman for the core hostgroup tests
8
+ describe CreateCommand do
9
+ it 'allows content source id' do
10
+ api_expects(:hostgroups, :create) do |p|
11
+ p['hostgroup']['name'] == 'hg1' && p['hostgroup']['content_source_id'] == 1
12
+ end
13
+ run_cmd(%w(hostgroup create --name hg1 --content-source-id 1))
14
+ end
15
+
16
+ it 'allows content view id' do
17
+ api_expects(:hostgroups, :create) do |p|
18
+ p['hostgroup']['name'] == 'hg1' && p['hostgroup']['content_view_id'] == 1
19
+ end
20
+ run_cmd(%w(hostgroup create --name hg1 --content-view-id 1))
21
+ end
22
+
23
+ it 'allows content view name' do
24
+ ex = api_expects(:content_views, :index) do |p|
25
+ p[:search] = "name = \"cv1\"" && p['organization_id'] == '1'
26
+ end
27
+ ex.returns(index_response([{'id' => 1}]))
28
+ api_expects(:hostgroups, :create) do |p|
29
+ p['hostgroup']['content_view_id'] == 1 && p['hostgroup']['name'] == 'hg1'
30
+ end
31
+ run_cmd(%w(hostgroup create --name hg1 --content-view cv1 --query-organization-id 1))
32
+ end
33
+
34
+ it 'allows lifecycle environment id' do
35
+ api_expects(:hostgroups, :create) do |p|
36
+ p['hostgroup']['name'] == 'hg1' && p['hostgroup']['lifecycle_environment_id'] == 1 &&
37
+ p['hostgroup']['organization_ids'] == %w(1 2)
38
+ end
39
+ run_cmd(%w(hostgroup create --name hg1 --lifecycle-environment-id 1 --organization-ids 1,2))
40
+ end
41
+
42
+ it 'allows lifecycle environment name' do
43
+ ex = api_expects(:lifecycle_environments, :index) do |p|
44
+ p[:name] = 'le1' && p['organization_id'] == '1'
45
+ end
46
+ ex.returns(index_response([{'id' => 1}]))
47
+ api_expects(:hostgroups, :create) do |p|
48
+ p['hostgroup']['name'] == 'hg1' && p['hostgroup']['lifecycle_environment_id'] == 1
49
+ end
50
+ run_cmd(%w(hostgroup create --name hg1 --lifecycle-environment le1
51
+ --query-organization-id 1 --organization-ids 1,2))
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,48 @@
1
+ {
2
+ "content_source_id":null,
3
+ "content_source_name":null,
4
+ "content_view_id":1,
5
+ "content_view_name":"Default Organization View",
6
+ "lifecycle_environment_id":1,
7
+ "lifecycle_environment_name":"Library",
8
+ "subnet_id":null,
9
+ "subnet_name":null,
10
+ "operatingsystem_id":null,
11
+ "operatingsystem_name":null,
12
+ "domain_id":null,
13
+ "domain_name":null,
14
+ "environment_id":1,
15
+ "environment_name":"Production Env",
16
+ "compute_profile_id":null,
17
+ "compute_profile_name":null,
18
+ "ancestry":null,
19
+ "parent_id":null,
20
+ "parent_name":null,
21
+ "puppet_proxy_id":null,
22
+ "puppet_ca_proxy_id":null,
23
+ "ptable_id":null,
24
+ "ptable_name":null,
25
+ "medium_id":null,
26
+ "medium_name":null,
27
+ "architecture_id":null,
28
+ "architecture_name":null,
29
+ "realm_id":null,
30
+ "realm_name":null,
31
+ "created_at":"2016-08-09 04:18:32 UTC",
32
+ "updated_at":"2016-08-09 04:18:32 UTC",
33
+ "id":1,
34
+ "parameters":[],
35
+ "template_combinations":[],
36
+ "puppetclasses":[],
37
+ "config_groups":[],
38
+ "all_puppetclasses":[],
39
+ "locations":[],
40
+ "organizations":[
41
+ {
42
+ "id":1,
43
+ "name":"Redhat",
44
+ "title":"Redhat",
45
+ "description":null
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,30 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/hostgroup'
3
+
4
+ module HammerCLIForeman
5
+ describe Hostgroup do
6
+ describe InfoCommand do
7
+ before do
8
+ @cmd = %w(hostgroup info)
9
+ end
10
+
11
+ let(:hostgroup_id) { 1 }
12
+
13
+ it "Shows information about a hostgroup" do
14
+ params = ["--id=#{hostgroup_id}"]
15
+
16
+ ex = api_expects(:hostgroups, :show, "Get info") do |par|
17
+ par["id"] == hostgroup_id.to_s
18
+ end
19
+ json_file = File.join(File.dirname(__FILE__), 'data', 'hostgroup.json')
20
+ ex.returns(JSON.parse(File.read(json_file)))
21
+
22
+ result = run_cmd(@cmd + params)
23
+ expected_fields = [['Lifecycle Environment', 'Library'],
24
+ ['Content View', 'Default Organization View']]
25
+ expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) }
26
+ expected_results.each { |expected| assert_cmd(expected, result) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/hostgroup'
3
+
4
+ module HammerCLIForeman
5
+ describe Hostgroup do
6
+ # These tests are only for the extensions Katello adds to the hostgroup command
7
+ # See hammer-cli-foreman for the core hostgroup tests
8
+ describe UpdateCommand do
9
+ it 'allows content source id' do
10
+ api_expects(:hostgroups, :update) do |p|
11
+ p['id'] == '1' && p['hostgroup']['content_source_id'] == 1
12
+ end
13
+ run_cmd(%w(hostgroup update --id 1 --content-source-id 1))
14
+ end
15
+
16
+ it 'allows content view id' do
17
+ api_expects(:hostgroups, :update) do |p|
18
+ p['id'] == '1' && p['hostgroup']['content_view_id'] == 1
19
+ end
20
+ run_cmd(%w(hostgroup update --id 1 --content-view-id 1))
21
+ end
22
+
23
+ it 'allows content view name' do
24
+ ex = api_expects(:content_views, :index) do |p|
25
+ p[:search] = "name = \"cv1\"" && p['organization_id'] == '1'
26
+ end
27
+ ex.returns(index_response([{'id' => 1}]))
28
+ api_expects(:hostgroups, :update) do |p|
29
+ p['id'] == '1' && p['hostgroup']['content_view_id'] == 1
30
+ end
31
+ run_cmd(%w(hostgroup update --id 1 --content-view cv1 --query-organization-id 1))
32
+ end
33
+
34
+ it 'allows lifecycle environment id' do
35
+ api_expects(:hostgroups, :update) do |p|
36
+ p['id'] == '1' && p['hostgroup']['lifecycle_environment_id'] == 1 &&
37
+ p['hostgroup']['organization_ids'] == %w(1 2)
38
+ end
39
+ run_cmd(%w(hostgroup update --id 1 --lifecycle-environment-id 1 --organization-ids 1,2))
40
+ end
41
+
42
+ it 'allows lifecycle environment name' do
43
+ ex = api_expects(:lifecycle_environments, :index) do |p|
44
+ p[:name] = 'le1' && p['organization_id'] == '1'
45
+ end
46
+ ex.returns(index_response([{'id' => 1}]))
47
+ api_expects(:hostgroups, :update) do |p|
48
+ p['id'] == '1' && p['hostgroup']['lifecycle_environment_id'] == 1
49
+ end
50
+ run_cmd(%w(hostgroup update --id 1 --lifecycle-environment le1
51
+ --query-organization-id 1 --organization-ids 1,2))
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,4 @@
1
1
  module LifecycleEnvironmentHelpers
2
-
3
2
  def expect_lifecycle_environment_search(org_id, name, id)
4
3
  ex = api_expects(:lifecycle_environments, :index, 'Find the lifecycle environment') do |par|
5
4
  par['name'] == name && par['organization_id'] == org_id
@@ -13,5 +12,4 @@ module LifecycleEnvironmentHelpers
13
12
  end
14
13
  ex.returns(index_response(results))
15
14
  end
16
-
17
15
  end
@@ -1,10 +1,8 @@
1
1
  module OrganizationHelpers
2
-
3
2
  def expect_organization_search(name, id)
4
3
  ex = api_expects(:organizations, :index, 'Find the organization') do |par|
5
4
  par[:search] == "name = \"#{name}\""
6
5
  end
7
6
  ex.at_least_once.returns(index_response([{'id' => id}]))
8
7
  end
9
-
10
8
  end
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../sync_plan/sync_plan_helpers')
4
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
5
+
6
+ describe "create a product" do
7
+ include OrganizationHelpers
8
+ include SyncPlanHelpers
9
+ include ProductHelpers
10
+
11
+ it 'by organization ID and product name' do
12
+ api_expects(:products, :create, 'create a product') do |par|
13
+ par['organization_id'] == 1 && par['name'] = 'product1'
14
+ end
15
+
16
+ assert_equal(
17
+ 0,
18
+ run_cmd(%w(product create --organization-id 1 --name product1)).exit_code
19
+ )
20
+ end
21
+
22
+ it 'by organization name and product name' do
23
+ expect_organization_search('org1', 1)
24
+ api_expects(:products, :create, 'create a product') do |par|
25
+ par['organization_id'] == 1 && par['name'] = 'product1'
26
+ end
27
+ assert_equal(
28
+ 0,
29
+ run_cmd(%w(product create --organization org1 --name product1)).exit_code
30
+ )
31
+ end
32
+
33
+ it 'by organization name, product name, and sync plan' do
34
+ expect_organization_search('org1', 1)
35
+ expect_sync_plan_search(1, 'sync_plan1', 1)
36
+ api_expects(:products, :create, 'create a product with a sync plan') do |par|
37
+ par['organization_id'] == 1 &&
38
+ par['name'] == 'product1' &&
39
+ par['sync_plan_id'] == 1
40
+ end
41
+ command = %w(product create --organization org1 --name product1 --sync-plan sync_plan1)
42
+ assert_equal(
43
+ 0,
44
+ run_cmd(command).exit_code
45
+ )
46
+ end
47
+
48
+ it 'fails if no organization is given' do
49
+ refute_equal(
50
+ 0,
51
+ run_cmd(%w(product create --name product1)).exit_code
52
+ )
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
4
+
5
+ describe 'delete a product' do
6
+ include OrganizationHelpers
7
+ include ProductHelpers
8
+
9
+ it 'by ID' do
10
+ api_expects(:products, :destroy, 'delete a product') do |par|
11
+ par['id'] == 1
12
+ end
13
+ assert_equal(
14
+ 0,
15
+ run_cmd(%w(product delete --id 1)).exit_code
16
+ )
17
+ end
18
+
19
+ it 'by organization ID and product name' do
20
+ expect_product_search(1, 'product1', 1)
21
+ api_expects(:products, :destroy, 'delete a product') do |par|
22
+ par['id'] == 1
23
+ end
24
+ assert_equal(
25
+ 0,
26
+ run_cmd(%w(product delete --organization-id 1 --name product1)).exit_code
27
+ )
28
+ end
29
+
30
+ it 'by organization name and product name' do
31
+ expect_organization_search('org1', 1)
32
+ expect_product_search(1, 'product1', 1)
33
+ api_expects(:products, :destroy, 'delete a product') do |par|
34
+ par['id'] == 1
35
+ end
36
+ assert_equal(
37
+ 0,
38
+ run_cmd(%w(product delete --organization org1 --name product1)).exit_code
39
+ )
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
4
+
5
+ describe "get product info" do
6
+ include OrganizationHelpers
7
+ include ProductHelpers
8
+
9
+ it 'by ID' do
10
+ expect_product_show(:id => 1)
11
+ assert_equal(
12
+ 0,
13
+ run_cmd(%w(product info --id 1)).exit_code
14
+ )
15
+ end
16
+
17
+ it 'by organization id and product name' do
18
+ expect_product_show(:name => 'product1', :org_id => 1, :id => 1)
19
+ assert_equal(
20
+ 0,
21
+ run_cmd(%w(product info --organization-id 1 --name product1)).exit_code
22
+ )
23
+ end
24
+
25
+ it 'by organization name and product name' do
26
+ expect_organization_search('org1', 1)
27
+ expect_product_show(:name => 'product1', :org_id => 1, :id => 1)
28
+ assert_equal(
29
+ 0,
30
+ run_cmd(%w(product info --organization org1 --name product1)).exit_code
31
+ )
32
+ end
33
+ end
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), 'product_helpers')
3
+
4
+ describe "listing products" do
5
+ include ProductHelpers
6
+
7
+ let(:empty_response_table) do
8
+ <<eostring
9
+ ---|------|-------------|--------------|--------------|-----------
10
+ ID | NAME | DESCRIPTION | ORGANIZATION | REPOSITORIES | SYNC STATE
11
+ ---|------|-------------|--------------|--------------|-----------
12
+ eostring
13
+ end
14
+
15
+ it 'displays the table properly' do
16
+ api_expects(:products, :index, 'index products').returns(index_response([]))
17
+ assert_cmd(
18
+ success_result(empty_response_table),
19
+ run_cmd(%w(product list --organization-id 1))
20
+ )
21
+ end
22
+
23
+ it 'by organization ID' do
24
+ ex = api_expects(:products, :index, 'index products') do |par|
25
+ par['organization_id'] == 1
26
+ end
27
+ ex.returns(index_response([]))
28
+
29
+ assert_equal(
30
+ 0,
31
+ run_cmd(%w(product list --organization-id 1)).exit_code
32
+ )
33
+ end
34
+
35
+ it 'by organization ID and subscription ID' do
36
+ ex = api_expects(:products, :index, 'organization product list') do |par|
37
+ par['organization_id'] == 1 && par['subscription_id'] == 1
38
+ end
39
+ ex.returns(index_response([]))
40
+
41
+ assert_equal(
42
+ 0,
43
+ run_cmd(%w(product list --organization-id 1 --subscription-id 1)).exit_code
44
+ )
45
+ end
46
+
47
+ it 'by organization ID and sync plan ID' do
48
+ ex = api_expects(:products, :index, 'organization product list') do |par|
49
+ par['organization_id'] == 1 && par['sync_plan_id'] == 1
50
+ end
51
+ ex.returns(index_response([]))
52
+
53
+ assert_equal(
54
+ 0,
55
+ run_cmd(%w(product list --organization-id 1 --sync-plan-id 1)).exit_code
56
+ )
57
+ end
58
+ end
@@ -5,4 +5,18 @@ module ProductHelpers
5
5
  end
6
6
  ex.returns(index_response([{'id' => id}]))
7
7
  end
8
+
9
+ def expect_product_show(options = {})
10
+ raise "#{__method__} must be called with :id" unless (options.keys & [:id]).size == 1
11
+
12
+ if options[:name]
13
+ raise "#{__method__} used with :name also requires :org_id" unless options[:org_id]
14
+ expect_product_search(options[:org_id], options[:name], options[:id])
15
+ end
16
+
17
+ ex = api_expects(:products, :show, 'Show a Product') do |par|
18
+ par['id'] == options[:id]
19
+ end
20
+ ex.returns(index_response([{'id' => options[:id]}]))
21
+ end
8
22
  end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../sync_plan/sync_plan_helpers')
4
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
5
+
6
+ describe "remove a product's sync plan" do
7
+ include OrganizationHelpers
8
+ include SyncPlanHelpers
9
+ include ProductHelpers
10
+
11
+ it "by product ID" do
12
+ api_expects(:products, :update, "set sync plan") do |params|
13
+ params['id'] == 1 && params['sync_plan_id'].nil?
14
+ end
15
+
16
+ assert_equal(
17
+ 0,
18
+ run_cmd(%w(product remove-sync-plan --id 1)).exit_code
19
+ )
20
+ end
21
+
22
+ it "by product name" do
23
+ expect_product_search(1, 'product1', 1)
24
+ api_expects(:products, :update, "set sync plan") do |params|
25
+ params['id'] == 1 && params['sync_plan_id'].nil?
26
+ end
27
+
28
+ assert_equal(
29
+ 0,
30
+ run_cmd(%w(product remove-sync-plan
31
+ --organization-id 1
32
+ --name product1)).exit_code
33
+ )
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../sync_plan/sync_plan_helpers')
4
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
5
+
6
+ describe "set a product's sync plan" do
7
+ include OrganizationHelpers
8
+ include SyncPlanHelpers
9
+ include ProductHelpers
10
+
11
+ it "by product ID and sync-plan ID" do
12
+ api_expects(:products, :update, "set sync plan") do |params|
13
+ params['id'] == 1 && params['sync_plan_id'] == 1
14
+ end
15
+
16
+ assert_equal(
17
+ 0,
18
+ run_cmd(%w(product set-sync-plan --id 1 --sync-plan-id 1)).exit_code
19
+ )
20
+ end
21
+
22
+ it "by product ID and sync-plan name (requires org ID)" do
23
+ expect_sync_plan_search(1, 'syncplan1', 1)
24
+ api_expects(:products, :update, "set sync plan") do |params|
25
+ params['id'] == 1 && params['sync_plan_id'] == 1
26
+ end
27
+
28
+ assert_equal(
29
+ 0,
30
+ run_cmd(%w(product set-sync-plan --organization-id 1 --id 1 --sync-plan syncplan1)).exit_code
31
+ )
32
+ end
33
+
34
+ it "by product name and sync-plan name (both requiring org ID)" do
35
+ expect_product_search(1, 'product1', 1)
36
+ expect_sync_plan_search(1, 'syncplan1', 1)
37
+ api_expects(:products, :update, "set sync plan") do |params|
38
+ params['id'] == 1 && params['sync_plan_id'] == 1
39
+ end
40
+
41
+ assert_equal(
42
+ 0,
43
+ run_cmd(%w(product set-sync-plan
44
+ --organization-id 1
45
+ --name product1
46
+ --sync-plan syncplan1)).exit_code
47
+ )
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../organization/organization_helpers')
3
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
4
+
5
+ describe 'update a product' do
6
+ include OrganizationHelpers
7
+ include ProductHelpers
8
+
9
+ it 'by product ID' do
10
+ api_expects(:products, :update, 'update a product') do |par|
11
+ par['id'] == 1 &&
12
+ par['description'] == 'new_description'
13
+ end
14
+ assert_equal(
15
+ 0,
16
+ run_cmd(%w(product update --organization-id 1 --id 1 --description new_description)).exit_code
17
+ )
18
+ end
19
+
20
+ it 'by organization ID and product name' do
21
+ expect_product_search(1, 'product1', 1)
22
+ api_expects(:products, :update, 'update a product') do |par|
23
+ par['id'] == 1 &&
24
+ par['description'] == 'new_description'
25
+ end
26
+ command = %w(product update --organization-id 1 --name product1 --description new_description)
27
+ assert_equal(
28
+ 0,
29
+ run_cmd(command).exit_code
30
+ )
31
+ end
32
+
33
+ it 'by organization name and product name' do
34
+ expect_organization_search('org1', 1)
35
+ expect_product_search(1, 'product1', 1)
36
+ api_expects(:products, :update, 'update a product') do |par|
37
+ par['id'] == 1 &&
38
+ par['description'] == 'new_description'
39
+ end
40
+ command = %w(product update --organization org1 --name product1 --description new_description)
41
+ assert_equal(
42
+ 0,
43
+ run_cmd(command).exit_code
44
+ )
45
+ end
46
+ end
@@ -24,7 +24,7 @@ describe "get repository info" do
24
24
  ex.returns({})
25
25
 
26
26
  result = run_cmd(@cmd + params)
27
- assert(result.exit_code, 0)
27
+ assert_equal(result.exit_code, 0)
28
28
  end
29
29
 
30
30
  it "Shows information about a repository with organization-id and product name" do
@@ -32,7 +32,7 @@ describe "get repository info" do
32
32
 
33
33
  expect_product_search(org_id, 'test_product', product_id)
34
34
 
35
- expect_repository_search(org_id, product_id, 'test_repo', repo_id)
35
+ expect_repository_search(product_id, 'test_repo', repo_id)
36
36
 
37
37
  ex2 = api_expects(:repositories, :show, "Get info") do |par|
38
38
  par["id"] == repo_id
@@ -41,6 +41,6 @@ describe "get repository info" do
41
41
  ex2.returns({})
42
42
 
43
43
  result = run_cmd(@cmd + params)
44
- assert(result.exit_code, 0)
44
+ assert_equal(result.exit_code, 0)
45
45
  end
46
46
  end
@@ -12,19 +12,20 @@ describe 'listing repositories' do
12
12
 
13
13
  let(:org_id) { 1 }
14
14
  let(:lifecycle_env_id) { 1 }
15
- let(:empty_response) do {
16
- "total" => 0,
17
- "subtotal" => 0,
18
- "page" => "1",
19
- "per_page" => "1000",
20
- "error" => nil,
21
- "search" => nil,
22
- "sort" => {
23
- "by" => nil,
24
- "order" => nil
25
- },
26
- "results" => []
27
- }
15
+ let(:empty_response) do
16
+ {
17
+ "total" => 0,
18
+ "subtotal" => 0,
19
+ "page" => "1",
20
+ "per_page" => "1000",
21
+ "error" => nil,
22
+ "search" => nil,
23
+ "sort" => {
24
+ "by" => nil,
25
+ "order" => nil
26
+ },
27
+ "results" => []
28
+ }
28
29
  end
29
30
 
30
31
  it "lists an organizations repositories" do
@@ -0,0 +1,18 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/repository'
3
+
4
+ module HammerCLIKatello
5
+ describe Repository::RemoveContentCommand do
6
+ it 'allows minimal parameters' do
7
+ api_expects(:repositories, :remove_content) { |p| p['id'] == '1' && p['ids'] == %w(1) }
8
+ run_cmd(%w(repository remove-content --ids 1 --id 1))
9
+ end
10
+
11
+ it 'resolves repository id' do
12
+ api_expects(:repositories, :index) { |p| p['name'] == 'repo1' }
13
+ .returns(index_response([{'id' => '1'}]))
14
+ api_expects(:repositories, :remove_content) { |p| p['id'] == '1' && p['ids'] == %w(1) }
15
+ run_cmd(%w(repository remove-content --ids 1 --name repo1))
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,15 @@
1
1
  module RepositoryHelpers
2
- def expect_repository_search(org_id, product_id, name, id)
2
+ def expect_repository_search(product_id, name, id)
3
3
  ex = api_expects(:repositories, :index, 'Find a repository') do |par|
4
- par['name'] == name && par['organization_id'] == org_id &&
5
- par['product_id'] == product_id
4
+ par['name'] == name && par['product_id'] == product_id
6
5
  end
7
6
  ex.returns(index_response([{'id' => id}]))
8
7
  end
8
+
9
+ def expect_repositories_search(org_id, names, ids)
10
+ ex = api_expects(:repositories, :index, 'Find repositories') do |par|
11
+ par['names'] == names && par['organization_id'] == org_id
12
+ end
13
+ ex.returns(index_response(ids.zip(names).map { |id, name| { 'id' => id, 'name' => name } }))
14
+ end
9
15
  end