Пример #1
0
def check_metadata(p, interactive=False):
    data = jsonf.load(p)
    errors = validator.validate(data)
    if not errors:
        return
    if errors and not interactive:
        raise ValueError(errors)
    for k, v in errors.items():
        cn.pverr(cn.color.red(k), v.args[0])
    ask_edit(p, errors)
    check_metadata(p, interactive)
Пример #2
0
def process_meta(meta):
    failed = validator.validate(meta, broadcast=True)
    failed.pop('broadcast', None)  # TODO: remove this after until v0.3
    if failed:
        keys = ', '.join(failed.keys())
        msg = "Metadata validation failed for keys: {0}".format(keys)
        raise MetadataError(msg, failed)

    replace_aliases(meta)
    add_missing_keys(meta)
    clean_keys(meta)
    return meta
def process_meta(meta):
    # attempt bringing metadata up to latest specification before passing it to
    # the validator
    upgrade_meta(meta)
    failed = validator.validate(meta, broadcast=True)
    if failed:
        keys = ', '.join(failed.keys())
        msg = "Metadata validation failed for keys: {0}".format(keys)
        raise MetadataError(msg, failed)
    replace_aliases(meta)
    add_missing_keys(meta)
    clean_keys(meta)
    parse_datetime(meta)
    return meta
def add_to_servers(cid, servers):
    """ Add content with given cid to the server """
    cdir = path.contentdir(cid)
    ipath = path.infopath(cdir)
    # We only let content that has been fully updated to be added
    if git.has_changes(cdir):
        raise RuntimeError('content has pending changes, please update first')
    # We let the exception from validation propagate up to the caller, and
    # caller is expected to handle this.
    if validator.validate(jsonf.load(ipath)):
        raise RuntimeError('content contains invalid metadata')
    for s in servers:
        target = path.contentdir(cid, server=s)
        if not os.path.islink(target):
            os.symlink(cdir, target)
            git.commit_add_to_server(target, s)
        # We add this to backlog regardless of whether a new symlink is crated.
        # We assume that user wishes to update the content even if symlink
        # already exists.
        backlog.cadd(cid, s)
def test_broadcast_flag():
    data = BASE_METADATA.copy()
    data['broadcast'] = '$BROADCAST'
    with pytest.raises(ValueError):
        mod.validate(data, broadcast=True)
def test_validation(data):
    assert mod.validate(data) == {}
Пример #7
0
def test_broadcast_flag():
    data = BASE_METADATA.copy()
    data['broadcast'] = '$BROADCAST'
    with pytest.raises(ValueError):
        mod.validate(data, broadcast=True)
Пример #8
0
def test_validation(data):
    assert mod.validate(data) == {}