tidy up tests, fix price detection

pull/2041/head
dgtlmoon 4 months ago
parent fbfacd57a3
commit 50f00a205a

@ -53,15 +53,19 @@ def get_itemprop_availability(html_content) -> Restock:
value = Restock() value = Restock()
if data: if data:
logger.debug(f"Using jsonpath to find price/availability/etc") logger.debug(f"Using jsonpath to find price/availability/etc")
price_parse = parse('$..(price|Price|highPrice)') price_parse = parse('$..(price|Price)')
pricecurrency_parse = parse('$..(pricecurrency|currency|priceCurrency )') pricecurrency_parse = parse('$..(pricecurrency|currency|priceCurrency )')
availability_parse = parse('$..(availability|Availability)') availability_parse = parse('$..(availability|Availability)')
price_result = price_parse.find(data) price_result = price_parse.find(data)
if price_result: if price_result:
if len(price_result) > 1 and len(set(str(item.value).replace('$', '') for item in price_result)) > 1: # Right now, we just support single product items, maybe we will store the whole actual metadata seperately in teh future and
# parse that for the UI?
prices_found = set(str(item.value).replace('$', '') for item in price_result)
if len(price_result) > 1 and len(prices_found) > 1:
# See of all prices are different, in the case that one product has many embedded data types with the same price # See of all prices are different, in the case that one product has many embedded data types with the same price
# One might have $121.95 and another 121.95 etc # One might have $121.95 and another 121.95 etc
logger.warning(f"More than one price found {prices_found}, throwing exception, cant use this plugin.")
raise MoreThanOnePriceFound() raise MoreThanOnePriceFound()
value['price'] = price_result[0].value value['price'] = price_result[0].value

@ -100,12 +100,8 @@ def test_check_ldjson_price_autodetect(client, live_server, measure_memory_usage
# Accept it # Accept it
uuid = extract_UUID_from_client(client) uuid = extract_UUID_from_client(client)
time.sleep(1) #time.sleep(1)
client.get(url_for('price_data_follower.accept', uuid=uuid, follow_redirects=True)) client.get(url_for('price_data_follower.accept', uuid=uuid, follow_redirects=True))
wait_for_all_checks(client)
# Trigger a check
time.sleep(1)
client.get(url_for("form_watch_checknow"), follow_redirects=True) client.get(url_for("form_watch_checknow"), follow_redirects=True)
wait_for_all_checks(client) wait_for_all_checks(client)
# Offer should be gone # Offer should be gone
@ -120,8 +116,8 @@ def test_check_ldjson_price_autodetect(client, live_server, measure_memory_usage
headers={'x-api-key': api_key}, headers={'x-api-key': api_key},
) )
# Should see this (dont know where the whitespace came from) assert b'8097000' in res.data
assert b'"highPrice": 8099900' in res.data
# And not this cause its not the ld-json # And not this cause its not the ld-json
assert b"So let's see what happens" not in res.data assert b"So let's see what happens" not in res.data

Loading…
Cancel
Save