import time from typing import Any import pytest import requests from tests.integration import config @pytest.fixture() def sme_vendor_for_country_id() -> 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( {'country_id': 1}, 403, id='Contract Admins are not allowed to update country_id', ), ], ) def test_update_vendor_country_id_fails( update_payload: dict[str, Any], expected_status_code: int, bearer_token_contract_admin_sme: str, sme_vendor_for_country_id: dict[str, Any], ) -> None: """PATCH /v2/vendor//country_id validates the request.. This test uses the v2 CreateVendor endpoint, then tries to update country_id 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_country_id, 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}/country_id', json=update_payload, headers=headers, ) assert response.status_code == expected_status_code, response