"""Ingest guards: the checks that refuse bad data rather than publishing it."""

import pytest

from app.services.ingest import _sizes_disagree


class TestSizeVeto:
    """A barcode is identity -- unless the sizes flatly disagree, in which case
    the retailer mislabelled it. Trusting one put a 70cl liqueur's price on a
    1L whisky's page as its 'cheapest'."""

    @pytest.mark.parametrize(("a", "b"), [(1000, 700), (250, 750), (700, 1750)])
    def test_materially_different_sizes_are_vetoed(self, a, b):
        assert _sizes_disagree(a, b)

    @pytest.mark.parametrize(("a", "b"), [(700, 750), (750, 700), (1000, 1000)])
    def test_the_700_750_sloppiness_is_tolerated(self, a, b):
        """Feeds are casually inconsistent between 70cl and 750ml for the same
        bottle; vetoing those would fragment the catalogue instead of protecting it."""
        assert not _sizes_disagree(a, b)

    @pytest.mark.parametrize(("a", "b"), [(None, 700), (700, None), (None, None)])
    def test_an_unknown_size_never_vetoes(self, a, b):
        """Absence of a fact is not evidence of a mismatch."""
        assert not _sizes_disagree(a, b)
