Skip to content
Snippets Groups Projects
Verified Commit 469b8215 authored by David Hoese's avatar David Hoese
Browse files

Add more tests for error conditions in data API

parent c6632db2
No related branches found
No related tags found
No related merge requests found
...@@ -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 site, 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[(site, 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}
......
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment