"""Integration tests for the store-listing endpoints. Covers /store/{id}, /stores/{classification} and /stores/grats, which were previously untested (only /stores had coverage in test_api.py). """ import pytest from Integration.consts import api from Integration.utils import assert_ok, is_int @pytest.mark.read def test_store_by_id(http): """Get a single store by id.""" response = assert_ok(http.get(api.STORE_BY_ID.format(store_id=api.STORE_ID))) body = response.json() # The store record should be a non-empty structure for a known store id. assert body, "expected a non-empty store record for id {}".format(api.STORE_ID) @pytest.mark.read @pytest.mark.parametrize("classification", api.STORE_CLASSIFICATIONS) def test_stores_by_classification(http, classification): """Get stores filtered by each supported classification.""" response = assert_ok( http.get(api.STORES_BY_CLASSIFICATION.format(classification=classification))) body = response.json() # Response is a dms_id -> store_name map; allow empty but require a dict. assert isinstance(body, dict) bad = [k for k in body if not is_int(k)] assert not bad, "non-integer keys for {}: {}".format(classification, bad) @pytest.mark.read def test_stores_classification_case_insensitive(http): """The classification route is declared case-insensitive in RoutesLoader.""" response = http.get(api.STORES_BY_CLASSIFICATION.format(classification="Physical")) assert response.status_code == 200, response.url assert isinstance(response.json(), dict) @pytest.mark.read def test_stores_grats(http): """Get the instant-grats stores list.""" response = assert_ok(http.get(api.STORES_GRATS)) assert isinstance(response.json(), dict) @pytest.mark.negative def test_stores_invalid_classification_not_found(http): """An unsupported classification does not match the asserted route -> 404.""" response = http.get(api.STORES_BY_CLASSIFICATION.format(classification="bogus")) assert response.status_code == 404, response.url @pytest.mark.negative def test_store_by_id_non_numeric_not_found(http): """store_id is asserted as \\d+, so a non-numeric id should 404.""" response = http.get(api.STORE_BY_ID.format(store_id="abc")) assert response.status_code == 404, response.url @pytest.mark.read def test_store_by_id_unknown_numeric_is_empty(http): """A valid-but-unknown numeric store id routes (200) and returns an empty list rather than 404 — the contract callers must handle.""" response = assert_ok(http.get(api.STORE_BY_ID.format(store_id="99999999"))) assert response.json() == []