hammer_cli_katello 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dcf91d9100831001701d8a61e531d765ac488c4
4
- data.tar.gz: 37a5a7be16c2289cc9b6a97aaff6248e80610b8f
3
+ metadata.gz: 8197e2982960b69052e68e379aba43aad78c6819
4
+ data.tar.gz: b9d0f0364f933ff8a71a8e8aafee5775610d2982
5
5
  SHA512:
6
- metadata.gz: c7c554fda4cc6b31e6e845a81eb38b4aaf68a7272e1abfdecb1de9360f20afc50f5b6d0cb137967be58859337029a757ca1b7dde2ec4f27ee931710307c0501f
7
- data.tar.gz: 647ad55f48a038b4c4f9c76539aa9a60c4a824e93525c40757c4af2921e126bb88a87946a3b8db15c12875fb694f8821088de9786c8fb0838bf33fc856813810
6
+ metadata.gz: 780d8434cd5a4968f09058345c61afffd1d3d3d94af048651c0076eeaa96e2732d1c0f944b68c71b8dce3fd14c454fc43a17b8c7bafd4d982dd6aa5236501322
7
+ data.tar.gz: 7b77ee2069bbb31901a6f96d271b9a85df834e28435fed5cfc2f031cd670ff804eb72b8e42aaa1b2d20d3a4db5e539a3abf2652aef409b9e5cdd8e7892c96977
@@ -67,13 +67,20 @@ module HammerCLIKatello
67
67
  validate_options do
68
68
  organization_options = [:option_organization_id, :option_organization_name, \
69
69
  :option_organization_label]
70
+ product_options = [:option_product_id, :option_product_name]
70
71
 
71
- if option(:option_repository_names).exist? || option(:option_content_view_name).exist?
72
+ if option(:option_product_name).exist? || option(:option_content_view_name).exist?
72
73
  any(*organization_options).required
73
74
  end
75
+
76
+ if option(:option_repository_names).exist?
77
+ any(*product_options).required
78
+ end
74
79
  end
75
80
 
76
- build_options
81
+ build_options do |o|
82
+ o.expand.including(:products)
83
+ end
77
84
  end
78
85
 
79
86
  class UpdateCommand < HammerCLIKatello::UpdateCommand
@@ -33,7 +33,9 @@ module HammerCLIKatello
33
33
  DEFAULT_SEARCHABLES = [s_name(_("Name to search by"))].freeze
34
34
 
35
35
  def for(resource)
36
- SEARCHABLES[resource.singular_name.to_sym] || DEFAULT_SEARCHABLES
36
+ SEARCHABLES[resource.singular_name.to_sym] ||
37
+ HammerCLIForeman::Searchables::SEARCHABLES[resource.singular_name.to_sym] ||
38
+ DEFAULT_SEARCHABLES
37
39
  end
38
40
  end
39
41
 
@@ -13,18 +13,30 @@ module HammerCLIKatello
13
13
  organization_options = [:option_organization_id, :option_organization_name, \
14
14
  :option_organization_label]
15
15
  product_options = [:option_product_id, :option_product_name]
16
+ content_view_options = [:option_content_view_id, :option_content_view_name]
16
17
 
17
- if option(:option_product_name).exist?
18
+ if option(:option_product_name).exist? || option(:option_content_view_name).exist?
18
19
  any(*organization_options).required
19
20
  end
20
21
 
21
22
  if option(:option_repository_name).exist?
22
23
  any(*product_options).required
23
24
  end
25
+
26
+ if option(:option_content_view_version_version).exist?
27
+ any(*content_view_options).required
28
+ end
29
+
30
+ if any(*content_view_options).exist?
31
+ any(:option_content_view_version_id,
32
+ :option_content_view_version_version,
33
+ :option_environment_id,
34
+ :option_environment_name).required
35
+ end
24
36
  end
25
37
 
26
38
  build_options do |o|
27
- o.expand.including(:products)
39
+ o.expand.including(:products, :content_views)
28
40
  end
29
41
  end
30
42
 
@@ -4,27 +4,15 @@ module HammerCLIKatello
4
4
  module SearchOptionsCreators
5
5
  include HammerCLIKatello::ForemanSearchOptionsCreators
6
6
 
7
- def create_repository_search_options(options)
8
- name = options[HammerCLI.option_accessor_name("name")]
9
- organization_id = options[HammerCLI.option_accessor_name("organization_id")]
10
-
11
- search_options = {}
12
- search_options['name'] = name if name
13
- search_options['organization_id'] = organization_id if organization_id
14
- search_options
15
- end
16
-
17
7
  def create_repositories_search_options(options)
18
8
  name = options[HammerCLI.option_accessor_name("name")]
19
9
  names = options[HammerCLI.option_accessor_name("names")]
20
10
  product_id = options[HammerCLI.option_accessor_name("product_id")]
21
- organization_id = options[HammerCLI.option_accessor_name("organization_id")]
22
11
 
23
12
  search_options = {}
24
13
  search_options['name'] = name if name
25
14
  search_options['names'] = names if names
26
15
  search_options['product_id'] = product_id if product_id
27
- search_options['organization_id'] = organization_id if organization_id
28
16
  search_options
29
17
  end
30
18
 
@@ -31,7 +31,8 @@ module HammerCLIKatello
31
31
  )
32
32
 
33
33
  option "--sync-date", "SYNC_DATE",
34
- _("start date and time of the synchronization defaults to now"),
34
+ _("Start date and time for the sync plan." \
35
+ "Time is optional, if kept blank current system time will be considered"),
35
36
  :format => HammerCLI::Options::Normalizers::DateTime.new
36
37
 
37
38
  success_message _("Sync plan created")
@@ -1,5 +1,5 @@
1
1
  module HammerCLIKatello
2
2
  def self.version
3
- @version ||= Gem::Version.new('0.10.2')
3
+ @version ||= Gem::Version.new('0.11.0')
4
4
  end
5
5
  end
@@ -5,8 +5,7 @@ describe 'content-view filter create' do
5
5
  include RepositoryHelpers
6
6
  before do
7
7
  @cmd = %w(content-view filter create)
8
- @base_params = ["--organization-id=#{org_id}", "--name=#{filter_name}", \
9
- "--content-view-id=#{content_view_id}", "--type=rpm"]
8
+ @base_params = ["--name=#{filter_name}", "--content-view-id=#{content_view_id}", "--type=rpm"]
10
9
  end
11
10
 
12
11
  let(:org_id) { 1 }
@@ -26,12 +25,9 @@ describe 'content-view filter create' do
26
25
  ids = repo_ids.join(',')
27
26
  params = %W(--repository-ids=#{ids})
28
27
 
29
- ex = api_expects(:content_view_filters, :create, 'Create content-view filter') do |par|
30
- par['name'] == filter_name && par['repository_ids'] == repo_ids
31
- true
32
- end
33
-
34
- ex.returns({})
28
+ api_expects(:content_view_filters, :create, 'Create content-view filter')
29
+ .with_params('name' => filter_name, 'repository_ids' => repo_ids.map(&:to_s))
30
+ .returns({})
35
31
 
36
32
  expected_result = success_result("Filter created\n")
37
33
  result = run_cmd(@cmd + @base_params + params)
@@ -39,25 +35,23 @@ describe 'content-view filter create' do
39
35
  end
40
36
 
41
37
  it 'creates a content-view filter with repository names' do
42
- params = %W(--repositories=#{repo_names.join(',')})
38
+ params = %W(--repositories=#{repo_names.join(',')} --product-id 3)
43
39
 
44
- expect_repositories_search(org_id.to_s, repo_names, repo_ids)
40
+ expect_generic_repositories_search({'names' => repo_names, 'product_id' => 3}, repositories)
45
41
 
46
- api_expects(:content_view_filters, :create, "Create content-view filter") do |par|
47
- par['name'] == filter_name && par['repository_ids'] == repo_ids &&
48
- par['type'] == 'rpm'
49
- end
42
+ api_expects(:content_view_filters, :create, "Create content-view filter")
43
+ .with_params('name' => filter_name, 'repository_ids' => repo_ids, 'type' => 'rpm')
50
44
 
51
45
  expected_result = success_result("Filter created\n")
52
46
  result = run_cmd(@cmd + @base_params + params)
53
47
  assert_cmd(expected_result, result)
54
48
  end
55
49
 
56
- it 'should fail with no organization specified' do
50
+ it 'should fail with no product specified' do
57
51
  ids = repo_ids.join(',')
58
52
  params = ["--repositories=#{ids}", "--name=#{filter_name}", \
59
53
  "--content-view-id=#{content_view_id}", "--type=rpm"]
60
54
  result = run_cmd(@cmd + params)
61
- assert(result.err[/--organization-id, --organization, --organization-label is required/])
55
+ assert(result.err[/--product-id, --product is required/])
62
56
  end
63
57
  end
@@ -16,11 +16,36 @@ module HammerCLIKatello
16
16
  run_cmd(%w(package list))
17
17
  end
18
18
 
19
+ describe 'content view options' do
20
+ it 'may be specified by ID' do
21
+ api_expects(:content_view_versions, :index)
22
+ .with_params('content_view_id' => 1, 'version' => '2.1')
23
+ .returns(index_response([{'id' => 5}]))
24
+ api_expects(:packages, :index).with_params('content_view_version_id' => 5)
25
+
26
+ run_cmd(%w(package list --content-view-id 1 --content-view-version 2.1))
27
+ end
28
+
29
+ it 'requires organization ID when given content view name' do
30
+ api_expects_no_call
31
+
32
+ r = run_cmd(%w(package list --content-view cv1 --content-view-version 2.1))
33
+ expected_error = "--organization-id, --organization, --organization-label is required"
34
+ assert(r.err.include?(expected_error), "Invalid error message")
35
+ end
36
+
37
+ it 'requires content view ID when given content view version name' do
38
+ api_expects_no_call
39
+
40
+ r = run_cmd(%w(package list --content-view-version cvv1))
41
+ assert(r.err.include?("--content-view-id, --content-view is required"),
42
+ "Invalid error message")
43
+ end
44
+ end
45
+
19
46
  describe 'repository options' do
20
47
  it 'may be specified by ID' do
21
- api_expects(:packages, :index) do |params|
22
- params['repository_id'] == 1
23
- end
48
+ api_expects(:packages, :index).with_params('repository_id' => 1)
24
49
 
25
50
  run_cmd(%w(package list --repository-id 1))
26
51
  end
@@ -35,9 +60,7 @@ module HammerCLIKatello
35
60
  it 'may be specified by name and product ID' do
36
61
  expect_repository_search(2, 'repo1', 1)
37
62
 
38
- api_expects(:packages, :index) do |params|
39
- params['repository_id'] == 1
40
- end
63
+ api_expects(:packages, :index).with_params('repository_id' => 1)
41
64
 
42
65
  run_cmd(%w(package list --repository repo1 --product-id 2))
43
66
  end
@@ -45,23 +68,19 @@ module HammerCLIKatello
45
68
 
46
69
  describe 'product options' do
47
70
  it 'may be specified by ID' do
48
- ex = api_expects(:repositories, :index) do |p|
49
- p['product_id'] == 1
50
- end
51
- ex.returns(index_response([{'id' => 2}]))
71
+ api_expects(:repositories, :index)
72
+ .with_params('product_id' => 1)
73
+ .returns(index_response([{'id' => 2}]))
52
74
 
53
- api_expects(:packages, :index) do |p|
54
- p['repository_id'] = 2
55
- end
75
+ api_expects(:packages, :index).with_params('repository_id' => 2)
56
76
 
57
77
  run_cmd(%w(package list --product-id 1))
58
78
  end
59
79
 
60
80
  it 'fail if more than one repository is found' do
61
- ex = api_expects(:repositories, :index) do |p|
62
- p['product_id'] == 1
63
- end
64
- ex.returns(index_response([{'id' => 2}, {'id' => 3}]))
81
+ api_expects(:repositories, :index)
82
+ .with_params('product_id' => 1)
83
+ .returns(index_response([{'id' => 2}, {'id' => 3}]))
65
84
 
66
85
  r = run_cmd(%w(package list --product-id 1))
67
86
  assert(r.err.include?("found more than one repository"), "Invalid error message")
@@ -78,11 +97,9 @@ module HammerCLIKatello
78
97
  it 'allows organization ID when resolving ID by name' do
79
98
  expect_product_search(3, 'product1', 1)
80
99
 
81
- expect_repository_search(1, nil, 2)
100
+ expect_generic_repositories_search({'product_id' => 1}, [{'id' => 2}])
82
101
 
83
- api_expects(:packages, :index) do |p|
84
- p['repository_id'] = 2
85
- end
102
+ api_expects(:packages, :index).with_params('repository_id' => 2)
86
103
 
87
104
  run_cmd(%w(package list --product product1 --organization-id 3))
88
105
  end
@@ -92,11 +109,9 @@ module HammerCLIKatello
92
109
 
93
110
  expect_product_search(3, 'product1', 1)
94
111
 
95
- expect_repository_search(1, nil, 2)
112
+ expect_generic_repositories_search({'product_id' => 1}, [{'id' => 2}])
96
113
 
97
- api_expects(:packages, :index) do |p|
98
- p['repository_id'] = 2
99
- end
114
+ api_expects(:packages, :index).with_params('repository_id' => 2)
100
115
 
101
116
  run_cmd(%w(package list --product product1 --organization org3))
102
117
  end
@@ -106,11 +121,9 @@ module HammerCLIKatello
106
121
 
107
122
  expect_product_search(3, 'product1', 1)
108
123
 
109
- expect_repository_search(1, nil, 2)
124
+ expect_generic_repositories_search({'product_id' => 1}, [{'id' => 2}])
110
125
 
111
- api_expects(:packages, :index) do |p|
112
- p['repository_id'] = 2
113
- end
126
+ api_expects(:packages, :index).with_params('repository_id' => 2)
114
127
 
115
128
  run_cmd(%w(package list --product product1 --organization-label org3))
116
129
  end
@@ -16,10 +16,9 @@ module HammerCLIKatello
16
16
  end
17
17
 
18
18
  it 'can be specified via product id' do
19
- ex = api_expects(:repositories, :index) do |p|
20
- p['product_id'] == 3 && p['name'] == 'repo1'
21
- end
22
- ex.returns(index_response([{'id' => 1}]))
19
+ api_expects(:repositories, :index)
20
+ .with_params('product_id' => 3, 'name' => 'repo1')
21
+ .returns(index_response([{'id' => 1}]))
23
22
 
24
23
  api_expects(:repositories, :destroy) { |p| p['id'] == 1 }
25
24
 
@@ -27,15 +26,13 @@ module HammerCLIKatello
27
26
  end
28
27
 
29
28
  it 'can be specified via product name' do
30
- ex = api_expects(:products, :index) do |p|
31
- p['organization_id'] == '6' && p['name'] == 'product3'
32
- end
33
- ex.returns(index_response([{'id' => 3}]))
29
+ api_expects(:products, :index)
30
+ .with_params('organization_id' => '6', 'name' => 'product3')
31
+ .returns(index_response([{'id' => 3}]))
34
32
 
35
- ex = api_expects(:repositories, :index) do |p|
36
- p['product_id'] == 3 && p['name'] == 'repo1' && p['organization_id'] == '6'
37
- end
38
- ex.returns(index_response([{'id' => 1}]))
33
+ api_expects(:repositories, :index)
34
+ .with_params('product_id' => 3, 'name' => 'repo1')
35
+ .returns(index_response([{'id' => 1}]))
39
36
 
40
37
  api_expects(:repositories, :destroy) { |p| p['id'] == 1 }
41
38
 
@@ -44,31 +41,31 @@ module HammerCLIKatello
44
41
 
45
42
  describe 'organization options' do
46
43
  it 'can be specified by organization id' do
47
- ex = api_expects(:repositories, :index) do |p|
48
- p['product_id'] == 3 && p['name'] == 'repo1' && p['organization_id'] == '6'
49
- end
50
- ex.returns(index_response([{'id' => 1}]))
44
+ api_expects(:products, :index)
45
+ .with_params('organization_id' => '6', 'name' => 'product3')
46
+ .returns(index_response([{'id' => 3}]))
47
+
48
+ api_expects(:repositories, :index)
49
+ .with_params('product_id' => 3, 'name' => 'repo1')
50
+ .returns(index_response([{'id' => 1}]))
51
51
 
52
52
  api_expects(:repositories, :destroy) { |p| p['id'] == 1 }
53
53
 
54
- run_cmd(%w(repository delete --name repo1 --product-id 3 --organization-id 6))
54
+ run_cmd(%w(repository delete --name repo1 --product product3 --organization-id 6))
55
55
  end
56
56
 
57
57
  it 'can be specified by organization name' do
58
- ex = api_expects(:organizations, :index) do |p|
59
- p[:search] == "name = \"org6\""
60
- end
61
- ex.returns(index_response([{'id' => 6}]))
58
+ api_expects(:organizations, :index)
59
+ .with_params(:search => "name = \"org6\"")
60
+ .returns(index_response([{'id' => 6}]))
62
61
 
63
- ex = api_expects(:products, :index) do |p|
64
- p['organization_id'] == 6 && p['name'] == 'product3'
65
- end
66
- ex.returns(index_response([{'id' => 3}]))
62
+ api_expects(:products, :index)
63
+ .with_params('organization_id' => 6, 'name' => 'product3')
64
+ .returns(index_response([{'id' => 3}]))
67
65
 
68
- ex = api_expects(:repositories, :index) do |p|
69
- p['product_id'] == 3 && p['name'] == 'repo1'
70
- end
71
- ex.returns(index_response([{'id' => 1}]))
66
+ api_expects(:repositories, :index)
67
+ .with_params('product_id' => 3, 'name' => 'repo1')
68
+ .returns(index_response([{'id' => 1}]))
72
69
 
73
70
  api_expects(:repositories, :destroy) { |p| p['id'] == 1 }
74
71
 
@@ -76,20 +73,17 @@ module HammerCLIKatello
76
73
  end
77
74
 
78
75
  it 'can be specified by organization label' do
79
- ex = api_expects(:organizations, :index) do |p|
80
- p[:search] == "label = \"org6\""
81
- end
82
- ex.returns(index_response([{'id' => 6}]))
83
-
84
- ex = api_expects(:products, :index) do |p|
85
- p['organization_id'] == 6 && p['name'] == 'product3'
86
- end
87
- ex.returns(index_response([{'id' => 3}]))
88
-
89
- ex = api_expects(:repositories, :index) do |p|
90
- p['product_id'] == 3 && p['name'] == 'repo1'
91
- end
92
- ex.returns(index_response([{'id' => 1}]))
76
+ api_expects(:organizations, :index)
77
+ .with_params(:search => "label = \"org6\"")
78
+ .returns(index_response([{'id' => 6}]))
79
+
80
+ api_expects(:products, :index)
81
+ .with_params('organization_id' => 6, 'name' => 'product3')
82
+ .returns(index_response([{'id' => 3}]))
83
+
84
+ api_expects(:repositories, :index)
85
+ .with_params('product_id' => 3, 'name' => 'repo1')
86
+ .returns(index_response([{'id' => 1}]))
93
87
 
94
88
  api_expects(:repositories, :destroy) { |p| p['id'] == 1 }
95
89
 
@@ -1,15 +1,18 @@
1
1
  module RepositoryHelpers
2
2
  def expect_repository_search(product_id, name, id)
3
- ex = api_expects(:repositories, :index, 'Find a repository') do |par|
4
- par['name'] == name && par['product_id'] == product_id
5
- end
6
- ex.returns(index_response([{'id' => id}]))
3
+ api_expects(:repositories, :index, 'Find a repository')
4
+ .with_params('name' => name, 'product_id' => product_id)
5
+ .returns(index_response([{'id' => id}]))
7
6
  end
8
7
 
9
8
  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 } }))
9
+ expect_generic_repositories_search({'names' => names, 'organization_id' => org_id},
10
+ ids.zip(names).map { |id, name| { 'id' => id, 'name' => name } })
11
+ end
12
+
13
+ def expect_generic_repositories_search(params = {}, returns = [])
14
+ api_expects(:repositories, :index, 'Find repositories')
15
+ .with_params(params)
16
+ .returns(index_response(returns))
14
17
  end
15
18
  end
@@ -20,20 +20,6 @@ describe HammerCLIKatello::SearchOptionsCreators do
20
20
  resource.stubs(:singular_name).returns('')
21
21
  end
22
22
 
23
- describe '#create_repository_search_options' do
24
- it 'handles a repository' do
25
- search_options_creators.create_repository_search_options(
26
- 'option_name' => 'repo1'
27
- )['name'].must_equal 'repo1'
28
- end
29
-
30
- it 'handles an organization_id' do
31
- search_options_creators.create_repository_search_options(
32
- 'option_organization_id' => 2
33
- )['organization_id'].must_equal 2
34
- end
35
- end
36
-
37
23
  describe '#create_repositories_search_options' do
38
24
  it 'handles an array of names' do
39
25
  search_options_creators.create_repositories_search_options(
@@ -52,12 +38,6 @@ describe HammerCLIKatello::SearchOptionsCreators do
52
38
  'option_product_id' => 3
53
39
  )['product_id'].must_equal 3
54
40
  end
55
-
56
- it 'handles an organization_id' do
57
- search_options_creators.create_repositories_search_options(
58
- 'option_organization_id' => 4
59
- )['organization_id'].must_equal 4
60
- end
61
41
  end
62
42
 
63
43
  describe '#create_content_view_versions_search_options(options)' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_katello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Price
@@ -34,7 +34,7 @@ authors:
34
34
  autorequire:
35
35
  bindir: bin
36
36
  cert_chain: []
37
- date: 2017-05-15 00:00:00.000000000 Z
37
+ date: 2017-08-21 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: hammer_cli_foreman