-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve user experience for our upcoming postSensorData API endpoint by not needing to make a list out of a single item. * Create draft PR for #145 * endpoint receives data and makes a BeliefsDataFrame * save beliefs, first test running * validation and upsampling in schema * changelog entry * test with upsampling, fix test data freshness * more tests * get test with non-existant sensor to work * test sending in the wrong unit * move unit check to SensorDataDescriptionSchema and comment on future work * move BeliefsDataFrame creation to Schema * clarity about type field, simpler date_range creation * some endpoint documentation * add some tests as Felix requested * save beliefs with api_utils.save_to_db, test sending data multiple times * add optional horizon field * Reverse if-else statement * Add placeholder for ownership check * Allow posting a single event value as a float rather than as a list of floats * Add dependency * PR fixes * Add some form of version management to dependencies installed by our Makefile Co-authored-by: nhoening <nhoening@users.noreply.github.com> Co-authored-by: Nicolas Höning <nicolas@seita.nl> Co-authored-by: Nicolas Höning <iam@nicolashoening.de>
- Loading branch information
1 parent
3f709df
commit 43dbe80
Showing
9 changed files
with
188 additions
and
48 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
82 changes: 82 additions & 0 deletions
82
flexmeasures/api/common/schemas/tests/test_sensor_data_schema.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,82 @@ | ||
import pytest | ||
|
||
from marshmallow import ValidationError | ||
|
||
from flexmeasures.api.common.schemas.sensor_data import ( | ||
SingleValueField, | ||
SensorDataSchema, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"deserialization_input, exp_deserialization_output", | ||
[ | ||
( | ||
1, | ||
[1], | ||
), | ||
( | ||
2.7, | ||
[2.7], | ||
), | ||
( | ||
[1], | ||
[1], | ||
), | ||
( | ||
[2.7], | ||
[2.7], | ||
), | ||
], | ||
) | ||
def test_value_field_deserialization( | ||
deserialization_input, | ||
exp_deserialization_output, | ||
): | ||
"""Testing straightforward cases""" | ||
vf = SensorDataSchema.values | ||
deser = vf.deserialize(deserialization_input) | ||
assert deser == exp_deserialization_output | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"serialization_input, exp_serialization_output", | ||
[ | ||
( | ||
1, | ||
[1], | ||
), | ||
( | ||
2.7, | ||
[2.7], | ||
), | ||
], | ||
) | ||
def test_value_field_serialization( | ||
serialization_input, | ||
exp_serialization_output, | ||
): | ||
"""Testing straightforward cases""" | ||
vf = SingleValueField() | ||
ser = vf.serialize("values", {"values": serialization_input}) | ||
assert ser == exp_serialization_output | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"deserialization_input, error_msg", | ||
[ | ||
( | ||
["three", 4], | ||
"Not a valid number", | ||
), | ||
( | ||
"3, 4", | ||
"Not a valid number", | ||
), | ||
], | ||
) | ||
def test_value_field_invalid(deserialization_input, error_msg): | ||
sf = SingleValueField() | ||
with pytest.raises(ValidationError) as ve: | ||
sf.deserialize(deserialization_input) | ||
assert error_msg in str(ve) |
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
Oops, something went wrong.