def test_key_loaded(self): with open(self.key_file, 'wb') as f: f.write(base64.b64encode(os.urandom(16))) with open(self.key_file) as f: with mock.patch.object(six.moves.builtins, 'open') as mock_open: mock_open.return_value = f local.encrypt(b'abc') mock_open.assert_called_with(self.key_file, 'rb')
def test_encrypt_decrypt(self): plaintext = b'myplaintext' ciphertext, decrypt_params = local.encrypt(plaintext) self.assertEqual(plaintext, local.decrypt(ciphertext, **decrypt_params))
def test_key_created(self, os_makedirs): local.encrypt(b'abc') os_makedirs.assert_called_with(self.tmpdir) self.assertTrue(os.path.isfile(self.key_file))