"""Integration tests for GET /carveout/{upc}/territory/structured. This endpoint optionally accepts GRASS auth headers (Grass-Account-Type / Grass-Account-Id). When neither is present the request proceeds without an ownership check; when only one is present, or the type is invalid, the GrassHeaders validator rejects the request with 400. Previously untested. """ import pytest from Integration.consts import api from Integration.utils import assert_ok # This endpoint validates a header schema (Content-Type + Correlation-Id, both # required) BEFORE the optional GRASS check, so every request must carry these # base headers to reach the endpoint's real behaviour. # See resources/json_schema/get_structured_territory_headers.json. _BASE_HEADERS = { "Content-Type": "application/json", "Correlation-Id": "it-structured-territory", } @pytest.mark.read def test_structured_territory_no_grass_headers(http): """With base headers but no GRASS auth, the endpoint returns carveouts.""" response = assert_ok( http.get(api.STRUCTURED_TERRITORY.format(upc=api.TERRITORY_UPC), headers=_BASE_HEADERS)) # Service returns a JSON payload; assert it parses (shape may be list/dict). assert response.json() is not None @pytest.mark.negative def test_structured_territory_missing_base_headers(http): """Missing the required Content-Type/Correlation-Id headers -> 400.""" response = http.get(api.STRUCTURED_TERRITORY.format(upc=api.TERRITORY_UPC)) assert response.status_code == 400, response.url @pytest.mark.negative def test_structured_territory_incomplete_grass_headers(http): """Providing only the account type (no id) must be rejected with 400.""" headers = dict(_BASE_HEADERS, **{api.GRASS_ACCOUNT_TYPE_HEADER: "vendor"}) response = http.get( api.STRUCTURED_TERRITORY.format(upc=api.TERRITORY_UPC), headers=headers) assert response.status_code == 400, response.url @pytest.mark.negative def test_structured_territory_invalid_account_type(http): """An unrecognised GRASS account type must be rejected with 400.""" headers = dict(_BASE_HEADERS, **{ api.GRASS_ACCOUNT_TYPE_HEADER: "not-a-real-type", api.GRASS_ACCOUNT_ID_HEADER: api.VENDOR_ID, }) response = http.get( api.STRUCTURED_TERRITORY.format(upc=api.TERRITORY_UPC), headers=headers) assert response.status_code == 400, response.url @pytest.mark.negative def test_structured_territory_non_numeric_upc_not_found(http): """upc is asserted as \\d+, so a non-numeric upc should 404.""" response = http.get(api.STRUCTURED_TERRITORY.format(upc="abc"), headers=_BASE_HEADERS) assert response.status_code == 404, response.url