SIENTIAPDE-1478
Enhance end-to-end tests for PredictionsBatch workflow scenarios - Introduced mock repositories for PI Web API and OPC operations to improve test coverage. - Updated test scenarios to handle partial write errors for PI Web API and OPC. - Refactored existing tests to assert correct behavior under various error conditions. - Enhanced logging and error handling in API and OPC activities to provide clearer feedback on failures. - Removed outdated integration test file to streamline test suite.
This commit is contained in:
@@ -127,8 +127,6 @@ async def test_write_pi_web_api_data_success(mock_dataframe, api, base_input_dat
|
||||
|
||||
result = await api.write_pi_web_api_data(input_data)
|
||||
|
||||
api.info.assert_called_once_with('Writing data to PI Web API...', metadata['metadata'])
|
||||
|
||||
api.pi_web_api_client.write_value.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
@@ -292,7 +290,7 @@ async def test_process_pi_web_api_response_success(api):
|
||||
'workflow_name': 'test_workflow',
|
||||
}
|
||||
|
||||
confidence = await api.process_pi_web_api_response(
|
||||
confidence, message = await api.process_pi_web_api_response(
|
||||
response_data=response_data,
|
||||
tags=tags,
|
||||
core_labels=core_labels,
|
||||
@@ -300,6 +298,7 @@ async def test_process_pi_web_api_response_success(api):
|
||||
)
|
||||
|
||||
assert confidence == 0
|
||||
assert message == ''
|
||||
assert api.emit_metric.call_count == 2
|
||||
# Verify that emit_metric was called with correct tags structure
|
||||
call_args_list = api.emit_metric.call_args_list
|
||||
@@ -326,7 +325,7 @@ async def test_process_pi_web_api_response_with_errors(api):
|
||||
'workflow_name': 'test_workflow',
|
||||
}
|
||||
|
||||
confidence = await api.process_pi_web_api_response(
|
||||
confidence, message = await api.process_pi_web_api_response(
|
||||
response_data=response_data,
|
||||
tags=tags,
|
||||
core_labels=core_labels,
|
||||
@@ -334,10 +333,9 @@ async def test_process_pi_web_api_response_with_errors(api):
|
||||
)
|
||||
|
||||
assert confidence == PI_WEB_API_PREDICTION_ERROR_CONFIDENCE
|
||||
assert message == "The number of written tags does not match the number of tag names: Expected ['tag1', 'tag2'] tags, but ['tag2'] tags were written."
|
||||
assert api.emit_metric.call_count == 2
|
||||
api.error.assert_any_call(
|
||||
"Error writing tag tag1:web_id_1 to PI Web API: ['Error writing tag']", metadata['metadata']
|
||||
)
|
||||
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@@ -355,7 +353,7 @@ async def test_process_pi_web_api_response_missing_tags(api):
|
||||
'workflow_name': 'test_workflow',
|
||||
}
|
||||
|
||||
confidence = await api.process_pi_web_api_response(
|
||||
confidence, message = await api.process_pi_web_api_response(
|
||||
response_data=response_data,
|
||||
tags=tags,
|
||||
core_labels=core_labels,
|
||||
@@ -363,6 +361,7 @@ async def test_process_pi_web_api_response_missing_tags(api):
|
||||
)
|
||||
|
||||
assert confidence == PI_WEB_API_PREDICTION_ERROR_CONFIDENCE
|
||||
assert message == "The number of written tags does not match the number of tag names: Expected ['tag1', 'tag2'] tags, but ['tag1'] tags were written."
|
||||
api.send_notification_async.assert_called_once()
|
||||
call_args = api.send_notification_async.call_args
|
||||
assert call_args.kwargs['notification_id'] == 'WRITE_PI_WEB_API_PREDICTION_ERROR'
|
||||
@@ -385,7 +384,7 @@ async def test_process_pi_web_api_response_missing_webid(api):
|
||||
'workflow_name': 'test_workflow',
|
||||
}
|
||||
|
||||
confidence = await api.process_pi_web_api_response(
|
||||
confidence, message = await api.process_pi_web_api_response(
|
||||
response_data=response_data,
|
||||
tags=tags,
|
||||
core_labels=core_labels,
|
||||
@@ -393,6 +392,7 @@ async def test_process_pi_web_api_response_missing_webid(api):
|
||||
)
|
||||
|
||||
assert confidence == PI_WEB_API_PREDICTION_ERROR_CONFIDENCE
|
||||
assert message == "The number of written tags does not match the number of tag names: Expected ['tag1', 'tag2'] tags, but ['tag2'] tags were written."
|
||||
api.error.assert_any_call('The response did not contain some WebIds', metadata['metadata'])
|
||||
|
||||
|
||||
@@ -411,7 +411,7 @@ async def test_process_pi_web_api_response_missing_tag_name(api):
|
||||
'workflow_name': 'test_workflow',
|
||||
}
|
||||
|
||||
confidence = await api.process_pi_web_api_response(
|
||||
confidence, message = await api.process_pi_web_api_response(
|
||||
response_data=response_data,
|
||||
tags=tags,
|
||||
core_labels=core_labels,
|
||||
@@ -419,6 +419,7 @@ async def test_process_pi_web_api_response_missing_tag_name(api):
|
||||
)
|
||||
|
||||
assert confidence == PI_WEB_API_PREDICTION_ERROR_CONFIDENCE
|
||||
assert message == "The number of written tags does not match the number of tag names: Expected ['tag1'] tags, but [] tags were written."
|
||||
api.error.assert_any_call(
|
||||
'The response did not contain the tag name for WebId unknown_web_id', metadata['metadata']
|
||||
)
|
||||
|
||||
@@ -812,7 +812,7 @@ async def test_fit_models_not_df_target_name_none_and_not_in_model(
|
||||
data = MagicMock()
|
||||
|
||||
output = await mlflow_repository.fit_models(
|
||||
'model_name', data, 'latest_production_id', metadata['metadata'], 'sklearn', 'pyfunc', None
|
||||
'model_name', data, 'latest_production_id', metadata['metadata'], 'sklearn', False, 'pyfunc', None
|
||||
)
|
||||
|
||||
mlflow_repository.download_model.assert_has_calls(
|
||||
@@ -908,6 +908,7 @@ async def test_fit_models_df_target_name_not_none_and_in_model(
|
||||
'latest_production_id',
|
||||
metadata['metadata'],
|
||||
'sklearn',
|
||||
False,
|
||||
'pyfunc',
|
||||
'feat_1',
|
||||
)
|
||||
@@ -1425,6 +1426,7 @@ async def test_retrain_model(mlflow_repository):
|
||||
model_name=model_name,
|
||||
data=data,
|
||||
transform_flavor='sklearn',
|
||||
skip_transform=False,
|
||||
predict_flavor='pyfunc',
|
||||
target_name='target',
|
||||
metadata=metadata['metadata'],
|
||||
|
||||
Reference in New Issue
Block a user