Skip to content

Commit

Permalink
Merge pull request #243 from UKGovernmentBEIS/PC-533-eco4-eligibility…
Browse files Browse the repository at this point in the history
…-logic-changes

PC-533: Update ECO4 eligibility logic
  • Loading branch information
chidin194 authored Nov 2, 2023
2 parents 8d6d12c + 035ec1e commit c2394f2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 29 deletions.
30 changes: 16 additions & 14 deletions help_to_heat/frontdoor/eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

def calculate_eligibility(session_data):
"""
Calculate which schemes the user is able to use. Based literally on the logic in the Mural file
(hence why it is illogical)
:param session_data:
:return: A tuple of which schemes the person is eligible for, if any
"""
Expand All @@ -30,64 +28,68 @@ def calculate_eligibility(session_data):
country = session_data.get("country")
benefits = session_data.get("benefits")
property_type = session_data.get("property_type")
own_property = session_data.get("own_property")

# "Scenario 0"
if property_type == "Park home":
return ("GBIS",)

# Scenario 1
# ECO4 and GBIS scenario 1 - home owner
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["eligible"]:
if epc_rating in ("E", "F", "G", "Not found"):
if own_property in ("Yes, I own my property and live in it",):
if epc_rating in ("D", "E", "F", "G", "Not found"):
if benefits in ("Yes",):
logger.error("Scenario 1")
return ("GBIS", "ECO4")

# Scenario 2
# ECO4 and GBIS scenario 2 - private rented (tenant or landlord)
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["ineligible"]:
if own_property in (
"No, I am a tenant",
"Yes, I am the property owner but I lease the property to one or more tenants",
):
if epc_rating in ("E", "F", "G", "Not found"):
if benefits in ("Yes",):
logger.error("Scenario 2")
return ("GBIS", "ECO4")

# ECO4 and GBIS scenario 3 - social housing tenant
if country in country_council_tax_bands:
if own_property in ("No, I am a social housing tenant",):
if epc_rating in ("D", "E", "F", "G", "Not found"):
if benefits in ("Yes",):
return ("GBIS", "ECO4")

# Scenario 3
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["eligible"]:
if epc_rating in ("D", "E", "F", "G", "Not found"):
if benefits in ("No",):
logger.error("Scenario 3a")
return ("GBIS",)

if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["eligible"]:
if epc_rating in ("D", "Not Found"):
if benefits in ("Yes",):
logger.error("Scenario 3b")
return ("GBIS",)

# Scenario 3.1
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["ineligible"]:
if epc_rating in ("D", "Not Found"):
if benefits in ("Yes",):
logger.error("Scenario 3.1")
return ("GBIS",)

# Scenario 4
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["ineligible"]:
if epc_rating in ("D", "E", "F", "G"):
if benefits in ("No",):
logger.error("Scenario 4")
return ()

# Scenario 5
if country in country_council_tax_bands:
if council_tax_band in country_council_tax_bands[country]["ineligible"]:
if epc_rating in ("Not found"):
if benefits in ("No",):
logger.error("Scenario 5")
return ()

return ()
55 changes: 40 additions & 15 deletions tests/test_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,37 @@
scenarios = (
(
{
"council_tax_band": "F",
"benefits": "Yes",
"epc_rating": "F",
"epc_rating": "D",
"country": "England",
"own_property": "Yes, I own my property and live in it",
},
"BOTH",
),
(
{
"council_tax_band": "B",
"benefits": "Yes",
"epc_rating": "F",
"epc_rating": "G",
"country": "England",
"own_property": "Yes, I own my property and live in it",
},
"BOTH",
),
(
{
"council_tax_band": "G",
"benefits": "Yes",
"epc_rating": "F",
"epc_rating": "D",
"country": "England",
"own_property": "Yes, I own my property and live in it",
"own_property": "No, I am a social housing tenant",
},
"BOTH",
),
(
{
"benefits": "Yes",
"epc_rating": "E",
"country": "England",
"own_property": "No, I am a tenant",
},
"BOTH",
),
Expand Down Expand Up @@ -192,14 +198,14 @@ def test_eligibility_unknown_epc():
}


def test_mural_scenario_1():
def test_eco4_scenario_1():
for country in eligible_council_tax:
for council_tax_band in eligible_council_tax[country]["eligible"]:
for epc_rating in ("E", "F", "G"):
for own_property in ("Yes, I own my property and live in it",):
for epc_rating in ("D", "E", "F", "G", "Not found"):
for benefits in ("Yes",):
session_data = {
"epc_rating": epc_rating,
"council_tax_band": council_tax_band,
"own_property": own_property,
"country": country,
"benefits": benefits,
}
Expand All @@ -208,14 +214,33 @@ def test_mural_scenario_1():
assert result == expected


def test_mural_scenario_2():
def test_eco4_scenario_2():
for country in eligible_council_tax:
for council_tax_band in eligible_council_tax[country]["ineligible"]:
for epc_rating in ("E", "F", "G"):
for own_property in (
"No, I am a tenant",
"Yes, I am the property owner but I lease the property to one or more tenants",
):
for epc_rating in ("E", "F", "G", "Not found"):
for benefits in ("Yes",):
session_data = {
"epc_rating": epc_rating,
"council_tax_band": council_tax_band,
"own_property": own_property,
"country": country,
"benefits": benefits,
}
result = calculate_eligibility(session_data)
expected = result_map["BOTH"]
assert result == expected


def test_eco4_scenario_3():
for country in eligible_council_tax:
for own_property in ("No, I am a social housing tenant",):
for epc_rating in ("D", "E", "F", "G", "Not found"):
for benefits in ("Yes",):
session_data = {
"epc_rating": epc_rating,
"own_property": own_property,
"country": country,
"benefits": benefits,
}
Expand Down

0 comments on commit c2394f2

Please sign in to comment.