product json updates
This commit is contained in:
@@ -223,9 +223,41 @@ def test_the_brand_match_is_case_insensitive(mirror):
|
||||
nutrition_score_sync.sync_scores_to_brand_tables()
|
||||
|
||||
for sql, params in mirror.calls:
|
||||
assert "lower(i.brand) = lower(%s)" in sql
|
||||
assert "= lower(%s)" in sql
|
||||
assert params == ("Cadbury",)
|
||||
assert "i.brand = %s" not in sql
|
||||
assert "brand = %s" not in sql
|
||||
|
||||
|
||||
def test_a_brand_spelled_two_ways_resolves_to_one_row(mirror):
|
||||
"""`nutrition_insights` really does hold both 'Grb' and 'GRB' for the same
|
||||
eleven products, written by two enrichment runs a month apart and carrying
|
||||
different scores. Folding the brand matches both, and `UPDATE ... FROM`
|
||||
against a multi-row match picks an arbitrary one - so the mirror wrote a
|
||||
different value on every run. Caught by re-running the sync and watching
|
||||
rows change again, which is the whole reason the idempotence test earns
|
||||
its place.
|
||||
"""
|
||||
nutrition_score_sync.sync_scores_to_brand_tables()
|
||||
|
||||
copy_sql = mirror.calls[0][0]
|
||||
assert "SELECT DISTINCT ON (image_id)" in copy_sql
|
||||
|
||||
|
||||
def test_a_real_score_beats_a_null_and_then_the_newest_wins(mirror):
|
||||
"""The tie-break, stated as an assertion.
|
||||
|
||||
A NULL is the absence of a measurement, not a measurement of absence, so
|
||||
it must never overwrite a known score just by being more recent - the same
|
||||
instinct as the COALESCE in the Excel upload's upsert.
|
||||
"""
|
||||
nutrition_score_sync.sync_scores_to_brand_tables()
|
||||
|
||||
copy_sql = mirror.calls[0][0]
|
||||
order = copy_sql[copy_sql.index("ORDER BY"):]
|
||||
assert "(health_score IS NOT NULL) DESC" in order
|
||||
assert "generated_at DESC" in order
|
||||
assert order.index("health_score IS NOT NULL") < order.index("generated_at")
|
||||
|
||||
|
||||
def test_the_mirror_uses_is_distinct_from_so_a_second_run_is_a_no_op(mirror):
|
||||
|
||||
Reference in New Issue
Block a user