"""Integration API tests for ows-carveouts.""" import pytest from Integration.consts import api from Integration.utils import assert_ok, assert_int_keyed_map def _assert_store_map(body): """A store carveout map is dms_id -> {dms_name, distros}.""" assert body, "expected a non-empty store map" dms_id = next(iter(body)) assert 'dms_name' in body[dms_id] assert 'distros' in body[dms_id] @pytest.mark.read def test_store_list(http): """Get Store list""" response = assert_ok(http.get(api.STORE_LIST)) response_body = response.json() # Keys are integer store ids; values are non-empty store names. assert_int_keyed_map(response_body, "store list") assert api.STORE_ID in response_body, \ "expected store {} in the store list".format(api.STORE_ID) # For the default dataset, pin the known name so a mapping regression # (store 496 -> wrong/corrupted name) is caught, not just emptiness. Skip # the name check when TEST_STORE_ID points at another dataset. if api.STORE_ID == "496": assert "Google Music" in response_body["496"], \ "store 496 should map to 'Google Music', got {!r}".format( response_body["496"]) @pytest.mark.read def test_release_store(http): """Get store carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.RELEASE_STORE.format(upc=api.UPC))) _assert_store_map(response.json()) @pytest.mark.read def test_release_territory(http): """Get territory carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.RELEASE_TERRITORY.format(upc=api.TERRITORY_UPC))) assert_int_keyed_map(response.json(), "release territory") @pytest.mark.read def test_release_substore(http): """Get substore carveouts that are explicitly set for the provided release""" response = assert_ok( http.get(api.RELEASE_SUBSTORE.format(upc=api.SUBSTORE_UPC, dms_id=api.DMS_ID))) response_body = assert_int_keyed_map(response.json(), "release substore") assert api.DMS_ID in response_body.keys() @pytest.mark.read def test_release_all(http): """Get all carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.RELEASE_ALL.format(upc=api.UPC))) response_body = response.json() assert 'territory' in response_body assert 'substore' in response_body assert 'store' in response_body _assert_store_map(response_body['store']) # Vendor Level carveouts @pytest.mark.read def test_vendor_store(http): """Get store carveouts that are explicitly set for the provided vendor""" response = assert_ok(http.get(api.VENDOR_STORE.format(vendor_id=api.VENDOR_ID))) _assert_store_map(response.json()) @pytest.mark.read def test_vendor_territory(http): """Get territory carveouts that are explicitly set for the provided vendor""" response = assert_ok(http.get(api.VENDOR_TERRITORY.format(vendor_id=api.VENDOR_ID))) assert_int_keyed_map(response.json(), "vendor territory") @pytest.mark.read def test_vendor_substore(http): """Get substore carveouts that are explicitly set for the provided vendor""" response = assert_ok( http.get(api.VENDOR_SUBSTORE.format( vendor_id=api.SUBSTORE_VENDOR_ID, dms_id=api.SUBSTORE_DMS_ID))) assert_int_keyed_map(response.json(), "vendor substore") @pytest.mark.read def test_vendor_all(http): """Get all carveouts that are explicitly set for the provided vendor""" response = assert_ok(http.get(api.VENDOR_ALL.format(vendor_id=api.VENDOR_ID))) response_body = response.json() assert 'territory' in response_body assert 'substore' in response_body assert 'store' in response_body _assert_store_map(response_body['store']) @pytest.mark.read def test_subaccount_store(http): """Get store carveouts that are explicitly set for the provided subaccount""" response = assert_ok(http.get(api.SUBACCOUNT_STORE.format(subaccount_id=api.SUBACCOUNT_ID))) _assert_store_map(response.json()) @pytest.mark.read def test_subaccount_territory(http): """Get territory carveouts that are explicitly set for the provided subaccount""" response = assert_ok( http.get(api.SUBACCOUNT_TERRITORY.format(subaccount_id=api.SUBACCOUNT_ID))) assert_int_keyed_map(response.json(), "subaccount territory") @pytest.mark.read def test_subaccount_substore(http): """Get substore carveouts that are explicitly set for the provided subaccount""" response = assert_ok( http.get(api.SUBACCOUNT_SUBSTORE.format( subaccount_id=api.SUBACCOUNT_ID, dms_id=api.SUBACCOUNT_DMS_ID))) assert_int_keyed_map(response.json(), "subaccount substore") @pytest.mark.read def test_subaccount_all(http): """Get all carveouts that are explicitly set for the provided subaccount""" response = assert_ok(http.get(api.SUBACCOUNT_ALL.format(subaccount_id=api.SUBACCOUNT_ID))) response_body = response.json() assert 'territory' in response_body assert 'substore' in response_body assert 'store' in response_body _assert_store_map(response_body['store']) @pytest.mark.read def test_combined_store(http): """Get store carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.COMBINED_STORE.format(upc=api.UPC))) _assert_store_map(response.json()) @pytest.mark.read def test_combined_territory(http): """Get territory carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.COMBINED_TERRITORY.format(upc=api.TERRITORY_UPC))) assert_int_keyed_map(response.json(), "combined territory") @pytest.mark.read def test_combined_substore(http): """Get substore carveouts that are explicitly set for the provided release""" response = assert_ok( http.get(api.COMBINED_SUBSTORE.format(upc=api.SUBSTORE_UPC, dms_id=api.DMS_ID))) assert_int_keyed_map(response.json(), "combined substore") @pytest.mark.read def test_combined_all(http): """Get all carveouts that are explicitly set for the provided release""" response = assert_ok(http.get(api.COMBINED_ALL.format(upc=api.UPC))) response_body = response.json() assert 'territory' in response_body assert 'substore' in response_body assert 'store' in response_body _assert_store_map(response_body['store'])