@@ -739,7 +739,11 @@ def setUp(self):
739739 common_name_en = "common mukera" ,
740740 kcals_per_unit = 550 ,
741741 )
742- LivelihoodStrategyFactory (product = self .product1 , livelihood_zone_baseline = self .baseline1 )
742+ LivelihoodStrategyFactory (
743+ product = self .product1 ,
744+ livelihood_zone_baseline = self .baseline1 ,
745+ strategy_type = LivelihoodStrategyType .FOOD_PURCHASE ,
746+ )
743747 self .characteristic1 = WealthCharacteristicFactory (description_en = "my test" )
744748 self .characteristic2 = WealthCharacteristicFactory (description_en = "my mukera" , description_fr = "my test" )
745749 WealthGroupCharacteristicValueFactory (
@@ -749,7 +753,11 @@ def setUp(self):
749753 wealth_group__livelihood_zone_baseline = self .baseline2 , wealth_characteristic = self .characteristic2
750754 )
751755 self .characteristic3 = WealthCharacteristicFactory ()
752- self .strategy = LivelihoodStrategyFactory (product = self .product1 , livelihood_zone_baseline = self .baseline3 )
756+ self .strategy = LivelihoodStrategyFactory (
757+ product = self .product1 ,
758+ livelihood_zone_baseline = self .baseline3 ,
759+ strategy_type = LivelihoodStrategyType .FOOD_PURCHASE ,
760+ )
753761 self .baseline = LivelihoodZoneBaselineFactory (main_livelihood_category = self .category1 )
754762 self .url = reverse ("livelihood-zone-baseline-faceted-search" )
755763
@@ -897,15 +905,6 @@ def test_search_with_livelihood_strategy_type(self):
897905 self .assertIn ("livelihood_zone__code" , baselines [0 ])
898906 self .assertIn ("reference_year_end_date" , baselines [0 ])
899907
900- # Test that search "lait" with language=fr returns MilkProduction via French translation
901- response = self .client .get (self .url , {"search" : "lait" , "language" : "fr" })
902- self .assertEqual (response .status_code , 200 )
903- data = response .data
904- strategy_type_results = data ["livelihood_strategy_types" ]
905- milk_results = [r for r in strategy_type_results if r ["value" ] == "MilkProduction" ]
906- self .assertEqual (len (milk_results ), 1 )
907- self .assertEqual (milk_results [0 ]["value_label" ], "Production du lait" )
908-
909908 # Test that search "goat" returns multiple goat-related products
910909 response = self .client .get (self .url , {"search" : "goat" , "language" : "en" })
911910 self .assertEqual (response .status_code , 200 )
@@ -917,6 +916,29 @@ def test_search_with_livelihood_strategy_type(self):
917916 self .assertIn (goat_milk_product .cpc , product_cpcs )
918917 self .assertEqual (len (product_results ), 3 )
919918
919+ # Test that searching the French strategy type label "viande" matches MeatProduction
920+ response = self .client .get (self .url , {"search" : "viande" , "language" : "fr" })
921+ self .assertEqual (response .status_code , 200 )
922+ data = response .data
923+ strategy_type_results = data ["livelihood_strategy_types" ]
924+ meat_results = [r for r in strategy_type_results if r ["value" ] == "MeatProduction" ]
925+ self .assertEqual (len (meat_results ), 1 )
926+ self .assertEqual (meat_results [0 ]["value_label" ], "Production de viande" )
927+ self .assertEqual (meat_results [0 ]["count" ], 1 )
928+ baselines = meat_results [0 ]["livelihood_zone_baselines" ]
929+ self .assertEqual (len (baselines ), 1 )
930+ self .assertEqual (baselines [0 ]["id" ], self .baseline2 .id )
931+
932+ # Test that searching "lait" with language=fr matches MilkProduction via French translation
933+ response = self .client .get (self .url , {"search" : "lait" , "language" : "fr" })
934+ self .assertEqual (response .status_code , 200 )
935+ data = response .data
936+ strategy_type_results = data ["livelihood_strategy_types" ]
937+ milk_results = [r for r in strategy_type_results if r ["value" ] == "MilkProduction" ]
938+ self .assertEqual (len (milk_results ), 1 )
939+ self .assertEqual (milk_results [0 ]["value_label" ], "Production de lait" )
940+ self .assertEqual (milk_results [0 ]["count" ], 1 )
941+
920942 # test taht strategy_type filter to baseline list endpoint
921943 baseline_url = reverse ("livelihoodzonebaseline-list" )
922944 response = self .client .get (baseline_url , {"strategy_type" : "MilkProduction" })
0 commit comments