def testEncryptWithKeyring(self): """Test encrypting with a specific keyring.""" # Where our keyrings are pubring=os.path.join(os.getcwd(), "rings", "pubtest.gpg") g=gpg.GPG(gpg.findGPG()) encrypted, warnings=g.encryptString(['*****@*****.**'], 'hello', pubring) self.assertEncrypted(encrypted)
def testNegativeFindGPG(self): """Negative test finding gpg.""" # This should fail to find the requested binary try: fnd=gpg.findGPG('ThisShouldNotExist') self.fail("Shouldn't have found ThisShouldNotExist, got: " + fnd) except exceptions.Exception, e: self.assertEquals(str(e), "Cannot find GPG")
def testFailingEncryption(self): """Test an attempt to encrypt with an invalid key should fail.""" g=gpg.GPG(gpg.findGPG()) try: encrypted, warnings=g.encryptString(['ThisKeyDoesNotExist'], 'hello') fail("Expected encryption to fail, returned\n" + encrypted + " with warnings:\n" + warnings) except gpg.EncryptionError, e: self.failUnless(str(e).find("public key not found") > 0, "Got the wrong error:\n" + str(e))
def testEncryptString(self): """Test encrypting a string.""" g=gpg.GPG(gpg.findGPG()) encrypted, warnings=g.encryptString(['primary'], 'hello') self.assertEncrypted(encrypted)
def testFindGPG(self): """Positive test finding gpg""" # Just make sure we got something self.failIf(len(gpg.findGPG()) == 0)