from typing import Any, Union import pytest import requests from tests.integration import config VENDOR_UUID = '2e79b9b8-29ed-44e1-832f-2aa3b47f13c8' ENDPOINT = f'{config.QA_BASE_URL}/vendor/{VENDOR_UUID}/first_statement_period' @pytest.mark.parametrize( 'profile_fixture, token_fixture, headers, payload, expected_status, expected_response', [ pytest.param( 'orchard_permissions_test_user_label_profile', None, { 'Orchard-User-Id': 'oa:3188', 'Orchard-Requestor-Service': 'graphql-account-test', }, {'first_statement_period': 1}, 200, {'vendor_id': 30, 'vendor_uuid': VENDOR_UUID, 'first_statement_period': '1'}, id='success', ), pytest.param( None, None, { 'Orchard-Requestor-Service': 'graphql-account-test', }, {'first_statement_period': 1}, 403, {'code': 'authorization_error', 'message': 'Forbidden'}, id='forbidden-no-auth', ), pytest.param( None, None, { 'Orchard-User-Id': 'oa:3188', 'Orchard-Requestor-Service': 'graphql-account-test', }, {'first_statement_period': []}, 400, { 'code': 'input_validation_error', 'message': {'first_statement_period': ['Shorter than minimum length 1.']}, }, id='invalid-payload', ), pytest.param( None, None, { 'Orchard-User-Id': 'invalid_3188', }, {'first_statement_period': 1}, 401, { 'code': 'authorization_error', 'message': 'Unauthorized user with user_id = invalid_3188', }, id='unauthorized-invalid-user-id', ), ], ) def test_update_vendor_first_statement_period( profile_fixture: str, token_fixture: str, headers: dict[str, str], payload: dict[str, Any], expected_status: int, expected_response: Union[dict[str, Any], dict[str, dict[str, list]]], request: Any, ) -> None: """PATCH /vendor/{VENDOR_UUID}/first_statement_period updates first_statement_period""" full_headers = { 'Content-Type': 'application/json', **headers, } if token_fixture: token = request.getfixturevalue(token_fixture) full_headers['Authorization'] = f'Bearer {token}' if profile_fixture: profile = request.getfixturevalue(profile_fixture) full_headers.update( { 'Orchard-Identity-Id': profile.identity_id, 'Orchard-Profile-Id': str(profile.profile_id), 'Orchard-Profile-Type': profile.profile_type, } ) response = requests.patch(ENDPOINT, headers=full_headers, json=payload) assert response.status_code == expected_status if expected_status == 200: assert response.json() == expected_response