From 83784657d571a1db855640fabd06bde07ffc55c1 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Sat, 2 Aug 2014 04:02:15 +0000 Subject: [PATCH] Add new unittest that tests encryption with a filename output. * ADD test_encryption_to_filename which checks that encrypt(..., output='somefilename.gpg') works correctly (when `output` is a string containing the filename). This tests for the bug reported in Issue #24. https://github.com/isislovecruft/python-gnupg/issues/24 --- gnupg/test/test_gnupg.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gnupg/test/test_gnupg.py b/gnupg/test/test_gnupg.py index 9541896..5154cf0 100755 --- a/gnupg/test/test_gnupg.py +++ b/gnupg/test/test_gnupg.py @@ -990,6 +990,27 @@ know, maybe you shouldn't be doing it in the first place. log.debug("new (from decryption): %r" % ddata) self.assertEqual(data, ddata) + def test_encryption_to_filename(self): + """Test that ``encrypt(..., output='somefile.gpg')`` 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-filename.gpg') + + 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) + 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', @@ -1034,7 +1055,8 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe', 'test_encryption_decryption_multi_recipient', 'test_decryption', 'test_symmetric_encryption_and_decryption', - 'test_file_encryption_and_decryption']), + 'test_file_encryption_and_decryption', + 'test_encryption_to_filename',]), 'listkeys': set(['test_list_keys_after_generation']), 'keyrings': set(['test_public_keyring', 'test_secret_keyring',