示例#1
0
def test_identifier_not_required():
    """When the provided schema is allowed but different format."""
    valid_identifier = {}

    schema = IdentifierSchema(allowed_schemes=["orcid"], required=False)
    loaded = schema.load(valid_identifier)
    assert valid_identifier == loaded == schema.dump(loaded)

    # Scheme is ignored since there is no identifier value
    valid_identifier = {"scheme": "isni"}

    loaded = schema.load(valid_identifier)
    assert valid_identifier == loaded == schema.dump(loaded)
def test_scheme_and_identifier_no_match_should_pass():
    wrong_scheme = {"identifier": "0000-0001-6759-6273", "scheme": "isbn"}

    schema = IdentifierSchema()
    data = schema.load(wrong_scheme)

    correct_scheme = {"scheme": "orcid"}
    correct_scheme.update(wrong_scheme)
    assert correct_scheme == data == schema.dump(data)
def test_valid_scheme_identifier_other_forbidden_should_pass():
    valid_scheme_identifier = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "orcid",
    }

    schema = IdentifierSchema(forbidden_schemes=["isbn"])
    data = schema.load(valid_scheme_identifier)
    assert valid_scheme_identifier == data == schema.dump(data)
def test_valid_scheme_identifier_allowed_should_pass():
    valid_scheme_identifier = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "orcid",
    }

    schema = IdentifierSchema(allowed_schemes=["orcid"])
    data = schema.load(valid_scheme_identifier)
    assert valid_scheme_identifier == data == schema.dump(data)
示例#5
0
def test_identifier_auto_scheme():
    valid_identifier = {
        "identifier": "0000-0001-6759-6273",
    }

    schema = IdentifierSchema(allowed_schemes=["orcid"])
    loaded = schema.load(valid_identifier)
    # NOTE: Since the schemas return the dict itself, the loaded object
    # is the same than the input and dumped objects (dicts)
    valid_identifier["scheme"] == "orcid"
    assert valid_identifier == loaded == schema.dump(loaded)
示例#6
0
def test_full_identifier():
    valid_full = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "orcid"
    }

    schema = IdentifierSchema(allowed_schemes=["orcid", "ror"])
    loaded = schema.load(valid_full)
    # NOTE: Since the schemas return the dict itself, the loaded object
    # is the same than the input and dumped objects (dicts)
    assert valid_full == loaded == schema.dump(loaded)
示例#7
0
def test_autoschema_allow_all_provided():
    valid_identifier = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "isni"
    }

    schema = IdentifierSchema(allow_all=True)
    loaded = schema.load(valid_identifier)
    # NOTE: Since the schemas return the dict itself, the loaded object
    # is the same than the input and dumped objects (dicts)
    assert valid_identifier == loaded == schema.dump(loaded)
def test_only_identifier_should_pass():
    only_identifier = {
        "identifier": "0000-0001-6759-6273",
    }

    schema = IdentifierSchema()
    data = schema.load(only_identifier)

    with_scheme = {"scheme": "orcid"}
    with_scheme.update(only_identifier)
    assert with_scheme == data == schema.dump(data)
def test_scheme_and_identifier_match_should_pass():
    valid_scheme_identifier = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "orcid",
    }

    schema = IdentifierSchema()
    data = schema.load(valid_scheme_identifier)
    # NOTE: Since the schemas return the dict itself, the loaded object
    # is the same than the input and dumped objects (dicts)
    assert valid_scheme_identifier == data == schema.dump(data)
def test_invalid_scheme_detected_identifier_allowed_should_pass():
    invalid_scheme_identifier = {
        "identifier": "0000-0001-6759-6273",
        "scheme": "bar",
    }

    schema = IdentifierSchema(allowed_schemes=["isbn", "orcid"])
    data = schema.load(invalid_scheme_identifier)

    with_scheme = {"scheme": "orcid"}
    with_scheme.update(invalid_scheme_identifier)
    assert with_scheme == data == schema.dump(data)
def test_allow_unknown_should_pass():
    valid_scheme_identifier = {"identifier": "foo", "scheme": "bar"}

    schema = IdentifierSchema(fail_on_unknown=False)
    data = schema.load(valid_scheme_identifier)
    assert valid_scheme_identifier == data == schema.dump(data)