Skip to content

Commit 406970a

Browse files
authored
Merge pull request #4028 from bcgov/feat/hamed-fse-excel-download-fixes-3861
Feat: Improve FSE Excel download and row handling - 3861
2 parents f911dad + 9768c9b commit 406970a

File tree

6 files changed

+536
-186
lines changed

6 files changed

+536
-186
lines changed

backend/lcfs/tests/final_supply_equipment/test_final_supply_equipment_repo.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,113 @@ async def test_get_fse_reporting_record_for_group_not_found(repo, fake_db):
817817
)
818818

819819
assert record is None
820+
821+
822+
@pytest.mark.anyio
823+
async def test_get_fse_reporting_record_for_group_query_does_not_filter_on_version(
824+
repo, fake_db
825+
):
826+
"""
827+
The query must be version-agnostic: the compiled SQL should NOT contain a
828+
WHERE clause on charging_equipment_version so that equipment linked to an
829+
older site version is still found.
830+
"""
831+
result_mock = MagicMock()
832+
result_mock.scalars.return_value.first.return_value = None
833+
fake_db.execute.return_value = result_mock
834+
835+
await repo.get_fse_reporting_record_for_group(
836+
charging_equipment_id=1,
837+
charging_equipment_version=99, # arbitrary; must be ignored
838+
compliance_report_group_uuid="group-xyz",
839+
)
840+
841+
stmt = fake_db.execute.call_args[0][0]
842+
compiled = str(stmt.compile(compile_kwargs={"literal_binds": True}))
843+
# The WHERE clause must filter on charging_equipment_id and
844+
# compliance_report_group_uuid but NOT on charging_equipment_version.
845+
assert "charging_equipment_id" in compiled
846+
assert "compliance_report_group_uuid" in compiled
847+
assert "charging_equipment_version" not in compiled.split("WHERE")[1].split("ORDER")[0]
848+
849+
850+
# ===========================================================================
851+
# bulk_update_fse_reporting_record — deactivate path
852+
# ===========================================================================
853+
854+
855+
@pytest.mark.anyio
856+
async def test_bulk_update_deactivate_executes_update(repo, fake_db):
857+
"""deactivate=True → execute + flush are called."""
858+
await repo.bulk_update_fse_reporting_record(
859+
charging_equipment_compliance_id=20,
860+
supply_from_date=None,
861+
supply_to_date=None,
862+
kwh_usage=None,
863+
compliance_notes=None,
864+
deactivate=True,
865+
)
866+
867+
fake_db.execute.assert_called_once()
868+
fake_db.flush.assert_called_once()
869+
870+
871+
@pytest.mark.anyio
872+
async def test_bulk_update_deactivate_sets_is_active_false(repo, fake_db):
873+
"""deactivate=True → compiled SQL must set is_active = false."""
874+
await repo.bulk_update_fse_reporting_record(
875+
charging_equipment_compliance_id=20,
876+
supply_from_date=None,
877+
supply_to_date=None,
878+
kwh_usage=None,
879+
compliance_notes=None,
880+
deactivate=True,
881+
)
882+
883+
stmt = fake_db.execute.call_args[0][0]
884+
compiled = str(stmt.compile(compile_kwargs={"literal_binds": True}))
885+
assert "is_active" in compiled
886+
assert "false" in compiled.lower()
887+
888+
889+
@pytest.mark.anyio
890+
async def test_bulk_update_deactivate_does_not_set_dates(repo, fake_db):
891+
"""
892+
deactivate=True must NOT update supply_from_date or supply_to_date because
893+
those columns are NOT NULL in the database.
894+
"""
895+
await repo.bulk_update_fse_reporting_record(
896+
charging_equipment_compliance_id=20,
897+
supply_from_date=None,
898+
supply_to_date=None,
899+
kwh_usage=None,
900+
compliance_notes=None,
901+
deactivate=True,
902+
)
903+
904+
stmt = fake_db.execute.call_args[0][0]
905+
compiled = str(stmt.compile(compile_kwargs={"literal_binds": True}))
906+
assert "supply_from_date" not in compiled
907+
assert "supply_to_date" not in compiled
908+
909+
910+
@pytest.mark.anyio
911+
async def test_bulk_update_deactivate_takes_precedence_over_activate(repo, fake_db):
912+
"""
913+
When both deactivate=True and activate=True are passed, deactivate must win
914+
(is_active is set to False, not True).
915+
"""
916+
await repo.bulk_update_fse_reporting_record(
917+
charging_equipment_compliance_id=30,
918+
supply_from_date=None,
919+
supply_to_date=None,
920+
kwh_usage=None,
921+
compliance_notes=None,
922+
activate=True,
923+
deactivate=True,
924+
)
925+
926+
stmt = fake_db.execute.call_args[0][0]
927+
compiled = str(stmt.compile(compile_kwargs={"literal_binds": True}))
928+
assert "is_active" in compiled
929+
assert "false" in compiled.lower()

0 commit comments

Comments
 (0)