import time from typing import Any import pytest import requests from tests.integration import config @pytest.fixture() def sme_vendor_for_external_identifier() -> dict[str, Any]: return { 'is_distributor': False, 'name': f'ows-account integration-test sme {time.time()}', 'owner': 'SME Analytics', 'company_brand': 'sme', 'service_tier_uuid': 'c069ab15-9370-4bd6-8ad1-895a64ae2ad8', 'payment_currency': 'USD', } @pytest.mark.parametrize( 'update_payload,expected_status_code', [ pytest.param({'bad': 'request'}, 400, id='Fails schema validation'), pytest.param( {'external_identifier_1': f'parent rep owner {time.time()}'}, 403, id='Contract Admins are not allowed to update external_identifier_1', ), ], ) def test_update_vendor_external_identifier_1_fails( update_payload: dict[str, Any], expected_status_code: int, bearer_token_contract_admin_sme: str, sme_vendor_for_external_identifier: dict[str, Any], ) -> None: """PATCH /v2/vendor//external-identifier-1 validates the request.. This test uses the v2 CreateVendor endpoint, then tries to update external_identifier_1 for the created vendor with a poorly formed request body. """ headers = {'Authorization': f'Bearer {bearer_token_contract_admin_sme}'} response = requests.post( f'{config.QA_BASE_URL}/v2/vendors', json=sme_vendor_for_external_identifier, headers=headers, ) assert response.status_code == 200, response.text actual = response.json() vendor_uuid = actual['vendor_uuid'] response = requests.patch( f'{config.QA_BASE_URL}/v2/vendor/{vendor_uuid}/external-identifier-1', json=update_payload, headers=headers, ) assert response.status_code == expected_status_code, response