'Test that encryption and decryption proceed after an exception'

def test_db_encrypt_decrypt_exception_continue(self):

    def create_malformed_template():
        'Initialize    a    malformed    template    which    should    fail    encryption.'
        t = template_format.parse('\n                                                heat_template_version:    2013-05-23\n                                                parameters:\n                                                                param1:\n                                                                                type:    string\n                                                                                description:    value1.\n                                                                param2:\n                                                                                type:    string\n                                                                                description:    value2.\n                                                                                hidden:    true\n                                                                param3:\n                                                                                type:    string\n                                                                                description:    value3\n                                                                                hidden:    true\n                                                                                default:    "don\'t    encrypt    me!    I\'m    not    sensitive    enough"\n                                                resources:\n                                                                a_resource:\n                                                                                type:    GenericResourceType\n                                                ')
        template = {'template': t, 'files': {'foo': 'bar'}, 'environment': ''}
        return db_api.raw_template_create(self.ctx, template)
    create_malformed_template()
    self._create_template()
    enc_result = db_api.db_encrypt_parameters_and_properties(self.ctx, cfg.CONF.auth_encryption_key, batch_size=50)
    self.assertEqual(1, len(enc_result))
    self.assertIs(AttributeError, type(enc_result[0]))
    enc_tmpls = self.ctx.session.query(models.RawTemplate).all()
    self.assertEqual('', enc_tmpls[1].environment)
    self.assertEqual('cryptography_decrypt_v1', enc_tmpls[2].environment['parameters']['param2'][0])
    dec_result = db_api.db_decrypt_parameters_and_properties(self.ctx, cfg.CONF.auth_encryption_key, batch_size=50)
    self.assertEqual(len(dec_result), 1)
    self.assertIs(AttributeError, type(dec_result[0]))
    dec_tmpls = self.ctx.session.query(models.RawTemplate).all()
    self.assertEqual('', dec_tmpls[1].environment)
    self.assertEqual('bar', dec_tmpls[2].environment['parameters']['param2'])
