Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 504 prevent silently rounding off latitude and longitude values…
… on asset page (#522) Consistent CLI/UI support for asset lat/lng positions up to 7 decimal places (previously the UI rounded to 4 decimal places, whereas the CLI allowed more than 4). * Do not round latitude/longitude values in AssetForm Signed-off-by: F.N. Claessen <felix@seita.nl> * Implement validated longitude and longitude fields that round to 7 decimal places Signed-off-by: F.N. Claessen <felix@seita.nl> * Use latitude and longitude fields in CLI Signed-off-by: F.N. Claessen <felix@seita.nl> * Raise rather than round Signed-off-by: F.N. Claessen <felix@seita.nl> * Use latitude and longitude fields in API Signed-off-by: F.N. Claessen <felix@seita.nl> * Extend rather than append list of error messages returns from internal API Signed-off-by: F.N. Claessen <felix@seita.nl> * black Signed-off-by: F.N. Claessen <felix@seita.nl> * flake8 Signed-off-by: F.N. Claessen <felix@seita.nl> * Fix tests Signed-off-by: F.N. Claessen <felix@seita.nl> * changelog entry Signed-off-by: F.N. Claessen <felix@seita.nl> Signed-off-by: F.N. Claessen <felix@seita.nl>
- Loading branch information
Showing
8 changed files
with
193 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .assets import LatitudeField, LongitudeField # noqa F401 | ||
from .generic_assets import GenericAssetIdField as AssetIdField # noqa F401 | ||
from .sensors import SensorIdField # noqa F401 | ||
from .times import AwareDateTimeField, DurationField # noqa F401 |
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
84 changes: 84 additions & 0 deletions
84
flexmeasures/data/schemas/tests/test_latitude_longitude.py
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,84 @@ | ||
import pytest | ||
|
||
from flexmeasures.data.schemas.assets import LatitudeField, LongitudeField | ||
from flexmeasures.data.schemas.utils import ValidationError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input", "exp_deserialization"), | ||
[ | ||
(0, 0), | ||
(0.1234567, 0.1234567), | ||
(-90, -90), | ||
(90, 90), | ||
], | ||
) | ||
def test_latitude(input, exp_deserialization): | ||
"""Testing straightforward cases""" | ||
lf = LatitudeField() | ||
deser = lf.deserialize(input, None, None) | ||
assert deser == exp_deserialization | ||
assert lf.serialize("duration", {"duration": deser}) == round(input, 7) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input", "error_messages"), | ||
[ | ||
("ninety", ["Not a valid number."]), | ||
(90.01, ["Latitude 90.01 exceeds the maximum latitude of 90 degrees."]), | ||
(0.12345678, ["Latitudes and longitudes are limited to 7 decimal places."]), | ||
( | ||
-90.00000001, | ||
[ | ||
"Latitude -90.00000001 exceeds the minimum latitude of -90 degrees.", | ||
"Latitudes and longitudes are limited to 7 decimal places.", | ||
], | ||
), | ||
], | ||
) | ||
def test_latitude_field_invalid(input, error_messages): | ||
lf = LatitudeField() | ||
with pytest.raises(ValidationError) as ve: | ||
lf.deserialize(input, None, None) | ||
assert error_messages == ve.value.messages | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input", "exp_deserialization"), | ||
[ | ||
(0, 0), | ||
(0.1234567, 0.1234567), | ||
(-180, -180), | ||
(180, 180), | ||
], | ||
) | ||
def test_longitude(input, exp_deserialization): | ||
"""Testing straightforward cases""" | ||
lf = LongitudeField() | ||
deser = lf.deserialize(input, None, None) | ||
assert deser == exp_deserialization | ||
assert lf.serialize("duration", {"duration": deser}) == round(input, 7) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input", "error_messages"), | ||
[ | ||
("one-hundred-and-eighty", ["Not a valid number."]), | ||
( | ||
-180.01, | ||
["Longitude -180.01 exceeds the minimum longitude of -180 degrees."], | ||
), | ||
( | ||
-180.00000001, | ||
[ | ||
"Longitude -180.00000001 exceeds the minimum longitude of -180 degrees.", | ||
"Latitudes and longitudes are limited to 7 decimal places.", | ||
], | ||
), | ||
], | ||
) | ||
def test_longitude_field_invalid(input, error_messages): | ||
lf = LongitudeField() | ||
with pytest.raises(ValidationError) as ve: | ||
lf.deserialize(input, None, None) | ||
assert error_messages == ve.value.messages |
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