<s> '''<STR_LIT>''' <EOL> import unittest , os , errno <EOL> import gnupg <EOL> from LRSignature import util as util <EOL> class Test ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def mkdir_p ( self , path ) : <EOL> try : <EOL> os . makedirs ( path ) <EOL> except OSError as exc : <EOL> if exc . errno == errno . EEXIST : <EOL> pass <EOL> else : raise <EOL> def rm_rf ( self , path ) : <EOL> for r , d , f in os . walk ( path ) : <EOL> for files in f : <EOL> os . remove ( os . path . join ( r , files ) ) <EOL> os . removedirs ( r ) <EOL> def chmod ( self , path , mode ) : <EOL> try : <EOL> os . chmod ( path , mode ) <EOL> except : <EOL> pass <EOL> def setUp ( self ) : <EOL> self . gnupghome = os . path . expanduser ( os . path . abspath ( os . path . join ( "<STR_LIT:..>" , "<STR_LIT>" ) ) ) <EOL> self . gpgbin = '<STR_LIT>' <EOL> self . rm_rf ( self . gnupghome ) <EOL> self . mkdir_p ( self . gnupghome ) <EOL> self . gpg = gnupg . GPG ( gnupghome = self . gnupghome , gpgbinary = self . gpgbin ) <EOL> self . sampleKeyId = "<STR_LIT>" <EOL> self . sampleKeyFingerprint = "<STR_LIT>" <EOL> self . sampleKey = '''<STR_LIT>''' <EOL> def tearDown ( self ) : <EOL> self . rm_rf ( self . gnupghome ) <EOL> pass <EOL> def checkKey ( self , key , keysource = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> numkeys = len ( keys ) <EOL> result = self . gpg . import_keys ( key ) <EOL> assert result != None and result . imported == <NUM_LIT:1> , "<STR_LIT>" . format ( keysource ) <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> assert len ( keys ) == numkeys + <NUM_LIT:1> , "<STR_LIT>" . format ( keysource ) <EOL> def testPGPFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> def testSKSFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> def testWebSiteFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> def testHTTPFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> def testMultipleFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:2> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:1> ] , keysource = "<STR_LIT>" ) <EOL> def testGoogleDocFetchKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keyURL = "<STR_LIT>" <EOL> fetchedKeys = util . fetchkeys ( keyURL ) <EOL> assert len ( fetchedKeys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> self . checkKey ( fetchedKeys [ <NUM_LIT:0> ] , keysource = "<STR_LIT>" ) <EOL> def testStoreKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> for key in keys : <EOL> assert key [ '<STR_LIT>' ] != self . sampleKeyId , "<STR_LIT>" <EOL> numkeys = len ( keys ) <EOL> numImported = util . storekey ( self . sampleKey , gnupghome = self . gnupghome , gpgbin = self . gpgbin ) <EOL> assert numImported == <NUM_LIT:1> , "<STR_LIT>" <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> assert len ( keys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> for key in keys : <EOL> assert key [ '<STR_LIT>' ] == self . sampleKeyId , "<STR_LIT>" <EOL> def testStoreExistingKey ( self ) : <EOL> '''<STR_LIT>''' <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> for key in keys : <EOL> assert key [ '<STR_LIT>' ] != self . sampleKeyId , "<STR_LIT>" <EOL> numkeys = len ( keys ) <EOL> numImported = util . storekey ( self . sampleKey , gnupghome = self . gnupghome , gpgbin = self . gpgbin ) <EOL> assert numImported == <NUM_LIT:1> , "<STR_LIT>" <EOL> numImported = util . storekey ( self . sampleKey , gnupghome = self . gnupghome , gpgbin = self . gpgbin ) <EOL> assert numImported == <NUM_LIT:0> , "<STR_LIT>" <EOL> keys = self . gpg . list_keys ( secret = False ) <EOL> assert len ( keys ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> for key in keys : <EOL> assert key [ '<STR_LIT>' ] == self . sampleKeyId , "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
