SIENTIAPDE-994
Refactor tests for Postgres activities and improve error handling - Updated test_postgres.py to enhance the testing of load_custom_query method, including cases for None data and date conversion. - Refactored repeat_last_prediction tests to use mocks for SQLAlchemy session execution. - Added tests for export_data_to_postgres method, covering both success and error scenarios. - Improved the initialization tests for Activities class to ensure proper instantiation of dependencies. - Enhanced test coverage for OPC repository connection validation. - Updated tests for prediction workflows to streamline input handling and improve clarity. - Introduced tests for connectors configuration to validate environment variable handling for MLFlow, OPC, and Postgres. - Added tests for logger utility to ensure default settings are correctly applied.
This commit is contained in:
@@ -55,7 +55,6 @@ async def test_run_none_path_flag(workflow_mock, format_and_export_prediction):
|
||||
call(
|
||||
Activities.write_opc_data,
|
||||
{
|
||||
'opc_servers': input_data['opc_servers'],
|
||||
'opc_output_config': input_data['opc_output_config'],
|
||||
'data': workflow_mock.execute_local_activity_method.return_value
|
||||
},
|
||||
@@ -116,7 +115,6 @@ async def test_run_default_path_flag(workflow_mock, format_and_export_prediction
|
||||
call(
|
||||
Activities.write_opc_data,
|
||||
{
|
||||
'opc_servers': input_data['opc_servers'],
|
||||
'opc_output_config': input_data['opc_output_config'],
|
||||
'data': workflow_mock.execute_local_activity_method.return_value
|
||||
},
|
||||
|
||||
@@ -231,7 +231,8 @@ async def test_run_stop_at_mlflow_content_gate(workflow_mock, prediction_process
|
||||
'2024-01-01', # get_last_timestamp
|
||||
('continue', 0.95, "Input data with bad quality"), # input_gate
|
||||
{'content': 'transformed_data', 'timestamp': '2024-01-01'}, # transform_data
|
||||
('continue', 0.95, "Error"), # mlflow_response_gate (transform)
|
||||
# mlflow_response_gate (transform)
|
||||
('continue', 0.95, "Error"),
|
||||
# mlflow_content_gate (transform)
|
||||
('continue', 0.95, "Transformed data not passed the content filter"),
|
||||
]
|
||||
@@ -299,7 +300,8 @@ async def test_run_stop_at_mlflow_last_response_gate(workflow_mock, prediction_p
|
||||
'2024-01-01', # get_last_timestamp
|
||||
('continue', 0.95, "Input data with bad quality"), # input_gate
|
||||
{'content': 'transformed_data', 'timestamp': '2024-01-01'}, # transform_data
|
||||
('continue', 0.95, "Error"), # mlflow_response_gate (transform)
|
||||
# mlflow_response_gate (transform)
|
||||
('continue', 0.95, "Error"),
|
||||
# mlflow_content_gate (transform)
|
||||
('continue', 0.95, "Transformed data not passed the content filter"),
|
||||
{'content': 'predicted_data', 'timestamp': '2024-01-01'}, # request_predict
|
||||
@@ -372,8 +374,14 @@ async def test_path_flag_handler_stop(workflow_mock, prediction_process):
|
||||
|
||||
# Act
|
||||
result = await prediction_process.path_flag_handler(
|
||||
data, path_flag, confidence, schema, table_name,
|
||||
model, last_timestamp, model_name, model_retention, ""
|
||||
data, path_flag, {
|
||||
'schema': schema,
|
||||
'table_name': table_name,
|
||||
'model_id': model,
|
||||
'last_timestamp': last_timestamp,
|
||||
'model_name': model_name,
|
||||
'model_retention': model_retention
|
||||
}, confidence, last_timestamp, ""
|
||||
)
|
||||
|
||||
# Assert
|
||||
@@ -398,8 +406,14 @@ async def test_path_flag_handler_repeat(workflow_mock, prediction_process):
|
||||
|
||||
# Act
|
||||
result = await prediction_process.path_flag_handler(
|
||||
data, path_flag, confidence, schema, table_name,
|
||||
model, last_timestamp, model_name, model_retention, ""
|
||||
data, path_flag, {
|
||||
'schema': schema,
|
||||
'table_name': table_name,
|
||||
'model_id': model,
|
||||
'last_timestamp': last_timestamp,
|
||||
'model_name': model_name,
|
||||
'model_retention': model_retention
|
||||
}, confidence, last_timestamp, ""
|
||||
)
|
||||
|
||||
# Assert
|
||||
@@ -433,8 +447,15 @@ async def test_path_flag_handler_continue(workflow_mock, prediction_process):
|
||||
|
||||
# Act
|
||||
result = await prediction_process.path_flag_handler(
|
||||
data, path_flag, confidence, schema, table_name,
|
||||
model, last_timestamp, model_name, model_retention, 'Prediction Process'
|
||||
data, path_flag, {
|
||||
'schema': schema,
|
||||
'table_name': table_name,
|
||||
'model_id': model,
|
||||
'last_timestamp': last_timestamp,
|
||||
'model_name': model_name,
|
||||
'model_retention': model_retention,
|
||||
'opc_output_config': {'test': 'config'}
|
||||
}, confidence, last_timestamp, 'Prediction Process'
|
||||
)
|
||||
|
||||
# Assert
|
||||
@@ -452,7 +473,8 @@ async def test_path_flag_handler_continue(workflow_mock, prediction_process):
|
||||
'model_retention': model_retention,
|
||||
'schema': schema,
|
||||
'table_name': table_name,
|
||||
'comment': 'Prediction Process'
|
||||
'comment': 'Prediction Process',
|
||||
'opc_output_config': {'test': 'config'}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -473,8 +495,15 @@ async def test_path_flag_handler_unknown(workflow_mock, prediction_process):
|
||||
|
||||
# Act
|
||||
result = await prediction_process.path_flag_handler(
|
||||
data, path_flag, confidence, schema, table_name,
|
||||
model, last_timestamp, model_name, model_retention, ""
|
||||
data, path_flag, {
|
||||
'schema': schema,
|
||||
'table_name': table_name,
|
||||
'model_id': model,
|
||||
'last_timestamp': last_timestamp,
|
||||
'model_name': model_name,
|
||||
'model_retention': model_retention,
|
||||
'opc_output_config': {'test': 'config'}
|
||||
}, confidence, last_timestamp, ""
|
||||
)
|
||||
|
||||
# Assert
|
||||
|
||||
@@ -55,11 +55,24 @@ async def test_run(workflow_mock: AsyncMock, predictions_batch: PredictionsBatch
|
||||
'table_name': input_data['table_name'],
|
||||
'model_id': input_data['model_id'],
|
||||
'model_name': input_data['model_name'],
|
||||
'input_filters': input_data.get('input_filters', {}),
|
||||
'mlflow_transform_filters': input_data.get('mlflow_transform_filters', {}),
|
||||
'mlflow_predict_filters': input_data.get('mlflow_predict_filters', {}),
|
||||
'input_filters': input_data.get('input_filters', {
|
||||
'EMPTY_DATA': {
|
||||
'POLICY': 'STOP'
|
||||
}
|
||||
}),
|
||||
'mlflow_transform_filters': input_data.get('mlflow_transform_filters', {
|
||||
'API_ERROR': {
|
||||
'POLICY': 'STOP'
|
||||
}
|
||||
}),
|
||||
'mlflow_predict_filters': input_data.get('mlflow_predict_filters', {
|
||||
'API_ERROR': {
|
||||
'POLICY': 'STOP'
|
||||
}
|
||||
}),
|
||||
'model_retention': input_data.get('model_retention', 60),
|
||||
'path_priority': input_data.get('path_priority', ['STOP', 'CONTINUE', 'REPEAT'])
|
||||
'path_priority': input_data.get('path_priority', ['STOP', 'CONTINUE', 'REPEAT']),
|
||||
'opc_output_config': input_data.get('opc_output_config', {})
|
||||
}
|
||||
|
||||
workflow_mock.execute_child_workflow.assert_has_calls([
|
||||
|
||||
Reference in New Issue
Block a user