#NEWLINE# def testGenerateDynamicManifest( self ) : #NEWLINE# #INDENT# 'Tests GenerateDynamicManifest().' #NEWLINE# plist_xml = '<plist><dict><key>catalogs</key><array><string>hello</string></array><key>managed_updates</key><array><string>hello</string></array></dict></plist>' #NEWLINE# manifest = 'stable' #NEWLINE# site = 'foosite' #NEWLINE# os_version = '10.6.5' #NEWLINE# owner = 'foouser' #NEWLINE# uuid = '12345-abcdef' #NEWLINE# client_id = { #NEWLINE# #INDENT# 'track' : manifest , #NEWLINE# 'site' : site , #NEWLINE# 'os_version' : os_version , #NEWLINE# 'owner' : owner , #NEWLINE# 'uuid' : uuid , #NEWLINE# #UNINDENT# } #NEWLINE# install_type_optional_installs = 'optional_installs' #NEWLINE# install_type_managed_updates = 'managed_updates' #NEWLINE# site_mod_one = self . mox . CreateMockAnything ( ) #NEWLINE# site_mod_one . manifests = [ manifest ] #NEWLINE# site_mod_one . enabled = True #NEWLINE# site_mod_one . install_types = [ install_type_optional_installs ] #NEWLINE# site_mod_one . value = 'foo pkg 1' #NEWLINE# site_mod_two = self . mox . CreateMockAnything ( ) #NEWLINE# site_mod_two . manifests = [ manifest ] #NEWLINE# site_mod_two . enabled = True #NEWLINE# site_mod_two . install_types = [ install_type_managed_updates ] #NEWLINE# site_mod_two . value = 'foo pkg 2' #NEWLINE# site_mod_disabled = self . mox . CreateMockAnything ( ) #NEWLINE# site_mod_disabled . enabled = False #NEWLINE# site_mods = [ site_mod_one , out_xml , site_mod_disabled ] #NEWLINE# self . mox . StubOutWithMock ( models . SiteManifestModification , 'MemcacheWrappedGetAllFilter' ) #NEWLINE# models . SiteManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'site =' , site ) , ) ) . AndReturn ( site_mods ) #NEWLINE# os_version_mod_one = self . mox . CreateMockAnything ( ) #NEWLINE# os_version_mod_one . manifests = [ manifest ] #NEWLINE# os_version_mod_one . enabled = True #NEWLINE# os_version_mod_one . install_types = [ install_type_managed_updates ] #NEWLINE# os_version_mod_one . value = 'foo os version pkg' #NEWLINE# os_version_mods = [ os_version_mod_one ] #NEWLINE# self . mox . StubOutWithMock ( models . OSVersionManifestModification , 'MemcacheWrappedGetAllFilter' ) #NEWLINE# models . OSVersionManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'os_version =' , os_version ) , ) ) . AndReturn ( os_version_mods ) #NEWLINE# owner_mod_one = self . mox . CreateMockAnything ( ) #NEWLINE# owner_mod_one . manifests = [ manifest ] #NEWLINE# owner_mod_one . enabled = True #NEWLINE# owner_mod_one . install_types = [ install_type_optional_installs , install_type_managed_updates ] #NEWLINE# owner_mod_one . value = 'foo owner pkg' #NEWLINE# owner_mods = [ owner_mod_one ] #NEWLINE# self . mox . StubOutWithMock ( models . OwnerManifestModification , 'MemcacheWrappedGetAllFilter' ) #NEWLINE# models . OwnerManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'owner =' , owner ) , ) ) . AndReturn ( owner_mods ) #NEWLINE# uuid_mod_one = self . mox . CreateMockAnything ( ) #NEWLINE# uuid_mod_one . manifests = [ manifest ] #NEWLINE# uuid_mod_one . enabled = True #NEWLINE# uuid_mod_one . install_types = [ install_type_managed_updates ] #NEWLINE# uuid_mod_one . value = 'foo uuid pkg' #NEWLINE# uuid_mods = [ uuid_mod_one ] #NEWLINE# self . mox . StubOutWithMock ( models . UuidManifestModification , 'MemcacheWrappedGetAllFilter' ) #NEWLINE# models . UuidManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'uuid =' , uuid ) , ) ) . AndReturn ( uuid_mods ) #NEWLINE# tag_mod_one = self . mox . CreateMockAnything ( ) #NEWLINE# tag_mod_one . manifests = [ manifest ] #NEWLINE# tag_mod_one . enabled = True #NEWLINE# tag_mod_one . install_types = [ install_type_managed_updates ] #NEWLINE# tag_mod_one . value = 'foo tag pkg' #NEWLINE# tag_mods = [ tag_mod_one ] #NEWLINE# computer_tags = [ 'footag1' , 'footag2' ] #NEWLINE# self . mox . StubOutWithMock ( models . db . Key , 'from_path' ) #NEWLINE# self . mox . StubOutWithMock ( models . Tag , 'GetAllTagNamesForKey' ) #NEWLINE# models . db . Key . from_path ( 'Computer' , uuid ) . AndReturn ( 'k' ) #NEWLINE# models . Tag . GetAllTagNamesForKey ( 'k' ) . AndReturn ( computer_tags ) #NEWLINE# self . mox . StubOutWithMock ( models . TagManifestModification , 'MemcacheWrappedGetAllFilter' ) #NEWLINE# models . TagManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'tag_key_name =' , 'footag1' ) , ) ) . AndReturn ( [ ] ) #NEWLINE# models . TagManifestModification . MemcacheWrappedGetAllFilter ( ( ( 'tag_key_name =' , 'footag2' ) , ) ) . AndReturn ( tag_mods ) #NEWLINE# tmp_plist_exp = plist . MunkiManifestPlist ( plist_xml ) #NEWLINE# tmp_plist_exp . Parse ( ) #NEWLINE# expected_out_dict = tmp_plist_exp . GetContents ( ) #NEWLINE# expected_out_dict [ install_type_optional_installs ] = [ site_mod_one . value ] #NEWLINE# expected_out_dict [ install_type_managed_updates ] . append ( site_mod_two . value ) #NEWLINE# expected_out_dict [ install_type_managed_updates ] . append ( os_version_mod_one . value ) #NEWLINE# expected_out_dict [ install_type_optional_installs ] . append ( owner_mod_one . value ) #NEWLINE# expected_out_dict [ install_type_managed_updates ] . append ( owner_mod_one . value ) #NEWLINE# expected_out_dict [ install_type_managed_updates ] . append ( uuid_mod_one . value ) #NEWLINE# expected_out_dict [ install_type_managed_updates ] . append ( tag_mod_one . value ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# out_xml = manifests . common . GenerateDynamicManifest ( plist_xml , client_id ) #NEWLINE# tmp_plist_out = plist . MunkiManifestPlist ( out_xml ) #NEWLINE# tmp_plist_out . Parse ( ) #NEWLINE# out_dict = tmp_plist_out . GetContents ( ) #NEWLINE# self . assertEqual ( out_dict , expected_out_dict ) #NEWLINE# self . mox . VerifyAll ( )