Skip to content

Commit b723f13

Browse files
authored
Merge pull request #2519 from bcgov/release
Hotfix 1.0.4.2
2 parents 6e7facb + 8bbfaec commit b723f13

File tree

13 files changed

+922
-209
lines changed

13 files changed

+922
-209
lines changed

backend/lcfs/tests/compliance_report/test_summary_service.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ async def test_calculate_renewable_fuel_target_summary_2024(
200200
line_8_obligation_deferred_gasoline=100,
201201
line_8_obligation_deferred_diesel=100,
202202
line_8_obligation_deferred_jet_fuel=100,
203+
line_4_eligible_renewable_fuel_required_gasoline=1,
204+
line_4_eligible_renewable_fuel_required_diesel=1,
205+
line_4_eligible_renewable_fuel_required_jet_fuel=1,
203206
)
204207

205208
result = compliance_report_summary_service.calculate_renewable_fuel_target_summary(
@@ -576,8 +579,8 @@ async def test_calculate_non_compliance_penalty_summary_with_penalty_payable(
576579
async def test_calculate_renewable_fuel_target_summary_no_renewables(
577580
compliance_report_summary_service,
578581
):
579-
# Test case where there are no renewable quantities
580-
fossil_quantities = {"gasoline": 1000, "diesel": 2000, "jet_fuel": 3000}
582+
# Test case where there are no renewable quantities, resulting in penalties with decimals
583+
fossil_quantities = {"gasoline": 1005, "diesel": 2005, "jet_fuel": 3005}
581584
renewable_quantities = {"gasoline": 0, "diesel": 0, "jet_fuel": 0}
582585
previous_retained = {"gasoline": 0, "diesel": 0, "jet_fuel": 0}
583586
previous_obligation = {"gasoline": 0, "diesel": 0, "jet_fuel": 0}
@@ -604,11 +607,11 @@ async def test_calculate_renewable_fuel_target_summary_no_renewables(
604607

605608
assert len(result) == 11
606609
assert isinstance(result[0], ComplianceReportSummaryRowSchema)
607-
# Penalty should be applied due to no renewables
608-
assert result[10].gasoline == 15.0
609-
assert result[10].diesel == 36.0
610-
assert result[10].jet_fuel == 45.0
611-
assert result[10].total_value == 96.0
610+
# Penalty should be applied due to no renewables, checking for decimal values
611+
assert result[10].gasoline == 15.08 # 50.25 L shortfall * $0.30/L = 15.075 rounded
612+
assert result[10].diesel == 36.09 # 80.2 L shortfall * $0.45/L = 36.09
613+
assert result[10].jet_fuel == 45.08 # 90.15 L shortfall * $0.50/L = 45.075 rounded
614+
assert result[10].total_value == (15.08 + 36.09 + 45.08) # 96.25
612615

613616

614617
@pytest.mark.anyio
@@ -849,14 +852,14 @@ async def test_can_sign_flag_logic(
849852
)
850853
)
851854

852-
compliance_report_summary_service.fuel_supply_repo.get_effective_fuel_supplies = AsyncMock(
853-
return_value=mock_effective_fuel_supplies
855+
compliance_report_summary_service.fuel_supply_repo.get_effective_fuel_supplies = (
856+
AsyncMock(return_value=mock_effective_fuel_supplies)
854857
)
855858
compliance_report_summary_service.notional_transfer_service.calculate_notional_transfers = AsyncMock(
856859
return_value=mock_notional_transfers
857860
)
858-
compliance_report_summary_service.fuel_export_repo.get_effective_fuel_exports = AsyncMock(
859-
return_value=mock_fuel_exports
861+
compliance_report_summary_service.fuel_export_repo.get_effective_fuel_exports = (
862+
AsyncMock(return_value=mock_fuel_exports)
860863
)
861864
compliance_report_summary_service.allocation_agreement_repo.get_allocation_agreements = AsyncMock(
862865
return_value=mock_allocation_agreements
@@ -884,36 +887,42 @@ def mock_calculate_renewable_fuel_target_summary(*args, **kwargs):
884887
gasoline=10.0,
885888
diesel=10.0,
886889
jet_fuel=10.0,
887-
total_value=30.0
890+
total_value=30.0,
888891
)
889892
result.append(row)
890893
return result
891894

892895
# Replace the method completely
893-
compliance_report_summary_service.calculate_renewable_fuel_target_summary = mock_calculate_renewable_fuel_target_summary
896+
compliance_report_summary_service.calculate_renewable_fuel_target_summary = (
897+
mock_calculate_renewable_fuel_target_summary
898+
)
894899

895900
# Call the method
896-
result = await compliance_report_summary_service.calculate_compliance_report_summary(1)
901+
result = (
902+
await compliance_report_summary_service.calculate_compliance_report_summary(1)
903+
)
897904

898905
# Assert that `can_sign` is True
899906
assert result.can_sign is True
900907

901908
# Scenario 2: No conditions met
902-
compliance_report_summary_service.fuel_supply_repo.get_effective_fuel_supplies = AsyncMock(
903-
return_value=[]
909+
compliance_report_summary_service.fuel_supply_repo.get_effective_fuel_supplies = (
910+
AsyncMock(return_value=[])
904911
)
905912
compliance_report_summary_service.notional_transfer_service.calculate_notional_transfers = AsyncMock(
906913
return_value=MagicMock(notional_transfers=[])
907914
)
908-
compliance_report_summary_service.fuel_export_repo.get_effective_fuel_exports = AsyncMock(
909-
return_value=[]
915+
compliance_report_summary_service.fuel_export_repo.get_effective_fuel_exports = (
916+
AsyncMock(return_value=[])
910917
)
911918
compliance_report_summary_service.allocation_agreement_repo.get_allocation_agreements = AsyncMock(
912919
return_value=[]
913920
)
914921

915922
# Call the method again
916-
result = await compliance_report_summary_service.calculate_compliance_report_summary(1)
923+
result = (
924+
await compliance_report_summary_service.calculate_compliance_report_summary(1)
925+
)
917926

918927
# Assert that `can_sign` is False
919928
assert result.can_sign is False

backend/lcfs/tests/services/redis/test_redis.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,6 @@ async def test_init_redis_success():
2424
mock_redis.close.assert_not_called()
2525

2626

27-
@pytest.mark.anyio
28-
async def test_init_redis_failure():
29-
"""
30-
Test Redis initialization fails during connection.
31-
"""
32-
app = FastAPI()
33-
34-
with patch(
35-
"lcfs.services.redis.lifetime.Redis",
36-
side_effect=RedisError("Connection failed"),
37-
):
38-
with pytest.raises(RedisError, match="Connection failed"):
39-
await init_redis(app)
40-
41-
assert not hasattr(app.state, "redis_client")
42-
43-
4427
@pytest.mark.anyio
4528
async def test_shutdown_redis_success():
4629
"""

0 commit comments

Comments
 (0)