<s> """<STR_LIT>""" <EOL> import logging <EOL> import mox <EOL> import stubout <EOL> from google . apputils import app <EOL> from tests . simian . mac . common import test <EOL> from simian . mac . cron import maintenance as maint <EOL> class AuthSessionCleanupTest ( test . RequestHandlerTest ) : <EOL> def GetTestClassInstance ( self ) : <EOL> return maint . AuthSessionCleanup ( ) <EOL> def GetTestClassModule ( self ) : <EOL> return maint <EOL> def testGet ( self ) : <EOL> """<STR_LIT>""" <EOL> self . mox . StubOutWithMock ( maint . gaeserver , '<STR_LIT>' ) <EOL> mock_ps = self . mox . CreateMockAnything ( ) <EOL> maint . gaeserver . AuthSessionSimianServer ( ) . AndReturn ( mock_ps ) <EOL> mock_ps . ExpireAll ( ) . AndReturn ( <NUM_LIT:2> ) <EOL> self . mox . ReplayAll ( ) <EOL> self . c . get ( ) <EOL> self . mox . VerifyAll ( ) <EOL> class UpdateAverageInstallDurationsTest ( test . RequestHandlerTest ) : <EOL> def GetTestClassInstance ( self ) : <EOL> return maint . UpdateAverageInstallDurations ( ) <EOL> def GetTestClassModule ( self ) : <EOL> return maint <EOL> def _testGetUpdatedDescriptionExistingDescWithAvgDuration ( self ) : <EOL> """<STR_LIT>""" <EOL> avg_duration_text = maint . models . PackageInfo . AVG_DURATION_TEXT <EOL> old_desc = '<STR_LIT>' % avg_duration_text % ( <NUM_LIT> , <NUM_LIT> ) <EOL> duration_dict = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> expected_desc = '<STR_LIT>' % avg_duration_text % ( <NUM_LIT> , <NUM_LIT> ) <EOL> new_desc = self . c . _GetUpdatedDescription ( duration_dict , old_desc ) <EOL> self . assertEqual ( new_desc , expected_desc ) <EOL> def _testGetUpdatedDescriptionExistingDescWithoutAvgDuration ( self ) : <EOL> """<STR_LIT>""" <EOL> avg_duration_text = maint . models . PackageInfo . AVG_DURATION_TEXT <EOL> old_desc = '<STR_LIT>' <EOL> duration_dict = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> expected_desc = '<STR_LIT>' % avg_duration_text % ( <NUM_LIT> , <NUM_LIT> ) <EOL> new_desc = self . c . _GetUpdatedDescription ( duration_dict , old_desc ) <EOL> self . assertEqual ( new_desc , expected_desc ) <EOL> def _testGetUpdatedDescriptionEmpty ( self ) : <EOL> """<STR_LIT>""" <EOL> avg_duration_text = maint . models . PackageInfo . AVG_DURATION_TEXT <EOL> old_desc = '<STR_LIT>' <EOL> duration_dict = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> expected_desc = avg_duration_text % ( <NUM_LIT> , <NUM_LIT> ) <EOL> new_desc = self . c . _GetUpdatedDescription ( duration_dict , old_desc ) <EOL> self . assertEqual ( new_desc , expected_desc ) <EOL> def testGet ( self ) : <EOL> """<STR_LIT>""" <EOL> pkginfo1 = self . mox . CreateMockAnything ( ) <EOL> pkginfo1 . name = '<STR_LIT>' <EOL> pkginfo1 . filename = '<STR_LIT>' <EOL> pkginfo1 . plist = '<STR_LIT>' <EOL> pkginfo1 . version = '<STR_LIT>' <EOL> pkg1_munki_name = '<STR_LIT>' % ( pkginfo1 . name , pkginfo1 . version ) <EOL> pkginfo1 . munki_name = pkg1_munki_name <EOL> pkg1_lock = '<STR_LIT>' % pkginfo1 . filename <EOL> mock_pl1 = self . mox . CreateMockAnything ( ) <EOL> pkginfo1 . plist = mock_pl1 <EOL> pkginfos = [ pkginfo1 ] <EOL> install_counts = { <EOL> pkg1_munki_name : { <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:50> , <EOL> '<STR_LIT>' : int ( ( <NUM_LIT:50> ) / <NUM_LIT:2> ) , <EOL> } , <EOL> } <EOL> pkg1_avg_duration_text = maint . models . PackageInfo . AVG_DURATION_TEXT % ( <EOL> install_counts [ pkg1_munki_name ] [ '<STR_LIT>' ] , <EOL> install_counts [ pkg1_munki_name ] [ '<STR_LIT>' ] ) <EOL> pkg1_desc = '<STR_LIT>' <EOL> pkg1_desc_updated = '<STR_LIT>' % ( pkg1_desc , pkg1_avg_duration_text ) <EOL> pkginfo1 . description = pkg1_desc <EOL> self . mox . StubOutWithMock ( maint . models . ReportsCache , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . models . PackageInfo , '<STR_LIT:all>' ) <EOL> self . mox . StubOutWithMock ( maint . gae_util , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . gae_util , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . models . Catalog , '<STR_LIT:all>' ) <EOL> self . mox . StubOutWithMock ( maint . models . Catalog , '<STR_LIT>' ) <EOL> maint . models . ReportsCache . GetInstallCounts ( ) . AndReturn ( <EOL> ( install_counts , None ) ) <EOL> maint . models . PackageInfo . all ( ) . AndReturn ( pkginfos ) <EOL> maint . gae_util . ObtainLock ( pkg1_lock , timeout = <NUM_LIT> ) . AndReturn ( True ) <EOL> mock_pl1 . __getitem__ ( '<STR_LIT:description>' ) . AndReturn ( pkg1_desc ) <EOL> mock_pl1 . __getitem__ ( '<STR_LIT:description>' ) . AndReturn ( pkg1_desc_updated ) <EOL> pkginfo1 . put ( ) . AndReturn ( None ) <EOL> maint . gae_util . ReleaseLock ( pkg1_lock ) . AndReturn ( None ) <EOL> delay = <NUM_LIT:0> <EOL> for track in maint . common . TRACKS : <EOL> delay += <NUM_LIT:5> <EOL> maint . models . Catalog . Generate ( track , delay = delay ) <EOL> self . mox . ReplayAll ( ) <EOL> self . c . get ( ) <EOL> self . assertEqual ( pkginfo1 . description , pkg1_desc_updated ) <EOL> self . mox . VerifyAll ( ) <EOL> class VerifyPackagesCleanupTest ( test . RequestHandlerTest ) : <EOL> def GetTestClassInstance ( self ) : <EOL> return maint . VerifyPackages ( ) <EOL> def GetTestClassModule ( self ) : <EOL> return maint <EOL> def MockPackageInfoQuery ( self , blobstore_key , return_value = None , sleep = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> mock_query = self . mox . CreateMockAnything ( ) <EOL> maint . models . PackageInfo . all ( ) . AndReturn ( mock_query ) <EOL> mock_query . filter ( '<STR_LIT>' , blobstore_key ) . AndReturn ( mock_query ) <EOL> mock_query . get ( ) . AndReturn ( return_value ) <EOL> if sleep : <EOL> maint . time . sleep ( sleep ) . AndReturn ( None ) <EOL> def testGet ( self ) : <EOL> """<STR_LIT>""" <EOL> self . mox . StubOutWithMock ( maint . models , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . blobstore , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . time , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( maint . mail , '<STR_LIT>' ) <EOL> blobstore_key_good = '<STR_LIT>' <EOL> blobstore_key_bad = '<STR_LIT>' <EOL> filename_bad = '<STR_LIT>' <EOL> mock_pkginfo_good = self . mox . CreateMockAnything ( ) <EOL> mock_pkginfo_bad = self . mox . CreateMockAnything ( ) <EOL> mock_pkginfo_good . blobstore_key = blobstore_key_good <EOL> mock_pkginfo_bad . blobstore_key = blobstore_key_bad <EOL> mock_pkginfo_bad . filename = filename_bad <EOL> mock_pkginfo_bad . mtime = maint . datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> pkginfos = [ mock_pkginfo_good , mock_pkginfo_bad ] <EOL> maint . models . PackageInfo . all ( ) . AndReturn ( pkginfos ) <EOL> maint . blobstore . BlobInfo . get ( <EOL> mock_pkginfo_good . blobstore_key ) . AndReturn ( True ) <EOL> maint . blobstore . BlobInfo . get ( <EOL> mock_pkginfo_bad . blobstore_key ) . AndReturn ( None ) <EOL> maint . mail . SendMail ( <EOL> mox . IgnoreArg ( ) , '<STR_LIT>' % filename_bad , <EOL> mox . IgnoreArg ( ) ) . AndReturn ( None ) <EOL> blob_good = self . mox . CreateMockAnything ( ) <EOL> blob_bad = self . mox . CreateMockAnything ( ) <EOL> blob_bad . filename = filename_bad <EOL> blobs = [ blob_good , blob_bad ] <EOL> maint . blobstore . BlobInfo . all ( ) . AndReturn ( blobs ) <EOL> blob_good . key ( ) . AndReturn ( blobstore_key_good ) <EOL> self . MockPackageInfoQuery ( blobstore_key_good , return_value = '<STR_LIT>' ) <EOL> blob_bad . key ( ) . AndReturn ( blobstore_key_bad ) <EOL> self . MockPackageInfoQuery ( blobstore_key_bad , sleep = <NUM_LIT:1> ) <EOL> self . MockPackageInfoQuery ( blobstore_key_bad , sleep = <NUM_LIT:1> ) <EOL> self . MockPackageInfoQuery ( blobstore_key_bad , sleep = <NUM_LIT:1> ) <EOL> self . MockPackageInfoQuery ( blobstore_key_bad , sleep = <NUM_LIT:1> ) <EOL> self . MockPackageInfoQuery ( blobstore_key_bad ) <EOL> maint . mail . SendMail ( <EOL> mox . IgnoreArg ( ) , '<STR_LIT>' % filename_bad , <EOL> mox . IgnoreArg ( ) ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> self . c . get ( ) <EOL> self . mox . VerifyAll ( ) <EOL> logging . basicConfig ( filename = '<STR_LIT>' ) <EOL> def main ( unused_argv ) : <EOL> test . main ( unused_argv ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
