Skip to content

Commit

Permalink
Update insights response (AOT-Technologies#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
auslin-aot authored Nov 22, 2023
1 parent fa52af3 commit 3f77e6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions forms-flow-api/src/formsflow_api/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class BusinessErrorCode(ErrorCodeMixin, Enum):
"Invalid response received from insights",
HTTPStatus.BAD_REQUEST,
)
INSIGHTS_NOTFOUND = (
"Analytics is not enabled for this tenant",
HTTPStatus.BAD_REQUEST,
)
INVALID_BPM_RESPONSE = "Invalid response received from bpm", HTTPStatus.BAD_REQUEST
BPM_BASE_URL_NOT_SET = "BPM_API_URL not set environment", HTTPStatus.BAD_REQUEST
MISSING_PAGINATION_PARAMETERS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_request(url_path, page_no=None, limit=None, **kwargs):
current_app.logger.debug("Response from analytics %s", response.json())
if response.ok:
return response.json()
if response.status_code == 404:
raise BusinessException(BusinessErrorCode.INSIGHTS_NOTFOUND)
raise BusinessException(BusinessErrorCode.INVALID_INSIGHTS_RESPONSE)
except requests.ConnectionError as e:
raise BusinessException(ExternalError.INSIGHTS_SERVICE_UNAVAILABLE) from e
10 changes: 10 additions & 0 deletions forms-flow-api/tests/unit/api/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ def test_get_dashboard_error_details(app, client, session, jwt):

rv = client.get("/dashboards/10000", headers=headers)
assert rv.json == {"message": "Dashboard - 10000 not accessible"}


def test_get_dashboard_error_details_tenant(app, client, session, jwt):
"""Get dashboards for tenant with analytics not created."""
token = get_token(jwt, tenant_key="test-tenant")
headers = {"Authorization": f"Bearer {token}", "content-type": "application/json"}

rv = client.get("/dashboards", headers=headers)
assert rv.status_code == 400
assert rv.json["message"] == "Analytics is not enabled for this tenant"

0 comments on commit 3f77e6f

Please sign in to comment.