Finalize purchase effective price fields
This commit is contained in:
@@ -8,6 +8,11 @@ import enrich_costco
|
||||
|
||||
|
||||
class PurchaseLogTests(unittest.TestCase):
|
||||
def test_derive_net_line_total_preserves_existing_then_derives(self):
|
||||
self.assertEqual("1.49", build_purchases.derive_net_line_total({"net_line_total": "1.49", "line_total": "2.98"}))
|
||||
self.assertEqual("5.99", build_purchases.derive_net_line_total({"line_total": "6.99", "matched_discount_amount": "-1.00"}))
|
||||
self.assertEqual("3.5", build_purchases.derive_net_line_total({"line_total": "3.50"}))
|
||||
|
||||
def test_derive_metrics_prefers_picked_weight_and_pack_count(self):
|
||||
metrics = build_purchases.derive_metrics(
|
||||
{
|
||||
@@ -161,6 +166,7 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
self.assertEqual("https://example.test/banana.jpg", rows[0]["image_url"])
|
||||
self.assertEqual("1", rows[0]["normalized_quantity"])
|
||||
self.assertEqual("lb", rows[0]["normalized_quantity_unit"])
|
||||
self.assertEqual("lb", rows[0]["effective_price_unit"])
|
||||
|
||||
def test_main_writes_purchase_and_example_csvs(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
@@ -576,10 +582,15 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
|
||||
rows_by_item = {row["normalized_item_id"]: row for row in rows}
|
||||
self.assertEqual("0.5893", rows_by_item["gnorm:banana"]["effective_price"])
|
||||
self.assertEqual("lb", rows_by_item["gnorm:banana"]["effective_price_unit"])
|
||||
self.assertEqual("0.4967", rows_by_item["cnorm:banana"]["effective_price"])
|
||||
self.assertEqual("lb", rows_by_item["cnorm:banana"]["effective_price_unit"])
|
||||
self.assertEqual("0.2495", rows_by_item["gnorm:ice"]["effective_price"])
|
||||
self.assertEqual("lb", rows_by_item["gnorm:ice"]["effective_price_unit"])
|
||||
self.assertEqual("26.99", rows_by_item["cnorm:patty"]["effective_price"])
|
||||
self.assertEqual("each", rows_by_item["cnorm:patty"]["effective_price_unit"])
|
||||
self.assertEqual("", rows_by_item["gnorm:patty"]["effective_price"])
|
||||
self.assertEqual("", rows_by_item["gnorm:patty"]["effective_price_unit"])
|
||||
|
||||
def test_build_purchase_rows_leaves_effective_price_blank_without_valid_denominator(self):
|
||||
fieldnames = enrich_costco.OUTPUT_FIELDS
|
||||
@@ -611,6 +622,7 @@ class PurchaseLogTests(unittest.TestCase):
|
||||
|
||||
rows, _links = build_purchases.build_purchase_rows([row], [], [], [], [], [], [])
|
||||
self.assertEqual("", rows[0]["effective_price"])
|
||||
self.assertEqual("", rows[0]["effective_price_unit"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user