Skip to content

Feat: LCFS - Add a Return report to the supplier button #1507 #1650

Feat: LCFS - Add a Return report to the supplier button #1507

Feat: LCFS - Add a Return report to the supplier button #1507 #1650

GitHub Actions / Backend Test Results succeeded Dec 23, 2024 in 0s

1 fail, 501 pass in 1m 58s

502 tests   501 ✅  1m 58s ⏱️
  1 suites    0 💤
  1 files      1 ❌

Results for commit 6f383dd.

Annotations

Check warning on line 0 in lcfs.tests.compliance_report.test_update_service

See this annotation in the file changed.

@github-actions github-actions / Backend Test Results

test_handle_submitted_status_with_existing_summary (lcfs.tests.compliance_report.test_update_service) failed

backend/pytest-results.xml [took 0s]
Raw output
AssertionError: Expected 'adjust_balance' to be called once. Called 0 times.
compliance_report_update_service = <lcfs.web.api.compliance_report.update_service.ComplianceReportUpdateService object at 0x7f24b3198250>
mock_repo = <AsyncMock spec='ComplianceReportRepository' id='139795600354144'>
mock_user_has_roles = <MagicMock name='user_has_roles' id='139795600172912'>
mock_org_service = <MagicMock id='139795599771344'>
compliance_report_summary_service = <lcfs.web.api.compliance_report.summary_service.ComplianceReportSummaryService object at 0x7f24b31bf8b0>

    @pytest.mark.anyio
    async def test_handle_submitted_status_with_existing_summary(
        compliance_report_update_service,
        mock_repo,
        mock_user_has_roles,
        mock_org_service,
        compliance_report_summary_service,
    ):
        # Mock data
        report_id = 1
        mock_report = MagicMock(spec=ComplianceReport)
        mock_report.compliance_report_id = report_id
        mock_report.organization_id = 123  # Mock organization ID
        mock_report.summary = MagicMock(spec=ComplianceReportSummary)
        mock_report.summary.line_20_surplus_deficit_units = 100  # Mock compliance units
    
        # Mock existing summary with user-edited values
        existing_summary = MagicMock(spec=ComplianceReportSummary)
        existing_summary.line_6_renewable_fuel_retained_gasoline = 1000
        existing_summary.line_7_previously_retained_diesel = 2000
        existing_summary.line_8_obligation_deferred_jet_fuel = 3000
    
        # Mock user roles (user has required roles)
        mock_user_has_roles.return_value = True
        compliance_report_update_service.request = MagicMock()
        compliance_report_update_service.request.user = MagicMock()
    
        # Mock calculated summary
        calculated_summary = ComplianceReportSummarySchema(
            summary_id=100,
            compliance_report_id=report_id,
            renewable_fuel_target_summary=[
                ComplianceReportSummaryRowSchema(
                    line="6",
                    field="renewable_fuel_retained",
                    gasoline=0,
                    diesel=0,
                    jet_fuel=0,
                ),
                ComplianceReportSummaryRowSchema(
                    line="7", field="previously_retained", gasoline=0, diesel=0, jet_fuel=0
                ),
                ComplianceReportSummaryRowSchema(
                    line="8", field="obligation_deferred", gasoline=0, diesel=0, jet_fuel=0
                ),
            ],
            low_carbon_fuel_target_summary=[
                ComplianceReportSummaryRowSchema(
                    line="12", field="low_carbon_fuel_required", value=0
                ),
            ],
            non_compliance_penalty_summary=[
                ComplianceReportSummaryRowSchema(
                    line="21", field="non_compliance_penalty_payable", value=0
                ),
            ],
            can_sign=True,
        )
    
        # Set up mocks
        mock_repo.get_summary_by_report_id.return_value = existing_summary
        compliance_report_summary_service.calculate_compliance_report_summary = AsyncMock(
            return_value=calculated_summary
        )
    
        # Inject the mocked org_service into the service being tested
        compliance_report_update_service.org_service = mock_org_service
    
        # Mock the adjust_balance method to return a mocked transaction result
        mock_org_service.adjust_balance.return_value = MagicMock()
    
        # Call the method
        await compliance_report_update_service.handle_submitted_status(mock_report)
    
        # Assertions
        mock_user_has_roles.assert_called_once_with(
            compliance_report_update_service.request.user,
            [RoleEnum.SUPPLIER, RoleEnum.SIGNING_AUTHORITY],
        )
        mock_repo.get_summary_by_report_id.assert_called_once_with(report_id)
        compliance_report_summary_service.calculate_compliance_report_summary.assert_called_once_with(
            report_id
        )
    
        # Ensure the adjust_balance method is called with the correct parameters
>       mock_org_service.adjust_balance.assert_called_once_with(
            transaction_action=TransactionActionEnum.Reserved,
            compliance_units=mock_report.summary.line_20_surplus_deficit_units,
            organization_id=mock_report.organization_id,
        )

lcfs/tests/compliance_report/test_update_service.py:285: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <AsyncMock name='mock.adjust_balance' id='139795599779168'>, args = ()
kwargs = {'compliance_units': <AsyncMock name='mock.save_compliance_report_summary().line_20_surplus_deficit_units' id='139795594546768'>, 'organization_id': 123, 'transaction_action': <TransactionActionEnum.Reserved: 'Reserved'>}
msg = "Expected 'adjust_balance' to be called once. Called 0 times."

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'adjust_balance' to be called once. Called 0 times.

/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/unittest/mock.py:940: AssertionError