"""Integration tests for reference_sap_profit_center.""" import random import pytest import requests from tests.integration.consts.api import QA_BASE_URL @pytest.mark.jira('PLATFORM-4455') def test_reference_sap_profit_centers( auth_headers: dict[str, str], admin_headers: dict[str, str] ) -> None: """Test GET /reference-sap-profit-center/:id endpoint authorized.""" # first fetch all the reference_sap_profit_centers with admin headers since # the readonly headers do not have access to this endpoint. endpoint = '{}/reference-sap-profit-center/'.format(QA_BASE_URL) res_get = requests.get(endpoint, headers=admin_headers) assert res_get.status_code == 200 items = res_get.json()['items'] # now test the endpoint with both admin and readonly headers and get a random item. random_item = random.choice(items) sap_profit_center_id = random_item['reference_sap_profit_center_id'] endpoint = '{}/reference-sap-profit-center/{}'.format( QA_BASE_URL, sap_profit_center_id ) res_get = requests.get(endpoint, headers=auth_headers) assert res_get.status_code == 200 assert res_get.json() == random_item @pytest.mark.jira('PLATFORM-4455') def test_reference_sap_profit_center_by_id_unauthorized( unauthorized_headers: dict[str, str] ) -> None: """Test the GET /reference_sap_profit_center/:id endpoint unauthorized.""" endpoint = '{}/reference-sap-profit-center/1'.format(QA_BASE_URL) res_get = requests.get(endpoint, headers=unauthorized_headers) assert res_get.status_code == 403 expected = { 'code': 'forbidden', 'message': 'User is forbidden' } assert res_get.json() == expected