Ejemplo n.º 1
0
 def teardown():
     os.remove(blueprint_file)
     field = Fields.get(Fields.name == 'name')
     field.delete_instance()
     field = Fields.get(Fields.name == 'colour')
     field.delete_instance()
     type = Types.get(Types.name == 'flowers')
     type.delete_instance()
Ejemplo n.º 2
0
def nullable_field(request, complex_data):
    ships = Types.get(Types.name == 'ships')
    sails = Fields(name='sails',
                   type=ships.id,
                   field_type='string',
                   nullable=False)
    sails.save()

    def teardown():
        sails.delete_instance()

    request.addfinalizer(teardown)
Ejemplo n.º 3
0
def simple_data(request, blueprint_file):
    bands = Types(name='bands', enabled=0)
    bands.save()
    name = Fields(name='band_name', type=bands.id, field_type='string')
    name.save()

    def teardown():
        name.delete_instance()
        bands.delete_instance()
        os.remove(blueprint_file)

    request.addfinalizer(teardown)
Ejemplo n.º 4
0
def build_field(request,
                name,
                type_id,
                field_type,
                unique=None,
                nullable=None):
    custom_field = Fields(name=name,
                          type=type_id,
                          field_type=field_type,
                          unique=unique,
                          nullable=nullable)
    custom_field.save()

    def teardown():
        custom_field.delete_instance()

    request.addfinalizer(teardown)
    return custom_field
Ejemplo n.º 5
0
def test_complex_blueprint(complex_blueprint, blueprint_file):
    """
    Tests the loading of blueprint with fields description.
    """
    load_blueprint(blueprint_file)
    type = Types.get(Types.name == 'plants')
    assert type.id > 0

    field = Fields.get(Fields.name == 'weight')
    assert field.field_type == 'int'
    assert field.type.id == type.id

    field = Fields.get(Fields.name == 'age')
    assert field.field_type == 'date'
    assert field.type.id == type.id

    field = Fields.get(Fields.name == 'colour')
    assert field.field_type == 'colours'
    assert field.type.id == type.id
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def test_load_simple_blueprint(simple_blueprint, blueprint_file):
    """
    Tests the loading of a simple blueprint that has only a list of fields.
    """
    load_blueprint(blueprint_file)
    type = Types.get(Types.name == 'flowers')
    assert type.id > 0
    assert type.enabled == True
    fields = ['name', 'colour']
    for field_name in fields:
        field = Fields.get(Fields.name == field_name)
        assert field.field_type == 'string'
        assert field.type.id == type.id
        assert field.nullable == True
Ejemplo n.º 8
0
def test_fields_io():
    """
    Verfies that is possible to create and delete a Fields instance.
    """
    custom_type = Types(name='sometype', enabled=0)
    custom_type.save()
    field = Fields(name='myfield', type=custom_type.id, field_type='string')
    field.save()
    assert getattr(field, 'id') != None
    field.delete_instance()
    custom_type.delete_instance()
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def test_nullable_blueprint(nullable_blueprint, blueprint_file):
    load_blueprint(blueprint_file)
    field = Fields.get(Fields.name == 'children')
    assert field.nullable == True
Ejemplo n.º 11
0
def complex_data(request, blueprint_file):
    builders = Types(name='builders', enabled=0)
    builders.save()
    ships = Types(name='ships', enabled=0)
    ships.save()
    tonnage = Fields(name='tonnage', type=ships.id, field_type='int')
    tonnage.save()
    flag = Fields(name='flag', type=ships.id, field_type='string')
    flag.save()
    launch_date = Fields(name='launch_date', type=ships.id, field_type='date')
    launch_date.save()
    builder = Fields(name='builder', type=ships.id, field_type='builders')
    builder.save()

    def teardown():
        tonnage.delete_instance()
        flag.delete_instance()
        launch_date.delete_instance()
        builder.delete_instance()
        ships.delete_instance()
        builders.delete_instance()
        os.remove(blueprint_file)

    request.addfinalizer(teardown)
Ejemplo n.º 12
0
 def teardown():
     field = Fields.get(Fields.name == 'children')
     field.delete_instance()