cubicweb/test/unittest_crypto.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 16 May 2019 17:17:42 +0200
branch3.26
changeset 12615 7abe23cbfda1
child 12682 da36da3f89f1
permissions -rw-r--r--
Make crypto module python3-compatible * Remove usage of unicode() and decode the base64-encoded string in encrypt(); * Encode the string received in decrypt() as (I supposed) it should come from the result of encrypt(). Add tests for this module along the way.

from unittest import TestCase

from cubicweb import crypto


class CryptoTC(TestCase):

    def test_encrypt_decrypt_roundtrip(self):
        data = {'a': u'ah', 'b': [1, 2]}
        seed = 'ssss'
        crypted = crypto.encrypt(data, seed)
        decrypted = crypto.decrypt(crypted, seed)
        self.assertEqual(decrypted, data)


if __name__ == '__main__':
    import unittest
    unittest.main()