"""Shared helpers and constants for integration tests.""" import requests ORIGINATING_VENDOR_ID = 7123 DESTINATION_VENDOR_ID = 6971 DESTINATION_VENDOR_ID_WITH_SUBACCOUNT = 16055 DESTINATION_SUBACCOUNT_ID = 1 TIMEOUT = 30 def url(base_url, path): """Build a full URL from the base and path.""" return f"{base_url}{path}" def create_job(base_url, auth_headers, project_id, destination_vendor_id=DESTINATION_VENDOR_ID, destination_subaccount_id=None): """Create a transfer job and return the job dict with products attached.""" body = { "project_id": project_id, "destination_vendor_id": destination_vendor_id, } if destination_subaccount_id is not None: body["destination_subaccount_id"] = destination_subaccount_id r = requests.post( url(base_url, "/transfer/job"), headers=auth_headers, json=body, timeout=TIMEOUT, ) assert r.status_code == 201, f"Failed to create transfer job: {r.text}" job = r.json() products_r = requests.get( url(base_url, f"/transfer/job/{job['project_transfer_job_id']}/products"), headers=auth_headers, timeout=TIMEOUT, ) assert products_r.status_code == 200, f"Failed to fetch products: {products_r.text}" job["products"] = products_r.json() return job def set_destination_artists(base_url, auth_headers, job_id, products, destination_artist_id): """Populate destination_artist_id on all snapshot rows for a job.""" updates = [ {"release_id": p["release_id"], "destination_artist_id": destination_artist_id} for p in products ] r = requests.patch( url(base_url, f"/transfer/job/{job_id}/products"), headers=auth_headers, json={"updates": updates}, timeout=TIMEOUT, ) assert r.status_code == 200, f"Failed to set destination artists: {r.text}" return r.json() def delete_job(base_url, auth_headers, job_id): """Delete a transfer job, asserting 204.""" r = requests.delete( url(base_url, f"/transfer/job/{job_id}"), headers=auth_headers, timeout=TIMEOUT, ) assert r.status_code == 204, f"Failed to delete transfer job {job_id}: {r.text}"