From d8fb658dc567ca2e036f148b56dc8784c8392b4c Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 17 Dec 2024 12:58:45 -0800 Subject: [PATCH] correct test cases --- .../compliance_report/test_update_service.py | 26 ++++++------------- .../test_initiative_agreement_services.py | 6 ++--- .../tests/transfer/test_transfer_services.py | 12 ++++----- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/backend/lcfs/tests/compliance_report/test_update_service.py b/backend/lcfs/tests/compliance_report/test_update_service.py index 753ec8b76..12532c4e0 100644 --- a/backend/lcfs/tests/compliance_report/test_update_service.py +++ b/backend/lcfs/tests/compliance_report/test_update_service.py @@ -69,6 +69,7 @@ async def test_update_compliance_report_status_change( mock_report.current_status.status = ComplianceReportStatusEnum.Draft mock_report.compliance_period = MagicMock() mock_report.compliance_period.description = "2024" + mock_report.transaction_id = 123 new_status = MagicMock(spec=ComplianceReportStatus) new_status.status = ComplianceReportStatusEnum.Submitted @@ -82,7 +83,7 @@ async def test_update_compliance_report_status_change( mock_repo.get_compliance_report_status_by_desc.return_value = new_status compliance_report_update_service.handle_status_change = AsyncMock() mock_repo.update_compliance_report.return_value = mock_report - compliance_report_update_service._perform_notificaiton_call = AsyncMock() + compliance_report_update_service._perform_notification_call = AsyncMock() # Call the method updated_report = await compliance_report_update_service.update_compliance_report( @@ -104,7 +105,7 @@ async def test_update_compliance_report_status_change( mock_report, compliance_report_update_service.request.user ) mock_repo.update_compliance_report.assert_called_once_with(mock_report) - compliance_report_update_service._perform_notificaiton_call.assert_called_once_with( + compliance_report_update_service._perform_notification_call.assert_called_once_with( mock_report, "Submitted" ) @@ -119,11 +120,11 @@ async def test_update_compliance_report_no_status_change( mock_report.compliance_report_id = report_id mock_report.current_status = MagicMock(spec=ComplianceReportStatus) mock_report.current_status.status = ComplianceReportStatusEnum.Draft - - # Fix for JSON serialization mock_report.compliance_period = MagicMock() mock_report.compliance_period.description = "2024" + mock_report.transaction_id = 123 + # Status does not change report_data = ComplianceReportUpdateSchema( status="Draft", supplemental_note="Test note" ) @@ -134,10 +135,7 @@ async def test_update_compliance_report_no_status_change( mock_report.current_status ) mock_repo.update_compliance_report.return_value = mock_report - - # Mock the handle_status_change method - compliance_report_update_service.handle_status_change = AsyncMock() - compliance_report_update_service._perform_notificaiton_call = AsyncMock() + compliance_report_update_service._perform_notification_call = AsyncMock() # Call the method updated_report = await compliance_report_update_service.update_compliance_report( @@ -146,18 +144,10 @@ async def test_update_compliance_report_no_status_change( # Assertions assert updated_report == mock_report - mock_repo.get_compliance_report_by_id.assert_called_once_with( - report_id, is_model=True - ) - mock_repo.get_compliance_report_status_by_desc.assert_called_once_with( - report_data.status - ) - compliance_report_update_service.handle_status_change.assert_not_called() - mock_repo.add_compliance_report_history.assert_not_called() - mock_repo.update_compliance_report.assert_called_once_with(mock_report) - compliance_report_update_service._perform_notificaiton_call.assert_called_once_with( + compliance_report_update_service._perform_notification_call.assert_called_once_with( mock_report, "Draft" ) + mock_repo.update_compliance_report.assert_called_once_with(mock_report) @pytest.mark.anyio diff --git a/backend/lcfs/tests/initiative_agreement/test_initiative_agreement_services.py b/backend/lcfs/tests/initiative_agreement/test_initiative_agreement_services.py index 2eb16223d..cb0ee6994 100644 --- a/backend/lcfs/tests/initiative_agreement/test_initiative_agreement_services.py +++ b/backend/lcfs/tests/initiative_agreement/test_initiative_agreement_services.py @@ -113,8 +113,8 @@ async def test_create_initiative_agreement(service, mock_repo, mock_request): internal_comment=None, ) - # Mock _perform_notificaiton_call to isolate it - service._perform_notificaiton_call = AsyncMock() + # Mock _perform_notification_call to isolate it + service._perform_notification_call = AsyncMock() # Call the service method result = await service.create_initiative_agreement(create_data) @@ -122,7 +122,7 @@ async def test_create_initiative_agreement(service, mock_repo, mock_request): # Assertions assert result == mock_initiative_agreement mock_repo.create_initiative_agreement.assert_called_once() - service._perform_notificaiton_call.assert_called_once_with( + service._perform_notification_call.assert_called_once_with( mock_initiative_agreement ) diff --git a/backend/lcfs/tests/transfer/test_transfer_services.py b/backend/lcfs/tests/transfer/test_transfer_services.py index 91c8e7f21..f82ef70c7 100644 --- a/backend/lcfs/tests/transfer/test_transfer_services.py +++ b/backend/lcfs/tests/transfer/test_transfer_services.py @@ -76,13 +76,13 @@ async def test_create_transfer_success(transfer_service, mock_transfer_repo): ) mock_transfer_repo.create_transfer.return_value = transfer_data - # Patch the _perform_notificaiton_call method - with patch.object(transfer_service, "_perform_notificaiton_call", AsyncMock()): + # Patch the _perform_notification_call method + with patch.object(transfer_service, "_perform_notification_call", AsyncMock()): result = await transfer_service.create_transfer(transfer_data) assert result.transfer_id == transfer_id assert isinstance(result, TransferCreateSchema) - transfer_service._perform_notificaiton_call.assert_called_once() + transfer_service._perform_notification_call.assert_called_once() @pytest.mark.anyio @@ -121,8 +121,8 @@ async def test_update_transfer_success( mock_transfer_repo.get_transfer_by_id.return_value = transfer mock_transfer_repo.update_transfer.return_value = transfer - # Replace _perform_notificaiton_call with an AsyncMock - transfer_service._perform_notificaiton_call = AsyncMock() + # Replace _perform_notification_call with an AsyncMock + transfer_service._perform_notification_call = AsyncMock() result = await transfer_service.update_transfer(transfer) @@ -133,7 +133,7 @@ async def test_update_transfer_success( # Verify mocks mock_transfer_repo.get_transfer_by_id.assert_called_once_with(transfer_id) mock_transfer_repo.update_transfer.assert_called_once_with(transfer) - transfer_service._perform_notificaiton_call.assert_awaited_once_with( + transfer_service._perform_notification_call.assert_awaited_once_with( transfer, status="Return to analyst" )