"""Integration tests for the combined projection endpoint. GET /carveout/projection/{upc}/dms/{dms_id} returns the evaluated set of territories a release can be delivered to for a given store, along with an ``empty_reason`` when the set is empty. Previously untested. """ import pytest from Integration.consts import api from Integration.utils import assert_ok @pytest.mark.read def test_projection_shape(http): """Projection returns the documented {empty_reason, territories} shape.""" response = assert_ok( http.get(api.PROJECTION.format(upc=api.UPC, dms_id=api.DMS_ID))) body = response.json() assert "empty_reason" in body assert "territories" in body assert isinstance(body["territories"], list) # Exactly one of the two states must hold: either we have territories, or # an explanatory reason for why the projection is empty. assert bool(body["territories"]) ^ (body["empty_reason"] is not None) @pytest.mark.read def test_projection_unknown_upc_is_empty_with_reason(http): """An unknown (but numeric) upc routes (200) and yields an empty projection with a populated empty_reason rather than 404.""" response = assert_ok( http.get(api.PROJECTION.format(upc="000000000000", dms_id=api.DMS_ID))) body = response.json() assert body["territories"] == [] assert body["empty_reason"] is not None @pytest.mark.negative def test_projection_non_numeric_upc_not_found(http): """upc is asserted as \\d+, so a non-numeric upc should 404.""" response = http.get(api.PROJECTION.format(upc="abc", dms_id=api.DMS_ID)) assert response.status_code == 404, response.url @pytest.mark.negative def test_projection_non_numeric_dms_not_found(http): """dms_id is asserted as \\d+, so a non-numeric dms_id should 404.""" response = http.get(api.PROJECTION.format(upc=api.UPC, dms_id="abc")) assert response.status_code == 404, response.url