예제 #1
0
def test_make_model_foreign_column(complex_type, custom_type_two,
                                   foreign_field):
    """
    Tests whether make_model can generate models with foreign key fields.
    """
    complex_type.enabled = 1
    complex_type.save()
    custom_type_two.enabled = 1
    model = make_model(custom_type_two)
    columns = Fields.select().where(Fields.type == custom_type_two.id,
                                    Fields.field_type == complex_type.name)
    for column in columns:
        field_object = getattr(model, column.name)
        assert isinstance(field_object, ForeignKeyField)
예제 #2
0
def test_make_model_columns(complex_type, complex_fields):
    """
    Verifies that make_model can correctly generate a model.
    """
    complex_type.enabled = 1
    model = make_model(complex_type)
    fields_dict = {
        'string': TextField,
        'int': IntegerField,
        'float': FloatField,
        'bool': BooleanField,
        'date': DateTimeField
    }
    columns = Fields.select().where(Fields.type == complex_type.id)
    for column in columns:
        field = fields_dict[column.field_type]
        field_object = getattr(model, column.name)
        assert isinstance(field_object, field)

        if column.unique:
            assert getattr(field_object, 'unique') == True

        if column.nullable:
            assert getattr(field_object, 'null') == True