Skip to content

Commit

Permalink
Handle Save Error
Browse files Browse the repository at this point in the history
  • Loading branch information
jlubken committed Feb 9, 2022
1 parent 54467c6 commit 22cda26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/dsdk/flowsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
status: bool,
description: Optional[str] = None,
name: Optional[str] = None,
status_code: Optional[str] = None,
status_code: Optional[int] = None,
text: Optional[str] = None,
):
"""__init__."""
Expand Down Expand Up @@ -236,6 +236,15 @@ def rest(
name=type(e).__name__,
text=str(e),
)
except SaveError as e:
logger.error(self.HTTP_ERROR, missing["id"])
return Result(
duration=interval,
status=False,
description="DATA_NOT_SAVED",
name=type(e).__name__,
status_code=400,
)
except HTTPError as e:
logger.error(self.HTTP_ERROR, missing["id"])
return Result(
Expand Down
23 changes: 14 additions & 9 deletions test/test_flowsheets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Test flowsheets."""

from inspect import unwrap

from pandas import DataFrame
from vcr import VCR

Expand Down Expand Up @@ -96,12 +98,20 @@ def test_invalid_empi(mock_flowsheets_service):
assert result.status is False
assert result.status_code == 400
assert result.name == "HTTPError"


@vcr.use_cassette("./test/flowsheets.data.not.saved.yaml")
def test_invalid_empi(mock_flowsheets_service):
def test_data_not_saved(mock_flowsheets_service):
"""Test data not saved."""
service = mock_flowsheets_service
flowsheets = service.flowsheets

inner = unwrap(flowsheets.on_rest)

def outer(*args, **kwargs):
return inner(flowsheets, *args, **kwargs)

service.flowsheets.on_rest = outer

postgres = service.postgres
postgres.df_from_query.return_value = DataFrame(
Expand All @@ -116,14 +126,9 @@ def test_invalid_empi(mock_flowsheets_service):
}
]
)
expected = (
"An error occurred while executing the command: "
"DATA_NOT_SAVED details : There was an error "
"filing data. Data was not saved.."
)

for result in service.publish():
assert result.description == expected
assert result.description == "DATA_NOT_SAVED"
assert result.status is False
assert result.status_code == 400
assert result.name == "SaveError"

0 comments on commit 22cda26

Please sign in to comment.