'Generally, we pass unicode strings (the type form data is
returned as) as plaintext to crypto_util.encrypt(). These have
to be converted to "binary stream" types (such as `file`) before
we can actually call gnupg.GPG.encrypt() on them. This is done
in crypto_util.encrypt() with an `if` branch that uses
`gnupg._util._is_stream(plaintext)` as the predicate, and calls
`gnupg._util._make_binary_stream(plaintext)` if necessary. This
test ensures our encrypt function works even if we provide
inputs such that this `if` branch is skipped (i.e., the object
passed for `plaintext` is one such that
`gnupg._util._is_stream(plaintext)` returns `True`).'

def test_encrypt_binary_stream(self):

    (source, codename) = utils.db_helper.init_source()
    with open(os.path.realpath(__file__)) as fh:
        ciphertext = crypto_util.encrypt(fh, [crypto_util.getkey(source.filesystem_id), config.JOURNALIST_KEY], store.path(source.filesystem_id, 'somefile.gpg'))
    plaintext = crypto_util.decrypt(codename, ciphertext)
    with open(os.path.realpath(__file__)) as fh:
        self.assertEqual(fh.read(), plaintext)
