diff --git a/src/dsdk/flowsheet.py b/src/dsdk/flowsheet.py index 1286ba4..0114f11 100644 --- a/src/dsdk/flowsheet.py +++ b/src/dsdk/flowsheet.py @@ -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__.""" @@ -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( diff --git a/test/test_flowsheets.py b/test/test_flowsheets.py index ac49cb6..8eb5aba 100644 --- a/test/test_flowsheets.py +++ b/test/test_flowsheets.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """Test flowsheets.""" +from inspect import unwrap + from pandas import DataFrame from vcr import VCR @@ -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( @@ -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"