bug fix to avoid swallowing exceptions/failed pages inside fetch_all_pages/small refactor
This commit is contained in:
1 parent
321546f9b9
commit
b071ac35bf
17 files changed
+309
-1650
No files matched your search
@@ -122,3 +122,73 @@ def test_past_prices_read_through():
|
||||
product = build_product_details(_doc(pastPrices=history), min_percentage=0)
|
||||
|
||||
assert product.pricing.past_prices == history
|
||||
|
||||
|
||||
# ----------------------------------------------------------- bypass_thresholds
|
||||
|
||||
|
||||
def test_bypass_builds_a_below_threshold_product():
|
||||
"""A new listing sends at any discount when the caller says so."""
|
||||
|
||||
doc = _doc(currentPrice=95.0, originalPrice=100.0) # 5%, way under 40
|
||||
product = build_product_details(doc, min_percentage=40, bypass_thresholds=True)
|
||||
assert product is not None
|
||||
assert product.metadata.percentage == 5
|
||||
|
||||
|
||||
def test_bypass_defaults_off():
|
||||
doc = _doc(currentPrice=95.0, originalPrice=100.0)
|
||||
assert build_product_details(doc, min_percentage=40) is None
|
||||
|
||||
|
||||
def test_bypass_does_not_rescue_broken_prices():
|
||||
"""The missing-price skip is a data guard, not a threshold."""
|
||||
|
||||
doc = _doc(currentPrice=95.0, originalPrice=None)
|
||||
assert build_product_details(doc, min_percentage=40, bypass_thresholds=True) is None
|
||||
|
||||
|
||||
# --------------------------------------------------------------- newListing
|
||||
|
||||
|
||||
def test_new_listing_flag_reads_through():
|
||||
product = build_product_details(_doc(newListing=True), min_percentage=0)
|
||||
assert product.metadata.new_listing is True
|
||||
|
||||
|
||||
def test_legacy_docs_without_the_flag_build_as_none():
|
||||
"""Documents written before newListing existed must not KeyError."""
|
||||
|
||||
product = build_product_details(_doc(), min_percentage=0)
|
||||
assert product.metadata.new_listing is None
|
||||
|
||||
|
||||
# ------------------------------------------------------------ msrp-less guard
|
||||
|
||||
|
||||
def test_msrpless_doc_with_missing_original_price_skips_not_crashes():
|
||||
"""Regression: the guard lived inside the has_msrp branch, so this doc
|
||||
shape raised ValidationError (not an expected error) and killed the
|
||||
consumer."""
|
||||
|
||||
doc = _doc(hasMsrp=False, originalPrice=None)
|
||||
assert build_product_details(doc, min_percentage=40) is None
|
||||
|
||||
|
||||
def test_msrpless_doc_with_zero_original_price_skips():
|
||||
doc = _doc(hasMsrp=False, originalPrice=0)
|
||||
assert build_product_details(doc, min_percentage=40) is None
|
||||
|
||||
|
||||
def test_bypass_does_not_rescue_msrpless_broken_prices():
|
||||
doc = _doc(hasMsrp=False, originalPrice=None)
|
||||
assert build_product_details(doc, min_percentage=40, bypass_thresholds=True) is None
|
||||
|
||||
|
||||
def test_msrpless_doc_with_prices_builds_unthresholded():
|
||||
"""A priced MSRP-less doc still skips the threshold gate entirely."""
|
||||
|
||||
doc = _doc(hasMsrp=False, currentPrice=95.0, originalPrice=100.0) # 5% < 40
|
||||
product = build_product_details(doc, min_percentage=40)
|
||||
assert product is not None
|
||||
assert product.pricing.has_msrp is False
|
||||
Reference in new issue
Block a user