Skip to content

test_spatial#

test_create_spatial_without_url#

Should return Validation error.

Source code in tests/unit/apps/core/adapters/test_spatial.py
def test_create_spatial_without_url():
    """Should return Validation error."""
    with pytest.raises(serializers.ValidationError) as error:
        ser = SpatialModelSerializer(data={})
        ser.is_valid(raise_exception=True)
        ser.save()
    assert "At least one of fields" in str(error.value) and "is required" in str(error.value)

test_create__with_non_existing_url#

Should throw an validation error.

Source code in tests/unit/apps/core/adapters/test_spatial.py
@pytest.mark.django_db
def test_create__with_non_existing_url(location_reference_data):
    """Should throw an validation error."""
    with pytest.raises(serializers.ValidationError) as error:
        ser = SpatialModelSerializer(data={"reference": {"url": "https://test.com"}})
        ser.is_valid(raise_exception=True)
        ser.save()
    assert "Location entry not found for url" in str(error.value)

test_create_dataset_license_with_existing_url#

Should create a Spatial.

Source code in tests/unit/apps/core/adapters/test_spatial.py
@pytest.mark.django_db
def test_create_dataset_license_with_existing_url(location_reference_data):
    """Should create a Spatial."""
    ser = SpatialModelSerializer(
        data={"reference": {"url": "http://www.yso.fi/onto/onto/yso/c_9908ce39"}}
    )
    ser.is_valid(raise_exception=True)
    spatial = ser.save()
    assert spatial is not None

test_update_spatial_with_invalid_url#

Should throw a validation error.

Source code in tests/unit/apps/core/adapters/test_spatial.py
@pytest.mark.django_db
def test_update_spatial_with_invalid_url(location_reference_data):
    """Should throw a validation error."""
    with pytest.raises(serializers.ValidationError) as error:
        ser = SpatialModelSerializer(
            data={"reference": {"url": "http://www.yso.fi/onto/onto/yso/c_9908ce39"}}
        )
        ser.is_valid(raise_exception=True)
        spatial = ser.save()
        ser = SpatialModelSerializer(
            instance=spatial, data={"reference": {"url": "https://diipadaapa.com"}}
        )
        ser.is_valid(raise_exception=True)
        spatial = ser.save()
    assert "Location entry not found for url " in str(error.value)

test_update_spatial#

Should update spatial.

Source code in tests/unit/apps/core/adapters/test_spatial.py
@pytest.mark.django_db
def test_update_spatial(location_reference_data):
    """Should update spatial."""
    ser = SpatialModelSerializer(
        data={"reference": {"url": "http://www.yso.fi/onto/onto/yso/c_9908ce39"}}
    )
    ser.is_valid(raise_exception=True)
    spatial = ser.save()
    ser = SpatialModelSerializer(
        instance=spatial, data={"reference": {"url": "http://www.yso.fi/onto/yso/p105080"}}
    )
    ser.is_valid(raise_exception=True)
    updated = ser.save()
    assert updated.reference.url == "http://www.yso.fi/onto/yso/p105080"