@@ -40,6 +40,21 @@ def test_ignore_unwanted_parents(self):
4040 self .assertEqual (len (result_df ), 1 )
4141 self .assertEqual (result_df ["cpc" ][0 ], product .pk )
4242
43+ def test_excludes_r0113 (self ):
44+ # Create the unwanted product R0113 with a matching common name
45+ ClassifiedProductFactory (cpc = "R0113" , common_name_en = "Rice" , description_en = "Rice" )
46+ # Create the preferred product that we want the lookup to return, and include 'rice' as an alias
47+ preferred = ClassifiedProductFactory (cpc = "P23162" , common_name_en = "Husked Rice" , description_en = "Husked Rice" )
48+ preferred .aliases = ["arroz" , "rice" , "riz" ]
49+ preferred .save ()
50+
51+ df = pd .DataFrame ({"product" : ["rice" ]})
52+ result_df = ClassifiedProductLookup ().do_lookup (df , "product" , "cpc" )
53+ self .assertTrue ("cpc" in result_df .columns )
54+ self .assertEqual (len (result_df ), 1 )
55+ # The lookup should return the preferred product, not the unwanted R0113
56+ self .assertEqual (result_df ["cpc" ][0 ], preferred .pk )
57+
4358 # The child record doesn't could have the search term in a the common name instead of the description,
4459 # and the child doesn't need to be first child (with a 0 suffix). The child could have its own children,
4560 # that don't match the search term.
0 commit comments