Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
MetObsAPI
Commits
469b8215
Verified
Commit
469b8215
authored
2 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Add more tests for error conditions in data API
parent
c6632db2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metobsapi/data_api.py
+2
-13
2 additions, 13 deletions
metobsapi/data_api.py
metobsapi/tests/test_data_api.py
+30
-0
30 additions, 0 deletions
metobsapi/tests/test_data_api.py
with
32 additions
and
13 deletions
metobsapi/data_api.py
+
2
−
13
View file @
469b8215
...
@@ -29,10 +29,6 @@ ROUNDING = {
...
@@ -29,10 +29,6 @@ ROUNDING = {
}
}
def
round_value
(
value
,
symbol
):
return
np
.
round
(
value
,
ROUNDING
.
get
(
symbol
,
1
))
def
handle_date
(
date
):
def
handle_date
(
date
):
try
:
try
:
date_len
=
len
(
date
)
date_len
=
len
(
date
)
...
@@ -68,7 +64,6 @@ def handle_symbols(symbols: list[str]):
...
@@ -68,7 +64,6 @@ def handle_symbols(symbols: list[str]):
try
:
try
:
site
,
inst
,
s
=
symbol
.
split
(
"
.
"
)
site
,
inst
,
s
=
symbol
.
split
(
"
.
"
)
si
=
(
site
,
inst
)
except
ValueError
:
except
ValueError
:
raise
ValueError
(
"
Symbols must have 3 period-separated parts: {}
"
.
format
(
symbol
))
raise
ValueError
(
"
Symbols must have 3 period-separated parts: {}
"
.
format
(
symbol
))
...
@@ -83,10 +78,10 @@ def handle_symbols(symbols: list[str]):
...
@@ -83,10 +78,10 @@ def handle_symbols(symbols: list[str]):
influx_symbols
.
setdefault
((
site
,
inst
),
[]).
append
(
influx_name
)
influx_symbols
.
setdefault
((
site
,
inst
),
[]).
append
(
influx_name
)
# Add the symbols needed to compute the wind_speed and wind_direction
# Add the symbols needed to compute the wind_speed and wind_direction
for
si
in
add_winds
:
for
si
te
,
inst
in
add_winds
:
influx_to_requested_symbols
[
f
"
{
site
}
.
{
inst
}
.wind_east
"
]
=
None
influx_to_requested_symbols
[
f
"
{
site
}
.
{
inst
}
.wind_east
"
]
=
None
influx_to_requested_symbols
[
f
"
{
site
}
.
{
inst
}
.wind_north
"
]
=
None
influx_to_requested_symbols
[
f
"
{
site
}
.
{
inst
}
.wind_north
"
]
=
None
influx_symbols
[
si
].
extend
((
"
wind_east
"
,
"
wind_north
"
))
influx_symbols
[
(
si
te
,
inst
)
].
extend
((
"
wind_east
"
,
"
wind_north
"
))
return
influx_to_requested_symbols
,
influx_symbols
return
influx_to_requested_symbols
,
influx_symbols
...
@@ -165,12 +160,6 @@ def calc_num_records(begin, end, interval):
...
@@ -165,12 +160,6 @@ def calc_num_records(begin, end, interval):
return
diff
/
data_responses
.
INTERVALS
[
interval
]
return
diff
/
data_responses
.
INTERVALS
[
interval
]
def
calc_file_size
(
num_records
,
num_streams
):
"""
Get number of bytes returned for a text based format.
"""
# estimate about 7 bytes (overhead + data characters) per data point
return
num_records
*
num_streams
*
7.0
def
handle_csv
(
frame
,
epoch
,
sep
=
"
,
"
,
message
=
""
,
code
=
200
,
status
=
"
success
"
,
**
kwargs
):
def
handle_csv
(
frame
,
epoch
,
sep
=
"
,
"
,
message
=
""
,
code
=
200
,
status
=
"
success
"
,
**
kwargs
):
output
=
"""
# status: {status}
output
=
"""
# status: {status}
# code: {code:d}
# code: {code:d}
...
...
This diff is collapsed.
Click to expand it.
metobsapi/tests/test_data_api.py
+
30
−
0
View file @
469b8215
...
@@ -234,6 +234,36 @@ class TestDataAPI:
...
@@ -234,6 +234,36 @@ class TestDataAPI:
assert
res
[
"
status
"
]
==
"
error
"
assert
res
[
"
status
"
]
==
"
error
"
assert
"'
symbols
'"
in
res
[
"
message
"
]
assert
"'
symbols
'"
in
res
[
"
message
"
]
def
test_nonexistent_symbol
(
self
,
client
):
res
=
client
.
get
(
"
/api/data.json?begin=-05:00:00&symbols=aoss.tower.air_temp:aoss.tower.noexist
"
)
res
=
json
.
loads
(
res
.
data
.
decode
())
assert
res
[
"
code
"
]
==
400
assert
res
[
"
status
"
]
==
"
error
"
assert
"
Unknown symbol
"
in
res
[
"
message
"
]
def
test_bad_symbol_site_inst
(
self
,
client
):
res
=
client
.
get
(
"
/api/data.json?begin=-05:00:00&symbols=aoss.tower.something.air_temp
"
)
res
=
json
.
loads
(
res
.
data
.
decode
())
assert
res
[
"
code
"
]
==
400
assert
res
[
"
status
"
]
==
"
error
"
assert
"
3 period-separated parts
"
in
res
[
"
message
"
]
def
test_symbol_unknown_site_inst
(
self
,
client
):
res
=
client
.
get
(
"
/api/data.json?begin=-05:00:00&symbols=aoss2.tower.air_temp
"
)
res
=
json
.
loads
(
res
.
data
.
decode
())
assert
res
[
"
code
"
]
==
400
assert
res
[
"
status
"
]
==
"
error
"
assert
"
Unknown site/instrument
"
in
res
[
"
message
"
]
def
test_multiple_symbol
(
self
,
client
):
res
=
client
.
get
(
"
/api/data.json?begin=-05:00:00&symbols=aoss.tower.air_temp:aoss.tower.wind_speed:aoss.tower.air_temp
"
)
res
=
json
.
loads
(
res
.
data
.
decode
())
assert
res
[
"
code
"
]
==
400
assert
res
[
"
status
"
]
==
"
error
"
assert
"
multiple times
"
in
res
[
"
message
"
]
def
test_too_many_points
(
self
,
client
):
def
test_too_many_points
(
self
,
client
):
res
=
client
.
get
(
"
/api/data.json?symbols=aoss.tower.air_temp&begin=1970-01-01T00:00:00
"
)
res
=
client
.
get
(
"
/api/data.json?symbols=aoss.tower.air_temp&begin=1970-01-01T00:00:00
"
)
assert
res
.
status_code
==
413
assert
res
.
status_code
==
413
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment