Skip to content

Commit 844f583

Browse files
authored
Merge pull request #3906 from bcgov/hotfix-v1.2.5.1
Hotfix v1.2.5.1
2 parents 0357799 + 38843f7 commit 844f583

File tree

12 files changed

+366
-93
lines changed

12 files changed

+366
-93
lines changed

backend/lcfs/db/models/compliance/ChargingSite.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ def generate_site_code(mapper, connection, target):
195195

196196
def latest_charging_site_version_subquery():
197197
"""
198-
Helper subquery that returns the latest version number for each charging site ID.
199-
Used to ensure queries only work with the most recent version of a site.
198+
Helper subquery that returns the latest version number for each charging site group UUID.
199+
Used to ensure queries only work with the most recent version of a site record group.
200200
"""
201201
return (
202202
select(
203-
ChargingSite.charging_site_id.label("charging_site_id"),
203+
ChargingSite.group_uuid.label("group_uuid"),
204204
func.max(ChargingSite.version).label("latest_version"),
205205
)
206-
.group_by(ChargingSite.charging_site_id)
206+
.group_by(ChargingSite.group_uuid)
207207
.subquery()
208208
)

backend/lcfs/tests/charging_equipment/test_charging_equipment_repo.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
)
1212
from lcfs.web.api.base import PaginationRequestSchema, SortOrder
1313
from lcfs.web.api.charging_equipment.repo import ChargingEquipmentRepository
14-
from lcfs.web.api.charging_equipment.schema import (
15-
ChargingEquipmentFilterSchema,
16-
ChargingEquipmentStatusEnum,
17-
)
14+
from lcfs.web.api.charging_equipment.schema import ChargingEquipmentStatusEnum
1815

1916

2017
@pytest.fixture
@@ -90,9 +87,8 @@ async def test_get_charging_equipment_list_success(
9087
repo, mock_db, valid_charging_equipment
9188
):
9289
"""Test getting paginated list of charging equipment."""
93-
# Setup pagination and filters
90+
# Setup pagination
9491
pagination = PaginationRequestSchema(page=1, size=10, sort_orders=[])
95-
filters = ChargingEquipmentFilterSchema(status=[ChargingEquipmentStatusEnum.DRAFT])
9692

9793
# Mock the database query results
9894
mock_items_result = MagicMock()
@@ -104,7 +100,7 @@ async def test_get_charging_equipment_list_success(
104100
mock_db.execute.side_effect = [mock_count_result, mock_items_result]
105101

106102
# Call the repository method
107-
items, total_count = await repo.get_charging_equipment_list(1, pagination, filters)
103+
items, total_count = await repo.get_charging_equipment_list(1, pagination)
108104

109105
# Verify the results
110106
assert len(items) == 1
@@ -314,13 +310,12 @@ async def test_update_charging_equipment_creates_new_version_for_validated(
314310
1, {"manufacturer": "ChargeCo", "model": "Rev2"}
315311
)
316312

317-
assert result is valid_charging_equipment
313+
assert result is not None
318314
assert result.version == original_version + 1
319315
assert result.manufacturer == "ChargeCo"
320316
assert result.model == "Rev2"
321317
assert result.group_uuid == "group-123"
322-
assert result.intended_uses == list(valid_charging_equipment.intended_uses)
323-
mock_db.add.assert_not_called()
318+
mock_db.add.assert_called_once()
324319
mock_db.flush.assert_called_once()
325320
assert mock_db.refresh.call_count == 2
326321

backend/lcfs/tests/charging_equipment/test_charging_equipment_services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def test_get_charging_equipment_list_supplier_success(
8484

8585
# Verify repo was called with correct organization_id
8686
mock_repo.get_charging_equipment_list.assert_called_once_with(
87-
mock_user.organization_id, pagination, None, False
87+
mock_user.organization_id, pagination, False
8888
)
8989

9090

@@ -109,7 +109,7 @@ async def test_get_charging_equipment_list_government_with_org_filter(
109109

110110
# Verify repo was called with filtered organization_id and exclude_draft=True for government users
111111
mock_repo.get_charging_equipment_list.assert_called_once_with(
112-
2, pagination, filters, True
112+
2, pagination, True
113113
)
114114

115115

@@ -131,7 +131,7 @@ async def test_get_charging_equipment_list_government_no_org_filter_success(
131131

132132
# Government users without an org filter should query all organizations (organization_id None) and exclude_draft=True
133133
mock_repo.get_charging_equipment_list.assert_called_once_with(
134-
None, pagination, None, True
134+
None, pagination, True
135135
)
136136

137137

backend/lcfs/tests/charging_site/test_charging_site_services.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,25 @@ async def test_update_charging_site_validated_creates_new_version(
393393
mock_existing_site.organization_id = 1
394394
mock_existing_site.charging_site_id = 1
395395
mock_existing_site.version = 1
396+
mock_existing_site.allocating_organization_id = None
397+
mock_existing_site.allocating_organization_name = None
398+
mock_existing_site.site_code = "SITE001"
399+
mock_existing_site.street_address = "123 Main St"
400+
mock_existing_site.city = "Vancouver"
401+
mock_existing_site.postal_code = "V6B 1A1"
402+
mock_existing_site.latitude = 49.2827
403+
mock_existing_site.longitude = -123.1207
404+
mock_existing_site.notes = "Test notes"
405+
mock_existing_site.status_id = 1
406+
mock_existing_site.group_uuid = "test-uuid"
407+
mock_existing_site.documents = []
396408
mock_repo.get_charging_site_by_id.return_value = mock_existing_site
397409
mock_repo.charging_site_name_exists.return_value = False
398410

399411
updated_status = MagicMock(spec=ChargingSiteStatus)
400412
updated_status.charging_site_status_id = 2
401413
updated_status.status = "Updated"
414+
updated_status._sa_instance_state = MagicMock()
402415
mock_repo.get_charging_site_status_by_name.return_value = updated_status
403416

404417
mock_org = MagicMock()
@@ -429,7 +442,7 @@ async def test_update_charging_site_validated_creates_new_version(
429442
mock_updated_site.create_user = "testuser"
430443
mock_updated_site.update_user = "testuser"
431444

432-
mock_repo.update_charging_site.return_value = mock_updated_site
445+
mock_repo.create_charging_site.return_value = mock_updated_site
433446

434447
update_data = ChargingSiteCreateSchema(
435448
charging_site_id=1,
@@ -446,9 +459,9 @@ async def test_update_charging_site_validated_creates_new_version(
446459
result = await charging_site_service.update_charging_site(update_data)
447460

448461
assert isinstance(result, ChargingSiteSchema)
449-
assert mock_existing_site.version == 2
462+
assert result.version == 2
450463
mock_repo.get_charging_site_status_by_name.assert_called_once_with("Updated")
451-
mock_repo.update_charging_site.assert_called_once_with(mock_existing_site)
464+
mock_repo.create_charging_site.assert_called_once()
452465

453466
@pytest.mark.anyio
454467
async def test_update_charging_site_duplicate_name(

0 commit comments

Comments
 (0)