Skip to content

Commit c85616f

Browse files
committed
Add rice unit test for ClassifiedProductLookup - see HEA-797
1 parent c2f86a5 commit c85616f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

apps/common/tests/test_lookups.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)