Skip to content

Commit b8c0676

Browse files
committed
Add unit test for sub-national seasons - see HEA-196
1 parent ac86666 commit b8c0676

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

pipelines_tests/test_assets/test_livelihood_activity_assets.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import pandas as pd
55
from django.test import TestCase
66
from pipelines.assets.livelihood_activity import (
7+
get_all_label_attributes,
78
get_label_attributes,
89
get_livelihood_activity_label_map,
910
)
1011

12+
from common.tests.factories import CountryFactory
1113
from metadata.models import ActivityLabel
14+
from metadata.tests.factories import SeasonFactory
1215

1316
LIVELIHOOD_ACTIVITY = ActivityLabel.LivelihoodActivityType.LIVELIHOOD_ACTIVITY
1417

@@ -40,7 +43,7 @@ def test_livelihood_activity_regexes(self):
4043
unwanted_attributes = {
4144
k: v
4245
for k, v in attributes.items()
43-
if k not in expected_attributes and k not in ["activity_label", "notes"]
46+
if k not in expected_attributes and k not in ["activity_label", "status", "notes"]
4447
}
4548

4649
self.assertFalse(
@@ -101,3 +104,39 @@ def test_activity_label_override(self):
101104
)
102105
# Test that additional attributes set in the ActivityLabel instance are ignored when using the regex
103106
self.assertEqual("", regex_attributes["season"])
107+
108+
def test_zone_specific_season_alias(self):
109+
country = CountryFactory()
110+
livelihood_zone_id = f"{country.iso3166a2}04"
111+
112+
general_season = SeasonFactory(
113+
country=country,
114+
name_en=f"{country.iso_en_ro_name}, Harvest",
115+
aliases=["season 1"],
116+
purpose=None,
117+
)
118+
zone_specific_season = SeasonFactory(
119+
country=country,
120+
name_en=f"{country.iso_en_ro_name}, Southern Unimodal, Harvest",
121+
aliases=[f"season 1 ({livelihood_zone_id.lower()})"],
122+
purpose=None,
123+
)
124+
125+
# Test that the zone-specific season alias is matched when looking up attributes for that Zone.
126+
attributes_df = get_all_label_attributes(
127+
labels=pd.Series(["season 1: lactation period (days)"]),
128+
activity_type=LIVELIHOOD_ACTIVITY,
129+
country_code=country.iso3166a2,
130+
livelihood_zone_id=livelihood_zone_id,
131+
)
132+
self.assertEqual(attributes_df.loc[0, "season"], zone_specific_season.name_en)
133+
134+
# Test that the general season alias is matched when looking up attributes for a different Zone.
135+
livelihood_zone_id = f"{country.iso3166a2}05"
136+
attributes_df = get_all_label_attributes(
137+
labels=pd.Series(["season 1: lactation period (days)"]),
138+
activity_type=LIVELIHOOD_ACTIVITY,
139+
country_code=country.iso3166a2,
140+
livelihood_zone_id=livelihood_zone_id,
141+
)
142+
self.assertEqual(attributes_df.loc[0, "season"], general_season.name_en)

0 commit comments

Comments
 (0)