47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""unit test: calculate_priority ranks MSRP-less products instead of burying them
|
|
|
|
run from the repo root:
|
|
uv run --with pytest pytest tests/test_alert_priority.py
|
|
|
|
pure and offline — passes plain dicts shaped like product documents; touches no
|
|
Mongo. The claim query sorts priority descending, so a priority of 0 means an
|
|
alert is only drained once everything else is.
|
|
"""
|
|
|
|
from monitor_utils.database import NO_MSRP_PRIORITY, calculate_priority
|
|
|
|
|
|
def document(current, original, **overrides) -> dict:
|
|
doc = {"_id": "p1", "currentPrice": current, "originalPrice": original}
|
|
doc.update(overrides)
|
|
return doc
|
|
|
|
|
|
def test_no_msrp_takes_its_own_rank():
|
|
assert calculate_priority(document(50.0, 50.0, hasMsrp=False)) == NO_MSRP_PRIORITY
|
|
|
|
|
|
def test_no_msrp_rank_sits_directly_under_the_seventy_band():
|
|
"""It must outrank every sub-70% product and lose to every 70%+ one."""
|
|
assert calculate_priority(document(25.0, 100.0)) == 7 # 75% off
|
|
assert NO_MSRP_PRIORITY < 7
|
|
assert NO_MSRP_PRIORITY > calculate_priority(document(45.0, 100.0)) # 55% off
|
|
|
|
|
|
def test_msrp_products_are_unaffected():
|
|
assert calculate_priority(document(25.0, 100.0, hasMsrp=True)) == 7
|
|
assert calculate_priority(document(50.0, 100.0, hasMsrp=True)) == 5
|
|
|
|
|
|
def test_documents_without_the_field_keep_the_percentage_path():
|
|
"""Documents written before hasMsrp existed must not all jump the queue."""
|
|
assert calculate_priority(document(50.0, 100.0)) == 5
|
|
assert calculate_priority(document(100.0, 100.0)) == 0
|
|
|
|
|
|
def test_broken_prices_still_outrank_nothing():
|
|
"""A missing or zero original price is a data defect, not a missing MSRP."""
|
|
assert calculate_priority(document(50.0, None, hasMsrp=False)) == 0
|
|
assert calculate_priority(document(50.0, 0, hasMsrp=False)) == 0
|
|
assert calculate_priority(document(None, 100.0, hasMsrp=False)) == 0
|