|
4 | 4 | import pandas as pd |
5 | 5 | from django.test import TestCase |
6 | 6 | from pipelines.assets.livelihood_activity import ( |
| 7 | + get_all_label_attributes, |
7 | 8 | get_label_attributes, |
8 | 9 | get_livelihood_activity_label_map, |
9 | 10 | ) |
10 | 11 |
|
| 12 | +from common.tests.factories import CountryFactory |
11 | 13 | from metadata.models import ActivityLabel |
| 14 | +from metadata.tests.factories import SeasonFactory |
12 | 15 |
|
13 | 16 | LIVELIHOOD_ACTIVITY = ActivityLabel.LivelihoodActivityType.LIVELIHOOD_ACTIVITY |
14 | 17 |
|
@@ -40,7 +43,7 @@ def test_livelihood_activity_regexes(self): |
40 | 43 | unwanted_attributes = { |
41 | 44 | k: v |
42 | 45 | 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"] |
44 | 47 | } |
45 | 48 |
|
46 | 49 | self.assertFalse( |
@@ -101,3 +104,39 @@ def test_activity_label_override(self): |
101 | 104 | ) |
102 | 105 | # Test that additional attributes set in the ActivityLabel instance are ignored when using the regex |
103 | 106 | 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