"""Functional tests for ECS task endpoints.""" from datetime import datetime from unittest.mock import patch import pytest @pytest.mark.parametrize('request_data,expected_assertions', [ ( { 'full_refresh': True, 'select_models': 'custom_model1 custom_model2', 'exclude_models': 'old_model' }, ['Full Refresh: True'] ), ( {}, ['Full Refresh: True'] ) ]) @patch('moneyhub.logic.ecs_task.Config.DBT_REFRESH_STATE_MACHINE_ARN', 'arn:aws:states:us-east-1:123456789:stateMachine:test-dbt-sm') @patch('moneyhub.logic.ecs_task.boto3') def test_dbt_refresh_endpoint_integration( mock_boto3, fixture_client, request_data, expected_assertions ): """Test the complete dbt refresh endpoint with different parameter combinations.""" mock_sfn_client = mock_boto3.client.return_value mock_execution = { 'executionArn': 'arn:aws:states:us-east-1:123456789:execution:test-dbt-sm:exec-id', 'startDate': datetime(2025, 11, 28, 12, 0, 0) } mock_sfn_client.start_execution.return_value = mock_execution response = fixture_client.post( '/ecs/dbt-refresh', headers={'correlation-id': 'functional-test-correlation'}, json=request_data ) response_data = response.json() assert response.status_code == 200 assert 'execution_arn' in response_data assert 'start_date' in response_data assert 'status' in response_data assert response_data['status'] == 'RUNNING' assert 'message' in response_data assert 'Step Function' in response_data['message'] for expected_assertion in expected_assertions: assert expected_assertion in response_data['message'] @patch('moneyhub.logic.ecs_task.Config.DBT_REFRESH_STATE_MACHINE_ARN', 'arn:aws:states:us-east-1:123456789:stateMachine:test-dbt-sm') @patch('moneyhub.logic.ecs_task.boto3') def test_dbt_refresh_production_flow(mock_boto3, fixture_client): """Test the dbt refresh endpoint with production parameters.""" mock_sfn_client = mock_boto3.client.return_value mock_execution = { 'executionArn': 'arn:aws:states:us-east-1:123456789:execution:test-dbt-sm:prod-exec-id', 'startDate': datetime(2025, 11, 28, 14, 30, 0) } mock_sfn_client.start_execution.return_value = mock_execution response = fixture_client.post( '/ecs/dbt-refresh', json={ 'full_refresh': False, 'select_models': 'prod_model1 prod_model2' } ) response_data = response.json() assert response.status_code == 200 assert 'execution_arn' in response_data assert 'start_date' in response_data assert 'message' in response_data assert 'Full Refresh: False' in response_data['message'] mock_sfn_client.start_execution.assert_called_once()