Add unittest which tests encrypt() when `output` is given an open file.

* ADD new unittest, `test_encryption_to_filehandle`.
fix/24-output-to-filename
Isis Lovecruft 2014-08-02 04:14:22 +00:00
parent 83784657d5
commit 4d120a2288
No known key found for this signature in database
GPG Key ID: 5C17776E27F7E84D
1 changed files with 24 additions and 1 deletions

View File

@ -1011,6 +1011,28 @@ know, maybe you shouldn't be doing it in the first place.
encrypted_message = fh.read()
log.debug("Encrypted file contains:\n\n%s\n" % encrypted_message)
def test_encryption_to_filehandle(self):
"""Test that ``encrypt(..., output=filelikething)`` is successful."""
with open(os.path.join(_files, 'kat.sec')) as katsec:
self.gpg.import_keys(katsec.read())
fpr = self.gpg.list_keys('kat')[0]['fingerprint']
output = os.path.join(self.gpg.homedir, 'test-encryption-to-filehandle.gpg')
output_file = open(output, 'w+')
message_filename = os.path.join(_files, 'cypherpunk_manifesto')
message_file = open(message_filename)
message = message_file.read()
message_file.close()
encrypted = self.gpg.encrypt(message, fpr, output=output_file)
self.assertTrue(encrypted.ok)
self.assertTrue(os.path.isfile(output))
# Check the contents:
with open(output) as fh:
encrypted_message = fh.read()
log.debug("Encrypted file contains:\n\n%s\n" % encrypted_message)
suites = { 'parsers': set(['test_parsers_fix_unsafe',
'test_parsers_fix_unsafe_semicolon',
@ -1056,7 +1078,8 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe',
'test_decryption',
'test_symmetric_encryption_and_decryption',
'test_file_encryption_and_decryption',
'test_encryption_to_filename',]),
'test_encryption_to_filename',
'test_encryption_to_filehandle',]),
'listkeys': set(['test_list_keys_after_generation']),
'keyrings': set(['test_public_keyring',
'test_secret_keyring',