removed timeout from send_request and added promo options to product metadata
This commit is contained in:
1 parent
4b63a2d39c
commit
b876c3d7b3
3 files changed
+71
-3
No files matched your search
@@ -11,15 +11,16 @@ Product), which is why convert_product_to_mongo no longer coerces them itself.
|
||||
from datetime import datetime
|
||||
|
||||
from monitor_utils.database import convert_product_to_mongo
|
||||
from monitor_utils.models import PricingInfo, Product
|
||||
from monitor_utils.models import PricingInfo, Product, ProductMetadata
|
||||
|
||||
|
||||
def _product(**pricing) -> Product:
|
||||
def _product(metadata: ProductMetadata | None = None, **pricing) -> Product:
|
||||
return Product(
|
||||
product_id="p1",
|
||||
title="Widget",
|
||||
url="http://x/p1",
|
||||
pricing=PricingInfo(**pricing),
|
||||
metadata=metadata or ProductMetadata(),
|
||||
)
|
||||
|
||||
|
||||
@@ -46,3 +47,57 @@ def test_core_fields_map_through():
|
||||
doc = convert_product_to_mongo(_product(original_price=200.0, current_price=150.0))
|
||||
assert doc["title"] == "Widget"
|
||||
assert doc["url"] == "http://x/p1"
|
||||
|
||||
|
||||
def test_promo_and_affiliate_fields_serialize():
|
||||
"""promo specifics + affiliate url reach the document under camelCase keys"""
|
||||
|
||||
doc = convert_product_to_mongo(
|
||||
_product(
|
||||
metadata=ProductMetadata(
|
||||
affiliate_url="http://aff/p1",
|
||||
promo_code="BIRTHDAY26",
|
||||
promo_percentage=22,
|
||||
promo_dollar_off=None,
|
||||
promo_min_spend=None,
|
||||
),
|
||||
original_price=200.0,
|
||||
current_price=150.0,
|
||||
)
|
||||
)
|
||||
assert doc["affiliateUrl"] == "http://aff/p1"
|
||||
assert doc["promoCode"] == "BIRTHDAY26"
|
||||
assert doc["promoPercentage"] == 22
|
||||
assert doc["promoDollarOff"] is None
|
||||
assert doc["promoMinSpend"] is None
|
||||
|
||||
|
||||
def test_dollar_promo_fields_serialize():
|
||||
"""a spend-threshold code stores amount + min spend, not a percentage"""
|
||||
|
||||
doc = convert_product_to_mongo(
|
||||
_product(
|
||||
metadata=ProductMetadata(
|
||||
promo_code="STORE22",
|
||||
promo_dollar_off=22,
|
||||
promo_min_spend=100,
|
||||
),
|
||||
original_price=200.0,
|
||||
current_price=150.0,
|
||||
)
|
||||
)
|
||||
assert doc["promoCode"] == "STORE22"
|
||||
assert doc["promoDollarOff"] == 22
|
||||
assert doc["promoMinSpend"] == 100
|
||||
assert doc["promoPercentage"] is None
|
||||
|
||||
|
||||
def test_promo_fields_default_to_none():
|
||||
"""a product with no promo still carries the keys as None (uniform doc shape)"""
|
||||
|
||||
doc = convert_product_to_mongo(_product(original_price=200.0, current_price=150.0))
|
||||
for key in ("promoCode", "promoPercentage", "promoDollarOff", "promoMinSpend"):
|
||||
assert doc[key] is None
|
||||
# percentage and channelId stay OUT of the doc on purpose
|
||||
assert "percentage" not in doc
|
||||
assert "channelId" not in doc
|
||||
Reference in new issue
Block a user