Esempio n. 1
0
def test_properties(client, dataset):

    pkg = DataPackage('Some Video', package_type='Video')
    assert not pkg.exists

    dataset.add(pkg)
    assert pkg.exists

    pkg.insert_property('my-key', 'my-value')
    pkg2 = client.get(pkg)
    print 'properties =', pkg2.properties
    assert pkg2.id == pkg.id
    assert pkg2.get_property('my-key').data_type == 'string'
    assert pkg2.get_property('my-key').value == 'my-value'

    explicit_ptypes = {
        'my-int1': ('integer', 123123),
        'my-int2': ('integer', '123123'),
        'my-float': ('double', 123.123),
        'my-float2': ('double', '123.123'),
        'my-float3': ('double', '123123'),
        'my-date': ('date', 1488847449697),
        'my-date2': ('date', 1488847449697.123),
        'my-date3': ('date', datetime.datetime.now()),
        'my-string': ('string', 'my-123123'),
        'my-string2': ('string', '123123'),
        'my-string3': ('string', '123123.123'),
        'my-string4': ('string', 'According to plants, humans are blurry.'),
    }
    for key, (ptype, val) in explicit_ptypes.items():
        pkg.insert_property(key, val, data_type=ptype)
        assert pkg.get_property(key).data_type == ptype

    inferred_ptypes = {
        'my-int1': ('integer', 123123),
        'my-int2': ('integer', '123123'),
        'my-float1': ('double', 123.123),
        'my-float2': ('double', '123.123'),
        'my-date': ('date', datetime.datetime.now()),
        'my-string': ('string', 'i123123'),
        'my-string2': ('string', '#1231'),
    }
    for key, (ptype, val) in inferred_ptypes.items():
        pkg.insert_property(key, val)
        prop = pkg.get_property(key)
        assert prop.data_type == ptype

    # remove property
    pkg.remove_property('my-key')
    with pytest.raises(Exception):
        assert pkg.get_property('my-key')

    pkg2 = client.get(pkg.id)
    with pytest.raises(Exception):
        assert pkg2.get_property('my-key')
Esempio n. 2
0
def test_properties(client, dataset):

    pkg = DataPackage("Some Video", package_type="Video")
    assert not pkg.exists

    dataset.add(pkg)
    assert pkg.exists

    pkg.insert_property("my-key", "my-value")
    pkg2 = client.get(pkg)
    print("properties =", pkg2.properties)
    assert pkg2.id == pkg.id
    assert pkg2.get_property("my-key").data_type == "string"
    assert pkg2.get_property("my-key").value == "my-value"

    explicit_ptypes = {
        "my-int1": ("integer", 123123),
        "my-int2": ("integer", "123123"),
        "my-float": ("double", 123.123),
        "my-float2": ("double", "123.123"),
        "my-float3": ("double", "123123"),
        "my-date": ("date", 1488847449697),
        "my-date2": ("date", 1488847449697.123),
        "my-date3": ("date", datetime.datetime.now()),
        "my-string": ("string", "my-123123"),
        "my-string2": ("string", "123123"),
        "my-string3": ("string", "123123.123"),
        "my-string4": ("string", "According to plants, humans are blurry."),
    }
    for key, (ptype, val) in explicit_ptypes.items():
        pkg.insert_property(key, val, data_type=ptype)
        assert pkg.get_property(key).data_type == ptype

    inferred_ptypes = {
        "my-int1": ("integer", 123123),
        "my-int2": ("integer", "123123"),
        "my-float1": ("double", 123.123),
        "my-float2": ("double", "123.123"),
        "my-date": ("date", datetime.datetime.now()),
        "my-string": ("string", "i123123"),
        "my-string2": ("string", "#1231"),
    }
    for key, (ptype, val) in inferred_ptypes.items():
        pkg.insert_property(key, val)
        prop = pkg.get_property(key)
        assert prop.data_type == ptype

    # remove property
    pkg.remove_property("my-key")
    assert pkg.get_property("my-key") is None

    pkg2 = client.get(pkg.id)
    assert pkg2.get_property("my-key") is None