'Uses a private key to encrypt data on model creation.
Verifies the data is encrypted in the database and can be decrypted.'

def test_text_field_create(self):

    with keys(keyinfo.DECRYPT_AND_ENCRYPT) as crypt:
        with secret_model() as model:
            test_val = 'Test    Secret'
            secret = model.objects.create(text=test_val)
            cursor = connection.cursor()
            query = ('SELECT    text    FROM    %s    WHERE    id    =    %d' % (model._meta.db_table, secret.id))
            cursor.execute(query)
            (db_val,) = cursor.fetchone()
            decrypted_val = crypt.Decrypt(db_val[len(EncryptedCharField.prefix):])
            self.assertEqual(test_val, decrypted_val)
