#NEWLINE# def testDeprecateOrphanedProducts( self ) : #NEWLINE# #INDENT# 'Tests _DeprecateOrphanedProducts() with deprecated & active products.' #NEWLINE# self . stubs . Set ( applesus . applesus , 'OS_VERSIONS' , frozenset ( [ '10.9' , '10.10' , None ] ) ) #NEWLINE# self . stubs . Set ( applesus . common , 'TRACKS' , ( applesus . common . TRACKS + [ 'parseerror' ] ) ) #NEWLINE# self . mox . StubOutWithMock ( applesus . plist , 'ApplePlist' ) #NEWLINE# self . mox . StubOutWithMock ( applesus . models , 'AppleSUSProduct' ) #NEWLINE# self . mox . StubOutWithMock ( applesus . models , 'AppleSUSCatalog' ) #NEWLINE# test_products = { #NEWLINE# #INDENT# '10.5_unstable' : [ 'product1' ] , #NEWLINE# '10.5_testing' : [ 'product1' ] , #NEWLINE# '10.5_stable' : [ 'product1' , 'product2' ] , #NEWLINE# '10.5_untouched' : [ 'product1' ] , #NEWLINE# '10.6_unstable' : [ 'product3' ] , #NEWLINE# '10.6_testing' : [ 'product3' , 'product4' ] , #NEWLINE# '10.6_stable' : [ 'product3' ] , #NEWLINE# '10.6_untouched' : [ 'product1' ] , #NEWLINE# '10.7_unstable' : [ 'product5' , 'product6' ] , #NEWLINE# '10.7_testing' : [ 'product5' ] , #NEWLINE# '10.7_stable' : [ 'product5' ] , #NEWLINE# '10.7_untouched' : [ 'product7' ] , #NEWLINE# '10.8_unstable' : [ 'product5' , 'product6' ] , #NEWLINE# '10.8_testing' : [ 'product5' ] , #NEWLINE# '10.8_stable' : [ 'product5' ] , #NEWLINE# '10.8_untouched' : [ 'product7' ] , #NEWLINE# '10.9_unstable' : [ 'product5' , 'product6' ] , #NEWLINE# '10.9_testing' : [ 'product5' ] , #NEWLINE# '10.9_stable' : [ 'product5' ] , #NEWLINE# '10.9_untouched' : [ 'product7' ] , #NEWLINE# '10.10_unstable' : [ 'product1' ] , #NEWLINE# '10.10_testing' : [ 'product3' , 'product4' ] , #NEWLINE# '10.10_stable' : [ 'product3' ] , #NEWLINE# '10.10_untouched' : [ 'product7' ] , #NEWLINE# '10.11_unstable' : [ 'product1' ] , #NEWLINE# '10.11_testing' : [ 'product3' , 'product4' ] , #NEWLINE# '10.11_stable' : [ 'product3' ] , #NEWLINE# '10.11_untouched' : [ 'product7' ] , #NEWLINE# #UNINDENT# } #NEWLINE# deprecated_products = [ ] #NEWLINE# for p in [ 'product2' , 'product3' , 'product7' , 'deprecateme' , 'andme' ] : #NEWLINE# #INDENT# mock_product = self . mox . CreateMockAnything ( ) #NEWLINE# mock_product . product_id = p #NEWLINE# deprecated_products . append ( mock_product ) #NEWLINE# #UNINDENT# for os_version in applesus . applesus . OS_VERSIONS : #NEWLINE# #INDENT# for track in ( applesus . common . TRACKS + [ 'untouched' ] ) : #NEWLINE# #INDENT# key = ( '%s_%s' % ( os_version , track ) ) #NEWLINE# if ( not os_version ) : #NEWLINE# #INDENT# applesus . models . AppleSUSCatalog . get_by_key_name ( key ) . AndReturn ( None ) #NEWLINE# continue #NEWLINE# #UNINDENT# mock_p = self . mox . CreateMockAnything ( ) #NEWLINE# mock_p . plist = ( 'fooplist-%s' % key ) #NEWLINE# applesus . models . AppleSUSCatalog . get_by_key_name ( key ) . AndReturn ( mock_p ) #NEWLINE# mock_plist = self . mox . CreateMockAnything ( ) #NEWLINE# mock_plist = applesus . plist . ApplePlist ( mock_p . plist ) . AndReturn ( mock_plist ) #NEWLINE# if ( track == 'parseerror' ) : #NEWLINE# #INDENT# mock_plist . Parse ( ) . AndRaise ( applesus . plist . Error ) #NEWLINE# continue #NEWLINE# #UNINDENT# mock_plist . Parse ( ) . AndReturn ( None ) #NEWLINE# mock_plist . get ( 'Products' , [ ] ) . AndReturn ( test_products [ key ] ) #NEWLINE# #UNINDENT# #UNINDENT# expected_deprecated_out = [ ] #NEWLINE# mock_query = self . mox . CreateMockAnything ( ) #NEWLINE# applesus . models . AppleSUSProduct . all ( ) . AndReturn ( mock_query ) #NEWLINE# mock_query . filter ( 'deprecated =' , False ) . AndReturn ( deprecated_products ) #NEWLINE# for deprecated_product in deprecated_products : #NEWLINE# #INDENT# if ( deprecated_product . product_id in [ 'product2' , 'deprecateme' , 'andme' ] ) : #NEWLINE# #INDENT# deprecated_product . put ( ) . AndReturn ( None ) #NEWLINE# expected_deprecated_out . append ( deprecated_product ) #NEWLINE# #UNINDENT# #UNINDENT# self . mox . ReplayAll ( ) #NEWLINE# out = self . c . _DeprecateOrphanedProducts ( ) #NEWLINE# self . assertEqual ( out , expected_deprecated_out ) #NEWLINE# self . mox . VerifyAll ( )