Skip to content

Commit

Permalink
Add more result error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MCPN committed Oct 13, 2023
1 parent 3fb76a7 commit 00675bb
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from dl_api_client.dsmaker.primitives import ResultField
from dl_api_lib_tests.db.base import DefaultApiTestBase
from dl_constants.enums import CalcMode
from dl_constants.enums import (
AggregationFunction,
CalcMode,
)


class TestResultErrors(DefaultApiTestBase):
Expand All @@ -22,3 +25,52 @@ def test_calcmode_formula_without_formula_field(self, saved_dataset, data_api):
result_resp = data_api.get_result(dataset=ds, fields=[ds.find_field(title)], fail_ok=True)
assert result_resp.status_code == 400
assert result_resp.bi_status_code == "ERR.DS_API.FORMULA.PARSE.UNEXPECTED_EOF.EMPTY_FORMULA"

def test_filter_errors(self, saved_dataset, data_api):
ds = saved_dataset
ds.result_schema["New date"] = ds.field(formula="DATE(NOW())") # just a date field
ds.result_schema["New bool"] = ds.field(formula='"P" = "NP"') # just a bool field

# invalid value for date
result_resp = data_api.get_result(
dataset=ds,
fields=[ds.find_field(title="New date")],
filters=[ds.find_field(title="New date").filter("EQ", values=["Office Supplies"])],
fail_ok=True,
)
assert result_resp.status_code == 400
assert result_resp.bi_status_code == "ERR.DS_API.FILTER.INVALID_VALUE"

# a very special check for invalid bool values
result_resp = data_api.get_result(
dataset=ds,
fields=[ds.find_field(title="New date")],
filters=[ds.result_schema["New bool"].filter("EQ", values=[""])],
fail_ok=True,
)
assert result_resp.status_code == 400
assert result_resp.bi_status_code == "ERR.DS_API.FILTER.INVALID_VALUE"

# unknown field
result_resp = data_api.get_result(
dataset=ds,
fields=[ds.find_field(title="New date")],
filters=[ds.field(title="Made-up field").filter("EQ", values=["whatever"])],
fail_ok=True,
)
assert result_resp.status_code == 400
assert result_resp.bi_status_code == "ERR.DS_API.FIELD.NOT_FOUND"

def test_invalid_group_by_configuration(self, saved_dataset, data_api):
ds = saved_dataset
ds.result_schema["Measure"] = ds.field(title="Measure", aggregation=AggregationFunction.sum)

result_resp = data_api.get_result(
dataset=saved_dataset,
fields=[ds.find_field(title="Measure")],
disable_group_by=True,
fail_ok=True,
)
assert result_resp.status_code == 400
assert result_resp.bi_status_code == "ERR.DS_API.INVALID_GROUP_BY_CONFIGURATION"
assert result_resp.json["message"] == "Invalid parameter disable_group_by for dataset with measure fields"

0 comments on commit 00675bb

Please sign in to comment.