Skip to content

Commit

Permalink
Updated pytests to include provisionOfTheAct as required field.
Browse files Browse the repository at this point in the history
  • Loading branch information
areyeslo committed Dec 30, 2024
1 parent 5528a8f commit 147a234
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ async def test_create_fuel_export_success(
}
created_export.fuel_category = {"category": "Diesel"}
created_export.units = "Litres"
created_export.provision_of_the_act = {
"provision_of_the_act_id": 3,
"name": "Test Provision"
}
mock_repo.create_fuel_export.return_value = created_export

# Call the method under test
Expand Down Expand Up @@ -190,6 +194,10 @@ async def test_update_fuel_export_success_existing_report(
}
existing_export.fuel_category = {"category": "Diesel"}
existing_export.units = "Litres"
existing_export.provision_of_the_act = {
"provision_of_the_act_id": 123,
"name": "Test Provision"
}
mock_repo.get_fuel_export_version_by_user.return_value = existing_export

# Mock the response from get_standardized_fuel_data
Expand All @@ -214,6 +222,11 @@ async def test_update_fuel_export_success_existing_report(
}
updated_export.fuel_category = {"category": "Diesel"}
updated_export.units = "Litres"

updated_export.provision_of_the_act = {
"provision_of_the_act_id": 123,
"name": "Test Provision"
}
mock_repo.update_fuel_export.return_value = updated_export

# Call the method under test
Expand Down Expand Up @@ -256,6 +269,10 @@ async def test_update_fuel_export_create_new_version(
}
existing_export.fuel_category = {"category": "Diesel"}
existing_export.units = "Litres"
existing_export.provision_of_the_act = {
"provision_of_the_act_id": 123,
"name": "Test Provision"
}
mock_repo.get_fuel_export_version_by_user.return_value = existing_export

# Mock the response from get_standardized_fuel_data
Expand All @@ -281,6 +298,10 @@ async def test_update_fuel_export_create_new_version(
}
new_export.fuel_category = {"category": "Diesel"}
new_export.units = "Litres"
new_export.provision_of_the_act = {
"provision_of_the_act_id": 123,
"name": "Test Provision"
}
mock_repo.create_fuel_export.return_value = new_export

# Call the method under test
Expand Down Expand Up @@ -458,6 +479,7 @@ async def test_compliance_units_calculation(
group_uuid=str(uuid4()),
version=0,
provisionOfTheActId=123,
provisionOfTheAct={"provision_of_the_act_id": 123, "name": "Test Provision"},
exportDate=datetime.now().date(),
)

Expand Down Expand Up @@ -488,6 +510,11 @@ async def create_fuel_export_side_effect(fuel_export: FuelExport):
fuel_export.fuel_category = {"category": "Diesel"}
fuel_export.units = "Litres"

fuel_export.provision_of_the_act = {
"provision_of_the_act_id": fuel_export.provision_of_the_act_id,
"name": "Test Provision"
}

# The service should have already calculated compliance_units
return fuel_export

Expand Down
17 changes: 17 additions & 0 deletions backend/lcfs/tests/fuel_export/test_fuel_exports_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ async def test_get_fuel_export_list_success(fuel_export_service, mock_repo):
export_date=date.today(),
group_uuid="test-uuid",
provision_of_the_act_id=1,
provision_of_the_act={
"provision_of_the_act_id": 1,
"name": "Test Provision"
},
version=0,
user_type=UserTypeEnum.SUPPLIER,
action_type=ActionTypeEnum.CREATE,
Expand All @@ -81,6 +85,11 @@ async def test_get_fuel_exports_paginated_success(fuel_export_service, mock_repo
quantity=100,
units="L",
export_date=date.today(),
provision_of_the_act_id=1,
provision_of_the_act={
"provision_of_the_act_id": 1,
"name": "Test Provision"
},
)
mock_repo.get_fuel_exports_paginated.return_value = ([mock_export], 1)

Expand Down Expand Up @@ -122,6 +131,10 @@ async def test_action_create_fuel_export_success(fuel_export_action_service, moc
user_type=UserTypeEnum.SUPPLIER,
action_type=ActionTypeEnum.CREATE,
provision_of_the_act_id=1,
provision_of_the_act={
"provision_of_the_act_id": 1,
"name": "Act Provision"
},
fuel_type_id=1,
fuel_category_id=1,
quantity=100,
Expand Down Expand Up @@ -168,6 +181,10 @@ async def test_action_update_fuel_export_success(fuel_export_action_service, moc
fuel_type_id=1,
fuel_category_id=1,
provision_of_the_act_id=1,
provision_of_the_act={
"provision_of_the_act_id": 1,
"name": "Act Provision"
},
quantity=100,
units="L",
export_date=date.today(),
Expand Down
10 changes: 10 additions & 0 deletions backend/lcfs/tests/fuel_export/test_fuel_exports_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ async def test_save_fuel_export_row_update_success(client, fastapi_app, set_mock
export_date="2024-01-01",
fuel_category_id=1,
fuel_category=FuelCategoryResponseSchema(category="Diesel"),
provisionOfTheActId=1,
provisionOfTheAct={
"provision_of_the_act_id": 1,
"name": "Test Provision"
}
)

# Create update payload with all required fields
Expand Down Expand Up @@ -301,6 +306,11 @@ async def test_save_fuel_export_row_create_success(client, fastapi_app, set_mock
export_date="2024-01-01",
fuel_category_id=1,
fuel_category=FuelCategoryResponseSchema(category="Diesel"),
provisionOfTheActId=1,
provisionOfTheAct={
"provision_of_the_act_id": 1,
"name": "Section 6"
}
)

mock_validate_organization_access.return_value = None
Expand Down

0 comments on commit 147a234

Please sign in to comment.