示例#1
0
def test_license_override():
    null_license_url = Image(identifier="ab80dbe1-414c-4ee8-9543-f9599312aeb8",
                             title="test",
                             creator="test",
                             license="by",
                             license_version="3.0",
                             meta_data={'license_url': 'null'})
    assert null_license_url.license_url is not None
def test_attribution():
    """
    The API includes an attribution string. Since there are some works where
    the title or creator is not known, the format of the attribution string
    can need to be tweaked slightly.
    """
    title_and_creator_missing = Image(
        identifier="ab80dbe1-414c-4ee8-9543-f9599312aeb8",
        title=None,
        creator=None,
        license="by",
        license_version="3.0")
    print('\nAttribution examples:\n')
    print(title_and_creator_missing.attribution)
    assert "This work" in title_and_creator_missing.attribution

    title = "A foo walks into a bar"
    creator_missing = Image(identifier="ab80dbe1-414c-4ee8-9543-f9599312aeb8",
                            title=title,
                            creator=None,
                            license="by",
                            license_version="3.0")
    print(creator_missing.attribution)
    assert title in creator_missing.attribution
    assert "by " not in creator_missing.attribution

    creator = "John Doe"
    title_missing = Image(identifier="ab80dbe1-414c-4ee8-9543-f9599312aeb8",
                          title=None,
                          creator=creator,
                          license="by",
                          license_version="3.0")
    print(title_missing.attribution)
    assert creator in title_missing.attribution
    assert "This work" in title_missing.attribution

    all_data_present = Image(identifier="ab80dbe1-414c-4ee8-9543-f9599312aeb8",
                             title=title,
                             creator=creator,
                             license="by",
                             license_version="3.0")
    print(all_data_present.attribution)
    assert title in all_data_present.attribution
    assert creator in all_data_present.attribution