Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more result error tests #19

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading