hammer_cli_foreman 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/config/foreman.yml +4 -0
  3. data/doc/release_notes.md +21 -5
  4. data/lib/hammer_cli_foreman/api/connection.rb +14 -5
  5. data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +17 -5
  6. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +27 -8
  7. data/lib/hammer_cli_foreman/auth.rb +14 -10
  8. data/lib/hammer_cli_foreman/auth_source_ldap.rb +38 -34
  9. data/lib/hammer_cli_foreman/compute_resource.rb +24 -0
  10. data/lib/hammer_cli_foreman/filter.rb +6 -2
  11. data/lib/hammer_cli_foreman/host.rb +2 -7
  12. data/lib/hammer_cli_foreman/hostgroup.rb +1 -0
  13. data/lib/hammer_cli_foreman/id_resolver.rb +27 -7
  14. data/lib/hammer_cli_foreman/location.rb +1 -0
  15. data/lib/hammer_cli_foreman/organization.rb +1 -0
  16. data/lib/hammer_cli_foreman/references.rb +10 -2
  17. data/lib/hammer_cli_foreman/smart_class_parameter.rb +10 -1
  18. data/lib/hammer_cli_foreman/smart_variable.rb +24 -16
  19. data/lib/hammer_cli_foreman/subnet.rb +33 -3
  20. data/lib/hammer_cli_foreman/template.rb +1 -1
  21. data/lib/hammer_cli_foreman/testing/api_expectations.rb +3 -1
  22. data/lib/hammer_cli_foreman/user.rb +37 -3
  23. data/lib/hammer_cli_foreman/version.rb +1 -1
  24. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  32. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/test/functional/filter_test.rb +146 -0
  38. data/test/functional/host_test.rb +12 -0
  39. data/test/functional/smart_variable_test.rb +4 -4
  40. data/test/functional/template_test.rb +20 -0
  41. data/test/functional/user_test.rb +13 -13
  42. data/test/unit/api/interactive_basic_auth_test.rb +18 -0
  43. data/test/unit/api/session_authenticator_wrapper_test.rb +72 -2
  44. data/test/unit/apipie_resource_mock.rb +3 -0
  45. data/test/unit/auth_source_ldap_test.rb +2 -3
  46. data/test/unit/commands_test.rb +1 -1
  47. data/test/unit/compute_resource_test.rb +24 -0
  48. data/test/unit/host_test.rb +1 -1
  49. data/test/unit/hostgroup_test.rb +1 -1
  50. data/test/unit/id_resolver_test.rb +59 -21
  51. data/test/unit/subnet_test.rb +1 -0
  52. data/test/unit/user_test.rb +7 -1
  53. metadata +35 -33
@@ -40,13 +40,13 @@ module HammerCLIForeman
40
40
  :fact_value => [],
41
41
  :filter => [],
42
42
  :host => [ s_name(_("Host name")) ],
43
- :hostgroup => [ s_name(_("Hostgroup name")), s("title", _("Hostgroup title"),:editable => false) ],
43
+ :hostgroup => [ s_name(_("Hostgroup name")), s("title", _("Hostgroup title"), :editable => false) ],
44
44
  # :image => [],
45
45
  :interface => [],
46
- :location => [ s_name(_("Location name")) ],
46
+ :location => [ s_name(_("Location name")), s("title", _("Location title"), :editable => false) ],
47
47
  :medium => [ s_name(_("Medium name")) ],
48
48
  :model => [ s_name(_("Model name")) ],
49
- :organization => [ s_name(_("Organization name")) ],
49
+ :organization => [ s_name(_("Organization name")), s("title", _("Organization title"), :editable => false) ],
50
50
  :operatingsystem => [ s("title", _("Operating system title"), :editable => false) ],
51
51
  :override_value => [],
52
52
  :ptable => [ s_name(_("Partition table name")) ],
@@ -144,7 +144,13 @@ module HammerCLIForeman
144
144
  end
145
145
 
146
146
  def get_ids(resource_name, options)
147
- options[HammerCLI.option_accessor_name("ids")] || find_resources(resource_name, options).map{|r| r['id']}
147
+ if (ids = options[HammerCLI.option_accessor_name("ids")])
148
+ ids
149
+ elsif !options_empty?(@api.resource(resource_name), options)
150
+ find_resources(resource_name, options).map{|r| r['id']}
151
+ else
152
+ []
153
+ end
148
154
  end
149
155
 
150
156
  def find_resources(resource_name, options)
@@ -157,9 +163,16 @@ module HammerCLIForeman
157
163
  def find_puppetclasses(options)
158
164
  resource_name = :puppetclasses
159
165
  resource = @api.resource(resource_name)
160
- results = resolved_call(resource_name, :index, options).first.values.flatten
161
- raise ResolverError.new(_("one of %s not found") % resource.name, resource) if results.count < expected_record_count(options, resource)
162
- results
166
+
167
+ if (ids = options[HammerCLI.option_accessor_name("ids")])
168
+ ids
169
+ elsif !options_empty?(resource, options)
170
+ results = resolved_call(resource_name, :index, options).first.values.flatten
171
+ raise ResolverError.new(_("one of %s not found") % resource.name, resource) if results.count < expected_record_count(options, resource)
172
+ results
173
+ else
174
+ []
175
+ end
163
176
  end
164
177
 
165
178
  def find_resource(resource_name, options)
@@ -249,6 +262,13 @@ module HammerCLIForeman
249
262
  pick_result(results, resource)['id']
250
263
  end
251
264
 
265
+ def options_empty?(resource, options)
266
+ searchables(resource).any? do |s|
267
+ values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)]
268
+ values && values.respond_to?(:empty?) && values.empty?
269
+ end
270
+ end
271
+
252
272
  def create_smart_class_parameters_search_options(options)
253
273
  search_options = {}
254
274
  value = options[HammerCLI.option_accessor_name('name')]
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
 
12
12
  output do
13
13
  field :id, _("Id")
14
+ field :title, _("Title")
14
15
  field :name, _("Name")
15
16
  field :description, _("Description")
16
17
  end
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
 
12
12
  output do
13
13
  field :id, _("Id")
14
+ field :title, _("Title")
14
15
  field :name, _("Name")
15
16
  field :description, _("Description")
16
17
  end
@@ -13,10 +13,10 @@ module HammerCLIForeman
13
13
  def self.taxonomies(dsl)
14
14
  dsl.build do
15
15
  collection :locations, _("Locations"), :numbered => false, :hide_blank => true do
16
- custom_field Fields::Reference
16
+ custom_field Fields::Reference, :name_key => :title
17
17
  end
18
18
  collection :organizations, _("Organizations"), :numbered => false, :hide_blank => true do
19
- custom_field Fields::Reference
19
+ custom_field Fields::Reference, :name_key => :title
20
20
  end
21
21
  end
22
22
  end
@@ -121,6 +121,14 @@ module HammerCLIForeman
121
121
  end
122
122
  end
123
123
 
124
+ def self.all_parameters(dsl)
125
+ dsl.build do
126
+ collection :all_parameters, _("All parameters"), :numbered => false do
127
+ custom_field Fields::KeyValue
128
+ end
129
+ end
130
+ end
131
+
124
132
  def self.puppetclasses(dsl)
125
133
  dsl.build do
126
134
  collection :puppetclasses, _("Puppetclasses"), :numbered => false do
@@ -107,7 +107,7 @@ module HammerCLIForeman
107
107
 
108
108
  build_options do |options|
109
109
  options.expand.including(:puppetclasses)
110
- options.without(:parameter_type, :validator_type, :override, :required)
110
+ options.without(:parameter_type, :validator_type, :override, :required, :override_value_order)
111
111
  end
112
112
 
113
113
  option "--override", "OVERRIDE", _("Override this parameter."),
@@ -119,12 +119,21 @@ module HammerCLIForeman
119
119
  ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
120
120
  option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
121
121
  :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
122
+ option "--override-value-order", "OVERRIDE_VALUE_ORDER", _("The order in which values are resolved"),
123
+ :format => HammerCLI::Options::Normalizers::List.new
122
124
 
123
125
  validate_options do
124
126
  if option(:option_name).exist?
125
127
  any(:option_puppetclass_name, :option_puppetclass_id).required
126
128
  end
127
129
  end
130
+
131
+ def request_params
132
+ params = super
133
+ override_order = params['smart_class_parameter']['override_value_order']
134
+ params['smart_class_parameter']['override_value_order'] = override_order.join("\n") if override_order.is_a?(Array)
135
+ params
136
+ end
128
137
  end
129
138
 
130
139
  class AddOverrideValueCommand < HammerCLIForeman::CreateCommand
@@ -1,5 +1,27 @@
1
1
  module HammerCLIForeman
2
2
 
3
+ module SmartVariableUpdateCreateCommons
4
+
5
+ def self.included(base)
6
+ base.option "--variable-type", "VARIABLE_TYPE", _("Type of the variable."),
7
+ :format => HammerCLI::Options::Normalizers::Enum.new(
8
+ ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
9
+ base.option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
10
+ :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
11
+ base.option "--override-value-order", "OVERRIDE_VALUE_ORDER", _("The order in which values are resolved"),
12
+ :format => HammerCLI::Options::Normalizers::List.new
13
+
14
+ base.build_options :without => [:variable_type, :validator_type, :override_value_order]
15
+ end
16
+
17
+ def request_params
18
+ params = super
19
+ override_order = params['smart_variable']['override_value_order']
20
+ params['smart_variable']['override_value_order'] = override_order.join("\n") if override_order.is_a?(Array)
21
+ params
22
+ end
23
+ end
24
+
3
25
  class SmartVariablesBriefList < HammerCLIForeman::ListCommand
4
26
  resource :smart_variables, :index
5
27
  command_name 'smart-variables'
@@ -80,31 +102,17 @@ module HammerCLIForeman
80
102
  end
81
103
 
82
104
  class CreateCommand < HammerCLIForeman::CreateCommand
105
+ include SmartVariableUpdateCreateCommons
83
106
 
84
107
  success_message _("Smart variable [%{variable}] created")
85
108
  failure_message _("Could not create the smart variable")
86
-
87
- build_options :without => [:variable_type, :validator_type]
88
-
89
- option "--variable-type", "VARIABLE_TYPE", _("Type of the variable."),
90
- :format => HammerCLI::Options::Normalizers::Enum.new(
91
- ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
92
- option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
93
- :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
94
109
  end
95
110
 
96
111
  class UpdateCommand < HammerCLIForeman::UpdateCommand
112
+ include SmartVariableUpdateCreateCommons
97
113
 
98
114
  success_message _("Smart variable [%{variable}] updated")
99
115
  failure_message _("Could not update the smart variable")
100
-
101
- build_options :without => [:variable_type, :validator_type]
102
-
103
- option "--variable-type", "VARIABLE_TYPE", _("Type of the variable."),
104
- :format => HammerCLI::Options::Normalizers::Enum.new(
105
- ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
106
- option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
107
- :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
108
116
  end
109
117
 
110
118
 
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
  field :name, _("Name")
12
12
  field :network, _("Network")
13
13
  field :mask, _("Mask")
14
+ field :vlanid, _("VLAN ID")
14
15
  end
15
16
 
16
17
  build_options
@@ -20,6 +21,7 @@ module HammerCLIForeman
20
21
  class InfoCommand < HammerCLIForeman::InfoCommand
21
22
 
22
23
  output ListCommand.output_definition do
24
+ field :description, _("Description"), Fields::LongText, :hide_blank => true
23
25
  field :priority, _("Priority")
24
26
  field :dns, _("DNS"), Fields::Reference, :details => :url
25
27
  field :dns_primary, _("Primary DNS")
@@ -27,12 +29,12 @@ module HammerCLIForeman
27
29
  field :tftp, _("TFTP"), Fields::Reference, :details => :url
28
30
  field :dhcp, _("DHCP"), Fields::Reference, :details => :url
29
31
  field :ipam, _("IPAM")
30
- field :vlanid, _("VLAN ID")
31
32
  field :gateway, _("Gateway")
32
33
  field :from, _("From")
33
34
  field :to, _("To")
34
35
  HammerCLIForeman::References.domains(self)
35
36
  HammerCLIForeman::References.taxonomies(self)
37
+ HammerCLIForeman::References.parameters(self)
36
38
  end
37
39
 
38
40
  build_options
@@ -44,7 +46,7 @@ module HammerCLIForeman
44
46
  success_message _("Subnet created")
45
47
  failure_message _("Could not create the subnet")
46
48
 
47
- build_options
49
+ build_options :without => [:subnet_parameters_attributes]
48
50
  end
49
51
 
50
52
 
@@ -53,7 +55,7 @@ module HammerCLIForeman
53
55
  success_message _("Subnet updated")
54
56
  failure_message _("Could not update the subnet")
55
57
 
56
- build_options
58
+ build_options :without => [:subnet_parameters_attributes]
57
59
  end
58
60
 
59
61
 
@@ -62,6 +64,34 @@ module HammerCLIForeman
62
64
  success_message _("Subnet deleted")
63
65
  failure_message _("Could not delete the subnet")
64
66
 
67
+ build_options :without => [:subnet_parameters_attributes]
68
+ end
69
+
70
+ class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
71
+ desc _("Create or update parameter for a subnet.")
72
+
73
+ success_message_for :update, _("Subnet parameter updated")
74
+ success_message_for :create, _("New subnet parameter created")
75
+ failure_message _("Could not set subnet parameter")
76
+
77
+ def validate_options
78
+ super
79
+ validator.any(:option_subnet_name, :option_subnet_id).required
80
+ end
81
+
82
+ build_options
83
+ end
84
+
85
+ class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
86
+ desc _("Delete parameter for a subnet.")
87
+
88
+ success_message _("Subnet parameter deleted")
89
+
90
+ def validate_options
91
+ super
92
+ validator.any(:option_subnet_name, :option_subnet_id).required
93
+ end
94
+
65
95
  build_options
66
96
  end
67
97
 
@@ -7,7 +7,7 @@ module HammerCLIForeman
7
7
  module TemplateCreateUpdateCommons
8
8
 
9
9
  def option_snippet
10
- option_type == "snippet"
10
+ option_type && (option_type == "snippet")
11
11
  end
12
12
 
13
13
  def option_template_kind_id
@@ -116,7 +116,9 @@ module HammerCLIForeman
116
116
  end
117
117
 
118
118
  class TestAuthenticator < ApipieBindings::Authenticators::BasicAuth
119
- attr_reader :user
119
+ def user(ask=nil)
120
+ @user
121
+ end
120
122
  end
121
123
 
122
124
  class FakeApiConnection < HammerCLI::Apipie::ApiConnection
@@ -11,6 +11,9 @@ module HammerCLIForeman
11
11
  field :login, _("Login")
12
12
  field :full_name, _("Name")
13
13
  field :mail, _("Email")
14
+ field :admin, _("Admin"), Fields::Boolean
15
+ field :last_login_on, _("Last login"), Fields::Date
16
+ field nil, _("Authorized by"), Fields::SingleReference, :key => :auth_source
14
17
  end
15
18
 
16
19
  def extend_data(user)
@@ -25,12 +28,9 @@ module HammerCLIForeman
25
28
  class InfoCommand < HammerCLIForeman::InfoCommand
26
29
 
27
30
  output ListCommand.output_definition do
28
- field :admin, _("Admin"), Fields::Boolean
29
31
  field :effective_admin, _("Effective admin"), Fields::Boolean
30
- field nil, _("Authorized by"), Fields::SingleReference, :key => :auth_source
31
32
  field :locale, _("Locale")
32
33
  field :timezone, _("Timezone")
33
- field :last_login_on, _("Last login"), Fields::Date
34
34
  field :description, _("Description")
35
35
  custom_field Fields::Reference, :label => _("Default organization"), :path => [:default_organization]
36
36
  custom_field Fields::Reference, :label => _("Default location"), :path => [:default_location]
@@ -55,6 +55,21 @@ module HammerCLIForeman
55
55
  def self.included(base)
56
56
  base.option '--default-organization', 'DEFAULT_ORGANIZATION_NAME', _("Default organization name")
57
57
  base.option '--default-location', 'DEFAULT_LOCATION_NAME', _("Default location name")
58
+ base.option "--ask-password", "ASK_PW", " ",
59
+ :format => HammerCLI::Options::Normalizers::Bool.new
60
+ end
61
+
62
+ def self.ask_password(type)
63
+ if type == :current
64
+ prompt = _("Enter user's current password:") + " "
65
+ elsif type == :new
66
+ prompt = _("Enter user's new password:") + " "
67
+ end
68
+ ask(prompt) {|q| q.echo = false}
69
+ end
70
+
71
+ def current_logged_user
72
+ HammerCLIForeman.foreman_api_connection.resource(:users).call(:show, :id => HammerCLIForeman.foreman_api_connection.authenticator.user(true))
58
73
  end
59
74
 
60
75
  def request_params
@@ -63,6 +78,11 @@ module HammerCLIForeman
63
78
  params['user']['default_organization_id'] ||= org_id unless org_id.nil?
64
79
  loc_id = location_id(option_default_location)
65
80
  params['user']['default_location_id'] ||= loc_id unless loc_id.nil?
81
+ params['user']['password'] = option_password unless option_password.nil?
82
+
83
+ if option_ask_password
84
+ params['user']['password'] = HammerCLIForeman::User::CommonUpdateOptions::ask_password(:new)
85
+ end
66
86
  params
67
87
  end
68
88
 
@@ -89,6 +109,20 @@ module HammerCLIForeman
89
109
  failure_message _("Could not update the user")
90
110
 
91
111
  include CommonUpdateOptions
112
+
113
+ def request_params
114
+ params = super
115
+
116
+ if (option_password || option_ask_password)
117
+ if current_logged_user["id"].to_s == params["id"].to_s
118
+ if (!option_current_password && (option_password || option_ask_password))
119
+ params['user']['current_password'] = HammerCLIForeman::User::CommonUpdateOptions::ask_password(:current)
120
+ end
121
+ end
122
+ end
123
+ params
124
+ end
125
+
92
126
  build_options
93
127
  end
94
128
 
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
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
@@ -0,0 +1,146 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'filter' do
4
+ def api_expects_filter_info(options)
5
+ override = !!options[:override]
6
+ api_expects(:filters, :show, 'Get filter info').with_params({
7
+ :id => '1'
8
+ }).returns(@filter.merge('override?' => override))
9
+ end
10
+
11
+ def taxonomy_usage_error(action, cmd)
12
+ usage_error_result(
13
+ cmd,
14
+ 'Organizations and locations can be set only for overriding filters',
15
+ "Could not #{action} the permission filter")
16
+ end
17
+
18
+ def assert_update_success(result)
19
+ assert_cmd(success_result("Permission filter for [User] updated\n"), result)
20
+ end
21
+
22
+ describe 'create' do
23
+ before do
24
+ @cmd = %w(filter create)
25
+ end
26
+
27
+ it 'prints error when taxonomies are used for a not-overriding filter' do
28
+ params = ['--organization-ids=1,2', '--location-ids=3,4', '--override=false']
29
+
30
+ api_expects_no_call
31
+
32
+ result = run_cmd(@cmd + params)
33
+ assert_cmd(taxonomy_usage_error('create', @cmd), result)
34
+ end
35
+ end
36
+
37
+ describe 'update' do
38
+ before do
39
+ @cmd = %w(filter update)
40
+ @filter = {
41
+ "search" => nil,
42
+ "resource_type" => "User",
43
+ "unlimited?" => false,
44
+ "created_at" => "2017-07-18 14:34:09 UTC",
45
+ "updated_at" => "2017-07-18 14:34:09 UTC",
46
+ "override?" => true,
47
+ "id" => 404,
48
+ "role" => {
49
+ "name" => "Some Role",
50
+ "id" => 28,
51
+ "description" => "Description\nof the new\nrole",
52
+ "origin" => nil
53
+ },
54
+ "permissions" => [{
55
+ "name" => "view_users",
56
+ "id" => 164,
57
+ "resource_type" => "User"
58
+ }],
59
+ "locations" => [{
60
+ "id" => 28,
61
+ "name" => "location74",
62
+ "title" => "location74",
63
+ "description" => nil
64
+ }],
65
+ "organizations" => [{
66
+ "id" => 27,
67
+ "name" => "organization74",
68
+ "title" => "organization74",
69
+ "description" => nil
70
+ }]
71
+ }
72
+ end
73
+
74
+ it 'resets taxonomies when a filter is not-overriding' do
75
+ params = ['--id=1']
76
+
77
+ api_expects_filter_info(:override => false)
78
+ api_expects(:filters, :update, 'Update the filter').with_params({
79
+ 'filter' => {
80
+ 'organization_ids' => [],
81
+ 'location_ids' => []
82
+ }
83
+ }).returns(@filter)
84
+
85
+ assert_update_success(run_cmd(@cmd + params))
86
+ end
87
+
88
+ it 'resets taxonomies when switching a filter to not-overriding' do
89
+ params = ['--id=1', '--override=false']
90
+
91
+ api_expects(:filters, :update, 'Update the filter').with_params({
92
+ 'filter' => {
93
+ 'organization_ids' => [],
94
+ 'location_ids' => []
95
+ }
96
+ }).returns(@filter)
97
+
98
+ assert_update_success(run_cmd(@cmd + params))
99
+ end
100
+
101
+ it 'can add taxonomies when a filter is overriding' do
102
+ params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
103
+
104
+ api_expects_filter_info(:override => true)
105
+ api_expects(:filters, :update, 'Update the filter').with_params({
106
+ 'filter' => {
107
+ 'organization_ids' => ['1', '2'],
108
+ 'location_ids' => ['3', '4']
109
+ }
110
+ }).returns(@filter)
111
+
112
+ assert_update_success(run_cmd(@cmd + params))
113
+ end
114
+
115
+ it 'can add taxonomies when switching a filter to overriding' do
116
+ params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4', '--override=true']
117
+
118
+ api_expects(:filters, :update, 'Update the filter').with_params({
119
+ 'filter' => {
120
+ 'organization_ids' => ['1', '2'],
121
+ 'location_ids' => ['3', '4']
122
+ }
123
+ }).returns(@filter)
124
+
125
+ assert_update_success(run_cmd(@cmd + params))
126
+ end
127
+
128
+ it 'prints error when taxonomies are used on not-overriding' do
129
+ params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
130
+
131
+ api_expects_filter_info(:override => false)
132
+
133
+ result = run_cmd(@cmd + params)
134
+ assert_cmd(taxonomy_usage_error('update', @cmd), result)
135
+ end
136
+
137
+ it 'prints error when taxonomies are used when switching a filter to not-overriding' do
138
+ params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4', '--override=false']
139
+
140
+ api_expects_no_call
141
+
142
+ result = run_cmd(@cmd + params)
143
+ assert_cmd(taxonomy_usage_error('update', @cmd), result)
144
+ end
145
+ end
146
+ end