@@ -17,6 +17,7 @@ def test_usage
1717 csv content-hosts [OPTIONS]
1818
1919Options:
20+ --clear-subscriptions When processing --itemized-subscriptions, clear existing subscriptions first
2021 --columns COLUMN_NAMES Comma separated list of column names to export
2122 --continue-on-error Continue processing even if individual resource error
2223 --export Export current data instead of importing
@@ -56,6 +57,19 @@ def test_usage
5657 stop_vcr
5758 end
5859
60+ def test_export_with_clear_subscriptions
61+ start_vcr
62+ set_user 'admin'
63+
64+ stdout , stderr = capture {
65+ hammer . run ( %W{ --reload-cache csv content-hosts --export --clear-subscriptions } )
66+ }
67+ assert_equal "Error: --clear-subscriptions option only relevant during import\n " , stderr
68+ assert_equal stdout , ''
69+
70+ stop_vcr
71+ end
72+
5973 def test_export_with_columns
6074 start_vcr
6175 set_user 'admin'
@@ -186,7 +200,7 @@ def test_import_search
186200 hammer . run ( %W{ --reload-cache csv content-hosts --verbose --file #{ file . path } } )
187201 }
188202 assert_equal '' , stderr
189- assert_equal "Updating content host 'testaaa0'...done\n Updating content host 'testaaa1'...done\n " , stdout
203+ assert_equal "Updating content host 'testaaa0'...clearing existing subscriptions... done\n Updating content host 'testaaa1'...clearing existing subscriptions ...done\n " , stdout
190204
191205
192206 %w{ testaaa0 testaaa1 testbbb0 testbbb1 testbbb2 } . each do |hostname |
@@ -196,6 +210,49 @@ def test_import_search
196210 stop_vcr
197211 end
198212
213+ # import a single line, then import again w/ clearing
214+ def test_import_single_line_clear_subs
215+ start_vcr
216+ set_user 'admin'
217+
218+ hostname = 'tester1'
219+
220+ file = Tempfile . new ( 'content_hosts_test' )
221+ file . write ( "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n " )
222+ file . write ( "#{ hostname } ,Test Corporation,Library,Default Organization View,\" \" ,Yes,,RHEL 7.2,x86_64,2,3882752,1,\" \" ,\" 69|Red Hat Enterprise Linux Server,290|Red Hat OpenShift Enterprise\" ,\" \" \" 1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium\" \" \" \n " )
223+ file . rewind
224+
225+ stdout , stderr = capture {
226+ hammer . run ( %W{ --reload-cache csv content-hosts --verbose --file #{ file . path } } )
227+ }
228+ assert_equal '' , stderr
229+ assert_equal "Creating content host '#{ hostname } '...done\n " , stdout
230+
231+ file = Tempfile . new ( 'content_hosts_test' )
232+ file . write ( "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n " )
233+ file . write ( "#{ hostname } ,Test Corporation,Library,Default Organization View,\" \" ,Yes,,RHEL 7.2,x86_64,2,3882752,1,\" \" ,\" 69|Red Hat Enterprise Linux Server,290|Red Hat OpenShift Enterprise\" ,\" \" \" |RH00004|Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)\" \" \" \n " )
234+ file . rewind
235+
236+ stdout , stderr = capture {
237+ hammer . run ( %W{ --reload-cache csv content-hosts --verbose --file #{ file . path } --clear-subscriptions } )
238+ }
239+ assert_equal '' , stderr
240+ assert_equal "Updating content host '#{ hostname } '...clearing existing subscriptions...done\n " , stdout
241+
242+ stdout , stderr = capture {
243+ hammer . run ( %W{ --reload-cache csv content-hosts --export --organization Test\ Corporation --itemized-subscriptions --search name=#{ hostname } } )
244+ }
245+ assert_equal '' , stderr
246+ lines = stdout . split ( "\n " )
247+ lines . select! { |line | line . match ( /tester1.*/ ) }
248+ assert_equal 1 , lines . length
249+ assert_match ( /.*Test Corporation,Library,Default Organization View,"",Yes,,RHEL 7.2,x86_64,2,3882752,1.*/ , lines [ 0 ] )
250+ assert_match ( /.*Red Hat Enterprise Linux Server, Standard.*/ , lines [ 0 ] )
251+ host_delete ( hostname )
252+
253+ stop_vcr
254+ end
255+
199256 def test_columns_config
200257 start_vcr
201258 set_user 'admin'
0 commit comments