def test_reference_property_specific_type():
    ref_prop = ReferenceProperty(valid_types="my-type", spec_version="2.1")

    with pytest.raises(ValueError):
        ref_prop.clean("not-my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf")

    assert ref_prop.clean("my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf") == \
        "my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf"
def test_reference_property():
    ref_prop = ReferenceProperty(valid_types="my-type", spec_version="2.1")

    assert ref_prop.clean("my-type--00000000-0000-4000-8000-000000000000")
    with pytest.raises(ValueError):
        ref_prop.clean("foo")

    # This is not a valid RFC 4122 UUID
    with pytest.raises(ValueError):
        ref_prop.clean("my-type--00000000-0000-0000-0000-000000000000")
Пример #3
0
def test_reference_property():
    ref_prop = ReferenceProperty()

    assert ref_prop.clean("my-type--00000000-0000-4000-8000-000000000000")
    with pytest.raises(ValueError):
        ref_prop.clean("foo")

    # This is not a valid V4 UUID
    with pytest.raises(ValueError):
        ref_prop.clean("my-type--00000000-0000-0000-0000-000000000000")
def test_reference_property_blacklist_standard_type():
    ref_prop = ReferenceProperty(invalid_types="identity", spec_version="2.1")
    result = ref_prop.clean(
        "location--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
    )
    assert result == ("location--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean(
        "location--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
    )
    assert result == ("location--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(CustomContentError):
        ref_prop.clean(
            "some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
        )

    result = ref_prop.clean(
        "some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
    )
    assert result == ("some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        ref_prop.clean(
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
        )

    with pytest.raises(ValueError):
        ref_prop.clean(
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
        )
def test_reference_property_whitelist_standard_type():
    ref_prop = ReferenceProperty(valid_types="identity", spec_version="2.1")
    result = ref_prop.clean(
        "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
    )
    assert result == ("identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        ref_prop.clean("foo--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        ref_prop.clean("foo--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)
def test_reference_property_blacklist_custom_type():
    ref_prop = ReferenceProperty(invalid_types="my-type", spec_version="2.1")

    result = ref_prop.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        ref_prop.clean("my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        ref_prop.clean("my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(CustomContentError):
        # This is not the blacklisted type, but it's still custom, and
        # customization is disallowed here.
        ref_prop.clean("not-my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean("not-my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("not-my-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
Пример #7
0
def test_reference_property():
    ref_prop = ReferenceProperty()

    assert ref_prop.clean("my-type--00000000-0000-4000-8000-000000000000")

    value = "my-type--00000000-0000-0000-0000-000000000000"
    assert ref_prop.clean(value) == value

    with pytest.raises(ValueError):
        ref_prop.clean("foo")

    # This is not a valid UUID
    with pytest.raises(ValueError):
        ref_prop.clean("my-type--1234-56789")
Пример #8
0
def test_reference_property_whitelist_hybrid_type():
    p = ReferenceProperty(valid_types=["a", "SCO"], spec_version="2.0")

    result = p.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = p.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(CustomContentError):
        # although whitelisted, "a" is a custom type
        p.clean("a--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = p.clean("a--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("a--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        p.clean("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    # should just assume "b" is a custom SCO type.
    result = p.clean("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
Пример #9
0
def test_reference_property():
    ref_prop = ReferenceProperty()

    assert ref_prop.clean("my-type--3a331bfe-0566-55e1-a4a0-9a2cd355a300")
    with pytest.raises(ValueError):
        ref_prop.clean("foo")
Пример #10
0
def test_reference_property_blacklist_hybrid_type():
    p = ReferenceProperty(invalid_types=["a", "SCO"], spec_version="2.0")

    with pytest.raises(ValueError):
        p.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        p.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        p.clean("a--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        p.clean("a--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(CustomContentError):
        p.clean("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    # should just assume "b" is a custom type which is not an SCO
    result = p.clean("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("b--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
Пример #11
0
def test_reference_property_blacklist_generic_type():
    ref_prop = ReferenceProperty(
        invalid_types=["SDO", "SRO"],
        spec_version="2.0",
    )

    result = ref_prop.clean(
        "file--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        False,
    )
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean(
        "file--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        True,
    )
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(CustomContentError):
        ref_prop.clean(
            "some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
            False,
        )

    result = ref_prop.clean(
        "some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        True,
    )
    assert result == ("some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        ref_prop.clean(
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
            False,
        )

    with pytest.raises(ValueError):
        ref_prop.clean(
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
            True,
        )

    with pytest.raises(ValueError):
        ref_prop.clean(
            "relationship--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
            False,
        )

    with pytest.raises(ValueError):
        ref_prop.clean(
            "relationship--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
            True,
        )
Пример #12
0
def test_reference_property_whitelist_generic_type():
    ref_prop = ReferenceProperty(
        valid_types=["SCO", "SRO"],
        spec_version="2.0",
    )

    result = ref_prop.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
                            False)
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)
    assert result == ("file--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean(
        "sighting--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        False,
    )
    assert result == ("sighting--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    result = ref_prop.clean(
        "sighting--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        True,
    )
    assert result == ("sighting--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    # The prop assumes some-type is a custom type of one of the generic
    # type categories.
    result = ref_prop.clean(
        "some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
        True,
    )
    assert result == ("some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)

    with pytest.raises(ValueError):
        ref_prop.clean("some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf",
                       False)

    with pytest.raises(ValueError):
        ref_prop.clean("identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False)

    with pytest.raises(ValueError):
        ref_prop.clean("identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True)