Improve product review display workflow
This commit is contained in:
@@ -41,6 +41,7 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
"order_date": "2026-03-01",
|
||||
"item_name": "FRESH BANANA",
|
||||
"item_name_norm": "BANANA",
|
||||
"image_url": "https://example.test/banana.jpg",
|
||||
"retailer_item_id": "100",
|
||||
"upc": "4011",
|
||||
"qty": "1",
|
||||
@@ -99,24 +100,18 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
}
|
||||
]
|
||||
|
||||
<<<<<<< HEAD
|
||||
rows, _observed, _canon, _links = build_purchases.build_purchase_rows(
|
||||
=======
|
||||
rows = build_purchases.build_purchase_rows(
|
||||
>>>>>>> be1bf63 (Build pivot-ready purchase log)
|
||||
[giant_row],
|
||||
[costco_row],
|
||||
giant_orders,
|
||||
costco_orders,
|
||||
<<<<<<< HEAD
|
||||
[],
|
||||
=======
|
||||
>>>>>>> be1bf63 (Build pivot-ready purchase log)
|
||||
)
|
||||
|
||||
self.assertEqual(2, len(rows))
|
||||
self.assertTrue(all(row["canonical_product_id"] for row in rows))
|
||||
self.assertEqual({"giant", "costco"}, {row["retailer"] for row in rows})
|
||||
self.assertEqual("https://example.test/banana.jpg", rows[0]["image_url"])
|
||||
|
||||
def test_main_writes_purchase_and_example_csvs(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
@@ -124,11 +119,13 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
costco_items = Path(tmpdir) / "costco_items.csv"
|
||||
giant_orders = Path(tmpdir) / "giant_orders.csv"
|
||||
costco_orders = Path(tmpdir) / "costco_orders.csv"
|
||||
resolutions_csv = Path(tmpdir) / "review_resolutions.csv"
|
||||
catalog_csv = Path(tmpdir) / "canonical_catalog.csv"
|
||||
links_csv = Path(tmpdir) / "product_links.csv"
|
||||
purchases_csv = Path(tmpdir) / "combined" / "purchases.csv"
|
||||
examples_csv = Path(tmpdir) / "combined" / "comparison_examples.csv"
|
||||
|
||||
fieldnames = enrich_costco.OUTPUT_FIELDS
|
||||
rows = []
|
||||
giant_row = {field: "" for field in fieldnames}
|
||||
giant_row.update(
|
||||
{
|
||||
@@ -178,7 +175,6 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
"is_fee": "false",
|
||||
}
|
||||
)
|
||||
rows.extend([giant_row, costco_row])
|
||||
|
||||
for path, source_rows in [
|
||||
(giant_items, [giant_row]),
|
||||
@@ -189,12 +185,35 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
writer.writeheader()
|
||||
writer.writerows(source_rows)
|
||||
|
||||
order_fields = ["order_id", "store_name", "store_number", "store_city", "store_state"]
|
||||
for path, source_rows in [
|
||||
(giant_orders, [{"order_id": "g1", "store_name": "Giant", "store_number": "42", "store_city": "Springfield", "store_state": "VA"}]),
|
||||
(costco_orders, [{"order_id": "c1", "store_name": "MT VERNON", "store_number": "1115", "store_city": "ALEXANDRIA", "store_state": "VA"}]),
|
||||
(
|
||||
giant_orders,
|
||||
[
|
||||
{
|
||||
"order_id": "g1",
|
||||
"store_name": "Giant",
|
||||
"store_number": "42",
|
||||
"store_city": "Springfield",
|
||||
"store_state": "VA",
|
||||
}
|
||||
],
|
||||
),
|
||||
(
|
||||
costco_orders,
|
||||
[
|
||||
{
|
||||
"order_id": "c1",
|
||||
"store_name": "MT VERNON",
|
||||
"store_number": "1115",
|
||||
"store_city": "ALEXANDRIA",
|
||||
"store_state": "VA",
|
||||
}
|
||||
],
|
||||
),
|
||||
]:
|
||||
with path.open("w", newline="", encoding="utf-8") as handle:
|
||||
writer = csv.DictWriter(handle, fieldnames=["order_id", "store_name", "store_number", "store_city", "store_state"])
|
||||
writer = csv.DictWriter(handle, fieldnames=order_fields)
|
||||
writer.writeheader()
|
||||
writer.writerows(source_rows)
|
||||
|
||||
@@ -203,12 +222,9 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
costco_items_enriched_csv=str(costco_items),
|
||||
giant_orders_csv=str(giant_orders),
|
||||
costco_orders_csv=str(costco_orders),
|
||||
<<<<<<< HEAD
|
||||
resolutions_csv=str(Path(tmpdir) / "review_resolutions.csv"),
|
||||
catalog_csv=str(Path(tmpdir) / "canonical_catalog.csv"),
|
||||
links_csv=str(Path(tmpdir) / "product_links.csv"),
|
||||
=======
|
||||
>>>>>>> be1bf63 (Build pivot-ready purchase log)
|
||||
resolutions_csv=str(resolutions_csv),
|
||||
catalog_csv=str(catalog_csv),
|
||||
links_csv=str(links_csv),
|
||||
output_csv=str(purchases_csv),
|
||||
examples_csv=str(examples_csv),
|
||||
)
|
||||
@@ -222,7 +238,6 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
self.assertEqual(2, len(purchase_rows))
|
||||
self.assertEqual(1, len(example_rows))
|
||||
|
||||
<<<<<<< HEAD
|
||||
def test_build_purchase_rows_applies_manual_resolution(self):
|
||||
fieldnames = enrich_costco.OUTPUT_FIELDS
|
||||
giant_row = {field: "" for field in fieldnames}
|
||||
@@ -255,7 +270,15 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
rows, _observed, _canon, _links = build_purchases.build_purchase_rows(
|
||||
[giant_row],
|
||||
[],
|
||||
[{"order_id": "g1", "store_name": "Giant", "store_number": "42", "store_city": "Springfield", "store_state": "VA"}],
|
||||
[
|
||||
{
|
||||
"order_id": "g1",
|
||||
"store_name": "Giant",
|
||||
"store_number": "42",
|
||||
"store_city": "Springfield",
|
||||
"store_state": "VA",
|
||||
}
|
||||
],
|
||||
[],
|
||||
[
|
||||
{
|
||||
@@ -273,8 +296,6 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
self.assertEqual("approved", rows[0]["review_status"])
|
||||
self.assertEqual("create", rows[0]["resolution_action"])
|
||||
|
||||
=======
|
||||
>>>>>>> be1bf63 (Build pivot-ready purchase log)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user