-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pablo Panero
committed
Oct 26, 2020
1 parent
b049941
commit 02ea234
Showing
10 changed files
with
191 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2020 CERN. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Test location schema.""" | ||
|
||
import pytest | ||
from marshmallow import ValidationError | ||
|
||
from invenio_rdm_records.services.schemas.metadata import LocationSchema | ||
|
||
|
||
def test_valid_full(): | ||
valid_full = { | ||
"geometry": { | ||
"type": "point", | ||
"coordinates": [-32.94682, -60.63932] | ||
}, | ||
"place": "test location place", | ||
"identifiers": { | ||
"wikidata": "12345abcde", | ||
"geonames": "12345abcde", | ||
}, | ||
"description": "test location description" | ||
} | ||
assert valid_full == LocationSchema().load(valid_full) | ||
|
||
|
||
def test_valid_minimal(): | ||
valid_minimal = { | ||
"geometry": { | ||
"type": "multipoint", | ||
"coordinates": [ | ||
[-32.94682, -60.63932], [-32.94682, -60.63932, 10.0] | ||
] | ||
}, | ||
"place": "test location place" | ||
|
||
} | ||
assert valid_minimal == LocationSchema().load(valid_minimal) | ||
|
||
|
||
def test_invalid_geometry_type(): | ||
invalid_location = { | ||
"geometry": { | ||
"type": "invalid", | ||
"coordinates": [-32.94682, -60.63932] | ||
}, | ||
"place": "test location place", | ||
"identifiers": { | ||
"wikidata": "12345abcde", | ||
"geonames": "12345abcde", | ||
}, | ||
"description": "test location description" | ||
} | ||
with pytest.raises(ValidationError): | ||
data = LocationSchema().load(invalid_location) | ||
|
||
|
||
def test_invalid_wrong_geometry_type(): | ||
invalid_location = { | ||
"geometry": { | ||
"type": "multipoint", | ||
"coordinates": [-32.94682, -60.63932] # This is a point | ||
}, | ||
"place": "test location place", | ||
"identifiers": { | ||
"wikidata": "12345abcde", | ||
"geonames": "12345abcde", | ||
}, | ||
"description": "test location description" | ||
} | ||
with pytest.raises(ValidationError): | ||
data = LocationSchema().load(invalid_location) | ||
|
||
|
||
def test_invalid_no_geometry(): | ||
invalid_location = { | ||
"place": "test location place", | ||
"identifiers": { | ||
"wikidata": "12345abcde", | ||
"geonames": "12345abcde", | ||
}, | ||
"description": "test location description" | ||
} | ||
with pytest.raises(ValidationError): | ||
data = LocationSchema().load(invalid_location) | ||
|
||
|
||
def test_invalid_no_place(): | ||
invalid_location = { | ||
"geometry": { | ||
"type": "multipoint", | ||
"coordinates": [ | ||
[-32.94682, -60.63932], [-32.94682, -60.63932, 10.0] | ||
] | ||
}, | ||
"identifiers": { | ||
"wikidata": "12345abcde", | ||
"geonames": "12345abcde", | ||
}, | ||
"description": "test location description" | ||
} | ||
with pytest.raises(ValidationError): | ||
data = LocationSchema().load(invalid_location) |
Oops, something went wrong.