From 4d120a22882738305015587379b49c2aff26b275 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Sat, 2 Aug 2014 04:14:22 +0000 Subject: [PATCH] Add unittest which tests encrypt() when `output` is given an open file. * ADD new unittest, `test_encryption_to_filehandle`. --- gnupg/test/test_gnupg.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gnupg/test/test_gnupg.py b/gnupg/test/test_gnupg.py index 5154cf0..46876f5 100755 --- a/gnupg/test/test_gnupg.py +++ b/gnupg/test/test_gnupg.py @@ -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',