'Tests for db_field override
Tests to ensure that udt\'s in models can specify db_field for a particular field and that it will be honored.
@since 3.1.0
@jira_ticket PYTHON-346
@expected_result The actual cassandra column will use the db_field specified.
@test_category data_types:udt'

def test_db_field_override(self):

    class db_field_different(UserType, ):
        age = columns.Integer(db_field='a')
        name = columns.Text(db_field='n')
    class TheModel(Model, ):
        id = columns.Integer(primary_key=True)
        info = columns.UserDefinedType(db_field_different)
    sync_table(TheModel)
    self.addCleanup(drop_table, TheModel)
    cluster = connection.get_cluster()
    type_meta = cluster.metadata.keyspaces[TheModel._get_keyspace()].user_types[db_field_different.type_name()]
    type_fields = (db_field_different.age.column, db_field_different.name.column)
    self.assertEqual(len(type_meta.field_names), len(type_fields))
    for f in type_fields:
        self.assertIn(f.db_field_name, type_meta.field_names)
    id = 0
    age = 42
    name = 'John'
    info = db_field_different(age=age, name=name)
    TheModel.create(id=id, info=info)
    self.assertEqual(1, TheModel.objects.count())
    john = TheModel.objects.first()
    self.assertEqual(john.id, id)
    info = john.info
    self.assertIsInstance(info, db_field_different)
    self.assertEqual(info.age, age)
    self.assertEqual(info.name, name)
    self.assertEqual(info.a, age)
    self.assertEqual(info.n, name)
