Exemplo n.º 1
0
def test_field_allowUpload():
    ''' properties must be dict'''
    preset = {"id": "id_test", "properties": [], "allow_upload": True}
    p = Preset(preset)
    eq_(p.allow_upload, preset['allow_upload'])

    preset['allow_upload'] = False
    p = Preset(preset)
    eq_(p.allow_upload, preset['allow_upload'])
Exemplo n.º 2
0
def test_validate_empty():
    ''' preset without empty must validate empty data'''
    preset = {
        "id": "id_test",
        "properties": []
    }
    data = {}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 3
0
def test_validate_string_not_required_missing():
    ''' if string property is not required we can skip it'''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_string",
                          "required": False,
                          "type" : "string" } ]
    }
    data = {}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 4
0
def test_validate_string_not_required():
    ''' if string property are not required we can insert it anyway'''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_string",
                          "required": False,
                          "type" : "string" } ]
    }
    data = { "prop_test_string" : "any_text_I_want" }
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 5
0
def test_validate_enum_not_required_missing():
    ''' if enum property is not required we can skip it'''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_enum",
                          "required": False,
                          "type" : "enum",
                          "values": ['alfa','beta','gamma'] } ]
    }
    data = {}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 6
0
def test_validate_enum_not_required():
    ''' if enum property is not required we can insert it anyway'''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_enum",
                          "required": False,
                          "type" : "enum",
                          "values": ['alfa','beta','gamma'] } ]
    }
    data = { "prop_test_enum": "alfa" }
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 7
0
def test_validate_string_required_missing():
    ''' if property of type string is required
        and we do not provide it, exception must be raised.
    '''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_string",
                          "required": True,
                          "type" : "string" } ]
    }
    data = {}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 8
0
def test_validate_enum_required_wrong():
    ''' if property of type enum is required
        and we provide a wrong value, exception must be raised
    '''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_enum",
                          "required": True,
                          "type" : "enum",
                          "values": ['alfa','beta','gamma'] } ]
    }
    data = {"prop_test_enum": "alsdkasld"}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 9
0
def test_validate_enum_required_missing():
    ''' if property of type enum is required
        and we do not provide it, exception must be raised.
    '''
    preset = {
        "id": "id_test",
        "properties": [ { "id": "prop_test_enum",
                          "required": True,
                          "type" : "enum",
                          "values": ['alfa','beta','gamma'] } ]
    }
    data = {}
    p = Preset(preset)
    p.validate(data)
Exemplo n.º 10
0
def test_properties_defaults():
    preset = {"id": "id_test", "properties": [{"id": "prop_test"}]}
    p = Preset(preset)
    eq_(len(p.properties), 1)
    eq_(p.properties[0].id, preset['properties'][0]['id'])
    eq_(p.properties[0].required, False)
    eq_(p.properties[0].type, "string")
Exemplo n.º 11
0
def test_properties_type_enum_missing_values():
    preset = {
        "id": "id_test",
        "properties": [{
            "id": "prop_test",
            "type": "enum"
        }]
    }
    Preset(preset)
Exemplo n.º 12
0
def test_properties_type_enum_values_type():
    preset = {
        "id": "id_test",
        "properties": [{
            "id": "prop_test",
            "type": "enum",
            "values": "errorrrre"
        }]
    }
    Preset(preset)
Exemplo n.º 13
0
def test_properties_type():
    '''test type value not valid'''
    preset = {
        "id": "id_test",
        "properties": [{
            "id": "prop_test",
            "type": "### non_esiste ###"
        }]
    }
    Preset(preset)
Exemplo n.º 14
0
def test_properties_type_enum_values():
    preset = {
        "id":
        "id_test",
        "properties": [{
            "id": "prop_test",
            "type": "enum",
            "values": ['uno', 'due', 'dieci']
        }]
    }
    p = Preset(preset)
    eq_(len(p.properties), 1)
    eq_(p.properties[0].id, preset['properties'][0]['id'])
    eq_(p.properties[0].type, preset['properties'][0]['type'])
    eq_(p.properties[0].values, preset['properties'][0]['values'])
Exemplo n.º 15
0
def test_properties_num():
    preset = {
        "id": "id_test",
        "properties": [{
            "id": "1_p"
        }, {
            "id": "2_p"
        }, {
            "id": "3_p"
        }]
    }
    p = Preset(preset)
    eq_(len(p.properties), 3)
    for i, prop in enumerate(preset['properties']):
        eq_(prop['id'], p.properties[i].id)
Exemplo n.º 16
0
def test_properties_all():
    preset = {
        "id":
        "id_test",
        "properties": [{
            "id": "prop_test",
            "description": "description test",
            "required": True,
            "type": "string"
        }]
    }
    p = Preset(preset)
    eq_(len(p.properties), 1)
    eq_(p.properties[0].id, preset['properties'][0]['id'])
    eq_(p.properties[0].description, preset['properties'][0]['description'])
    eq_(p.properties[0].required, preset['properties'][0]['required'])
    eq_(p.properties[0].type, preset['properties'][0]['type'])
Exemplo n.º 17
0
def test_field_properties_missing():
    ''' properties is not optional'''
    preset = {"id": "id_test"}
    Preset(preset)
Exemplo n.º 18
0
def test_field_id_empty():
    ''' id is not optional'''
    preset = {"id": "", "properties": []}
    Preset(preset)
Exemplo n.º 19
0
def test_field_id_missing():
    ''' id is not optional'''
    preset = {"properties": []}
    Preset(preset)
Exemplo n.º 20
0
def test_field_allowUpload_default():
    preset = {"id": "id_test", "properties": []}
    p = Preset(preset)
    eq_(p.allow_upload, True)
Exemplo n.º 21
0
def test_field_id_type():
    ''' id must be a string '''
    preset = {"id": {}, "properties": []}
    Preset(preset)
Exemplo n.º 22
0
def test_creation():
    preset = {"id": "id_test", "properties": []}
    p = Preset(preset)
    eq_(p.id, preset['id'])
Exemplo n.º 23
0
def test_field_allowUpload_type():
    ''' allow_upload must be bool'''
    preset = {"id": "id_test", "properties": [], "allow_upload": "test"}
    Preset(preset)
Exemplo n.º 24
0
def test_properties_duplicate_id():
    preset = {"id": "id_test", "properties": [{"id": "1_p"}, {"id": "1_p"}]}
    Preset(preset)
Exemplo n.º 25
0
def test_properties_id_empty():
    preset = {"id": "id_test", "properties": [{"id": ""}]}
    Preset(preset)
Exemplo n.º 26
0
def test_id_empty():
    preset = {"id": "", "properties": []}
    Preset(preset)
Exemplo n.º 27
0
def test_properties_empty():
    preset = {"id": "id_test", "properties": []}
    p = Preset(preset)
    eq_(len(p.properties), 0)
Exemplo n.º 28
0
def test_field_properties_type():
    ''' properties must be dict'''
    preset = {"id": "id_test", "properties": "asd"}
    Preset(preset)