@@ -589,7 +589,7 @@ def test_filter_by_wealth_characteristic(self):
589589 self .assertEqual (len (response .json ()), 1 )
590590
591591
592- class LivelihoodBaselineFacetedSearchViewTestCase (APITestCase ):
592+ class LivelihoodZoneBaselineFacetedSearchViewTestCase (APITestCase ):
593593 def setUp (self ):
594594 self .category1 = LivelihoodCategoryFactory ()
595595 self .baseline1 = LivelihoodZoneBaselineFactory (main_livelihood_category = self .category1 )
@@ -618,17 +618,38 @@ def setUp(self):
618618 wealth_group__livelihood_zone_baseline = self .baseline2 , wealth_characteristic = self .characteristic2
619619 )
620620 self .characteristic3 = WealthCharacteristicFactory ()
621- self .strategy = LivelihoodStrategyFactory (product = self .product1 )
621+ self .strategy = LivelihoodStrategyFactory (product = self .product1 , livelihood_zone_baseline = self . baseline3 )
622622 self .baseline = LivelihoodZoneBaselineFactory (main_livelihood_category = self .category1 )
623- self .url = reverse ("livelihood-baseline-faceted-search" )
623+ self .url = reverse ("livelihood-zone- baseline-faceted-search" )
624624
625625 def test_search_with_product (self ):
626626 # Test when search matches entries
627627 response = self .client .get (self .url , {"search" : self .product1 .description_en , "language" : "en" })
628628 self .assertEqual (response .status_code , 200 )
629- data = response .data
630- self .assertEqual (len (data ["products" ]), 1 )
631- self .assertEqual (data ["products" ][0 ]["count" ], 2 ) # 2 zones have this proudct
629+ search_data = response .data
630+ self .assertEqual (len (search_data ["products" ]), 1 )
631+ self .assertEqual (search_data ["products" ][0 ]["count" ], 2 ) # 2 zones have this product
632+ # confirm the product value is correct
633+ self .assertEqual (search_data ["products" ][0 ]["value" ], self .product1 .cpc )
634+ # Apply the filters to the baseline
635+ baseline_url = reverse ("livelihoodzonebaseline-list" )
636+ response = self .client .get (
637+ baseline_url , {search_data ["products" ][0 ]["filter" ]: search_data ["products" ][0 ]["value" ]}
638+ )
639+ self .assertEqual (response .status_code , 200 )
640+ self .assertEqual (len (json .loads (response .content )), 2 )
641+ data = json .loads (response .content )
642+ self .assertTrue (any (d ["name" ] == self .baseline1 .name for d in data ))
643+ self .assertTrue (any (d ["name" ] == self .baseline3 .name for d in data ))
644+ self .assertFalse (any (d ["name" ] == self .baseline2 .name for d in data ))
645+
646+ response = self .client .get (baseline_url , {search_data ["items" ][0 ]["filter" ]: search_data ["items" ][0 ]["value" ]})
647+ self .assertEqual (response .status_code , 200 )
648+ self .assertEqual (len (json .loads (response .content )), 1 )
649+ data = json .loads (response .content )
650+ self .assertTrue (any (d ["name" ] == self .baseline1 .name for d in data ))
651+ self .assertFalse (any (d ["name" ] == self .baseline2 .name for d in data ))
652+ self .assertFalse (any (d ["name" ] == self .baseline3 .name for d in data ))
632653 # Search by the second product
633654 response = self .client .get (
634655 self .url ,
@@ -637,8 +658,8 @@ def test_search_with_product(self):
637658 },
638659 )
639660 self .assertEqual (response .status_code , 200 )
640- data = response .data
641- self .assertEqual (len (data ["products" ]), 0 )
661+ search_data = response .data
662+ self .assertEqual (len (search_data ["products" ]), 0 )
642663
643664 def test_search_with_wealth_characterstics (self ):
644665 # Test when search matches entries
0 commit comments