Skip to content

Merge remote-tracking branch 'origin/release-0.2.0' into feat/kevin-1387 #1404

Merge remote-tracking branch 'origin/release-0.2.0' into feat/kevin-1387

Merge remote-tracking branch 'origin/release-0.2.0' into feat/kevin-1387 #1404

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

3 fail, 490 pass in 1m 51s

493 tests  ±0   490 ✅ ±0   1m 51s ⏱️ +4s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     3 ❌ ±0 

Results for commit 33befe5. ± Comparison against earlier commit 6a70acc.

Annotations

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

See this annotation in the file changed.

@github-actions github-actions / Backend Test Results

test_calculate_fuel_quantities_renewable (lcfs.tests.compliance_report.test_summary_service) failed

backend/pytest-results.xml [took 0s]
Raw output
AssertionError: Expected aggregate_allocation_agreements to have been awaited once. Awaited 0 times.
compliance_report_summary_service = <lcfs.web.api.compliance_report.summary_service.ComplianceReportSummaryService object at 0x7fa78447e170>
mock_repo = <AsyncMock spec='ComplianceReportRepository' id='140357455347280'>
mock_trxn_repo = <AsyncMock spec='TransactionRepository' id='140357458793744'>
mock_fuel_supply_repo = <AsyncMock spec='FuelSupplyRepository' id='140357456083264'>

    @pytest.mark.anyio
    async def test_calculate_fuel_quantities_renewable(
        compliance_report_summary_service,
        mock_repo,
        mock_trxn_repo,
        mock_fuel_supply_repo,
    ):
        # Create a mock repository
        mock_repo.aggregate_fuel_supplies.return_value = {"gasoline": 200.0}
        mock_repo.aggregate_other_uses.return_value = {"diesel": 75.0}
        mock_repo.aggregate_allocation_agreements.return_value = {"jet-fuel": 25.0}
    
        # Define test inputs
        compliance_report_id = 2
        effective_fuel_supplies: List[FuelSupply] = []
        fossil_derived = False
    
        # Call the method under test
        result = await compliance_report_summary_service.calculate_fuel_quantities(
            compliance_report_id, effective_fuel_supplies, fossil_derived
        )
    
        # Assertions
        mock_repo.aggregate_fuel_supplies.assert_called_once_with(
            effective_fuel_supplies, fossil_derived
        )
        mock_repo.aggregate_other_uses.assert_awaited_once_with(
            compliance_report_id, fossil_derived
        )
>       mock_repo.aggregate_allocation_agreements.assert_awaited_once_with(
            compliance_report_id
        )

lcfs/tests/compliance_report/test_summary_service.py:833: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <AsyncMock name='mock.aggregate_allocation_agreements' id='140357455054496'>
args = (2,), kwargs = {}
msg = 'Expected aggregate_allocation_agreements to have been awaited once. Awaited 0 times.'

    def assert_awaited_once_with(self, /, *args, **kwargs):
        """
        Assert that the mock was awaited exactly once and with the specified
        arguments.
        """
        if not self.await_count == 1:
            msg = (f"Expected {self._mock_name or 'mock'} to have been awaited once."
                   f" Awaited {self.await_count} times.")
>           raise AssertionError(msg)
E           AssertionError: Expected aggregate_allocation_agreements to have been awaited once. Awaited 0 times.

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

Check warning on line 0 in lcfs.tests.internal_comment.test_internal_comment

See this annotation in the file changed.

@github-actions github-actions / Backend Test Results

test_get_internal_comments_multiple_comments (lcfs.tests.internal_comment.test_internal_comment) failed

backend/pytest-results.xml [took 0s]
Raw output
assert 0 == 3
 +  where 0 = len([])
client = <httpx.AsyncClient object at 0x7fa7841c6e90>
fastapi_app = <fastapi.applications.FastAPI object at 0x7fa77fdd81f0>
set_mock_user = <function set_mock_user.<locals>._set_mock_auth at 0x7fa77f93df30>
add_models = <function add_models.<locals>._add at 0x7fa77f767760>

    @pytest.mark.anyio
    async def test_get_internal_comments_multiple_comments(
        client: AsyncClient,
        fastapi_app: FastAPI,
        set_mock_user,
        add_models,
    ):
        """
        Test retrieving multiple internal comments for an entity.
        """
        set_mock_user(
            fastapi_app, [RoleEnum.GOVERNMENT], user_details={"username": "IDIRUSER"}
        )
    
        transfer = Transfer(
            transfer_id=5,
            from_organization_id=1,
            to_organization_id=2,
            agreement_date=datetime.now(),
            transaction_effective_date=datetime.now(),
            price_per_unit=1.0,
            quantity=100,
            transfer_category_id=1,
            current_status_id=1,
            recommendation=TransferRecommendationEnum.Record,
            effective_status=True,
        )
        await add_models([transfer])
    
        comments = []
        for i in range(3):
            internal_comment = InternalComment(
                internal_comment_id=i,
                comment=f"Comment {i}",
                audience_scope=AudienceScopeEnum.ANALYST.value,
                create_user="IDIRUSER",
            )
            await add_models([internal_comment])
            association = TransferInternalComment(
                transfer_id=transfer.transfer_id,
                internal_comment_id=internal_comment.internal_comment_id,
            )
            await add_models([association])
            comments.append(internal_comment)
    
        entity_type = EntityTypeEnum.TRANSFER.value
        entity_id = transfer.transfer_id
        url = fastapi_app.url_path_for(
            "get_comments", entity_type=entity_type, entity_id=entity_id
        )
        response = await client.get(url)
    
        assert response.status_code == status.HTTP_200_OK
        data = response.json()
    
        assert isinstance(data, list)
>       assert len(data) == 3
E       assert 0 == 3
E        +  where 0 = len([])

lcfs/tests/internal_comment/test_internal_comment.py:364: AssertionError

Check warning on line 0 in lcfs.tests.user.test_user_views

See this annotation in the file changed.

@github-actions github-actions / Backend Test Results

test_get_user_activities_as_manage_users_same_org (lcfs.tests.user.test_user_views) failed

backend/pytest-results.xml [took 0s]
Raw output
assert 403 == 200
 +  where 403 = <Response [403 Forbidden]>.status_code
 +  and   200 = status.HTTP_200_OK
client = <httpx.AsyncClient object at 0x7fa78448f250>
fastapi_app = <fastapi.applications.FastAPI object at 0x7fa7841eaec0>
set_mock_user = <function set_mock_user.<locals>._set_mock_auth at 0x7fa77f78ad40>
add_models = <function add_models.<locals>._add at 0x7fa77ec04e50>

    @pytest.mark.anyio
    async def test_get_user_activities_as_manage_users_same_org(
        client: AsyncClient,
        fastapi_app: FastAPI,
        set_mock_user,
        add_models,
    ):
        # Mock the current user as a user with MANAGE_USERS
        set_mock_user(fastapi_app, [RoleEnum.MANAGE_USERS])
    
        # Assuming target user with user_profile_id=3 exists and is in organization_id=1
        target_user_id = 1
    
        # Create activity history records for the target user
        transfer = Transfer(
            transfer_id=1,
            from_organization_id=1,
            to_organization_id=2,
            agreement_date=datetime.strptime("2024-01-01", "%Y-%m-%d"),
            transaction_effective_date=datetime.strptime("2024-01-01", "%Y-%m-%d"),
            price_per_unit=1.0,
            quantity=10,
            transfer_category_id=1,
            current_status_id=1,
            recommendation=TransferRecommendationEnum.Record,
            effective_status=True,
        )
        transfer_history = TransferHistory(
            transfer_history_id=1,
            transfer_id=transfer.transfer_id,
            transfer_status_id=3,  # Sent
            user_profile_id=target_user_id,
        )
    
        await add_models(
            [
                transfer,
                transfer_history,
            ]
        )
    
        # Prepare request data
        pagination = {
            "page": 1,
            "size": 10,
            "filters": [],
            "sortOrders": [],
        }
    
        # Send request to get user activities
        url = fastapi_app.url_path_for("get_user_activities", user_id=target_user_id)
        response = await client.post(url, json=pagination)
    
>       assert response.status_code == status.HTTP_200_OK
E       assert 403 == 200
E        +  where 403 = <Response [403 Forbidden]>.status_code
E        +  and   200 = status.HTTP_200_OK

lcfs/tests/user/test_user_views.py:173: AssertionError