"""Integration tests for GET /product//tracks/grats. Access rule (backend/access_rules.yml): ContentProfile: ['*'] Tested across both content reviewer personas. """ import pytest import requests from tests.testutils.api_client import APIClient @pytest.fixture() def test_label_product_with_instant_grats() -> int: """Return a product belonging to 7123 with instant grats.""" return 353131 @pytest.fixture() def other_label_product_with_instant_grats() -> int: """Return a product belonging to 22411 with instant grats.""" return 1611080 # Subclassing the ows-track APIClient # during the Permissions Platform (PP) rollout. These methods can be merged into # OwsProductStaging when the rollout is complete. class _Client(APIClient): def get_all_grats_by_product_id(self, product_id: int) -> requests.Response: """Executes a GET against ows-track product//tracks/grats. This assumes ows-grass is not proxying this endpoint for this client. """ endpoint = '{}/product/{}/tracks/grats'.format(self.base_url, product_id) return requests.get(endpoint, headers=self._request_headers()) @pytest.mark.parametrize( 'client_fixture, base_url_fixture, product_id_fixture, expected_status_code, error_response_json', [ pytest.param( 'api_client', 'grass_base_url_track', 'test_label_product_with_instant_grats', 200, None, id="""Workstation Label user request, proxied through ows-grass can get instant grats by product id belonging to 7123""", ), pytest.param( 'api_client', 'grass_base_url_track', 'other_label_product_with_instant_grats', 403, {'code': 'ows_product_error', 'message': 'User is forbidden'}, id="""Workstation Label user request, proxied through ows-grass cannot get instant grats by product id belonging to 22411""", ), pytest.param( 'content_reviewer_pp_client', 'base_url', 'test_label_product_with_instant_grats', 403, {'code': 'authorization_error', 'message': 'Unauthorized'}, id="""WIP PP-1180 - Content reviewer with PP-based permissions is not authorized to get instant grats by product id belonging to 7123""", ), pytest.param( 'content_reviewer_pp_client', 'base_url', 'other_label_product_with_instant_grats', 403, {'code': 'authorization_error', 'message': 'Unauthorized'}, id="""WIP PP-1180 - Content reviewer with PP-based permissions is not authorized to get instant grats by product id belonging to 22411""", ), pytest.param( 'content_reviewer_profile_client', 'base_url', 'test_label_product_with_instant_grats', 200, None, id="""Content reviewer with Profile-based permissions is authorized to get instant grats by product id belonging to 7123""", ), pytest.param( 'content_reviewer_profile_client', 'base_url', 'other_label_product_with_instant_grats', 200, None, id="""Content reviewer with Profile-based permissions is authorized to get instant grats by product id belonging to 22411""", ), ]) def test_get_all_instant_grats_by_product_id( client_fixture: str, base_url_fixture: str, expected_status_code: int, error_response_json: dict | None, product_id_fixture: str, request: pytest.FixtureRequest, ) -> None: """Both content reviewer personas can list instant grats for a product.""" client = _Client( base_url=request.getfixturevalue(base_url_fixture), headers=request.getfixturevalue(client_fixture)._headers, ) response = client.get_all_grats_by_product_id( request.getfixturevalue(product_id_fixture) ) assert response.status_code == expected_status_code, ( 'Expected {}, got {} — body: {}'.format(expected_status_code, response.status_code, response.text) ) if response.status_code == 200: assert 'items' in response.json() else: assert error_response_json is not None, ( 'Misconfigured test case: expected non-200 status code but no error response JSON provided' ) assert response.json() == error_response_json