"""Integration tests for POST /transfer/job.""" import requests from .helpers import ( DESTINATION_VENDOR_ID, ORIGINATING_VENDOR_ID, TIMEOUT, create_job, delete_job, url, ) class TestCreateTransferJob: """Tests for POST /transfer/job.""" def test_creates_job_with_products(self, qa_base_url, auth_headers, qa_project): """Returns 201 with job and snapshotted products.""" job = create_job(qa_base_url, auth_headers, qa_project["project_id"]) try: assert job["project_id"] == qa_project["project_id"] assert job["originating_vendor_id"] == ORIGINATING_VENDOR_ID assert job["destination_vendor_id"] == DESTINATION_VENDOR_ID assert job["status"] == "QUEUED" assert isinstance(job["products"], list) assert len(job["products"]) >= 1 assert job["products"][0]["release_id"] == qa_project["release_id"] finally: delete_job(qa_base_url, auth_headers, job["project_transfer_job_id"]) def test_revenue_cutoff_date_is_last_day_of_previous_month( self, qa_base_url, auth_headers, qa_project ): """Server always sets revenue_cutoff_date to last day of previous month.""" import datetime today = datetime.date.today() expected = (today.replace(day=1) - datetime.timedelta(days=1)).isoformat() r = requests.post( url(qa_base_url, "/transfer/job"), headers=auth_headers, json={ "project_id": qa_project["project_id"], "destination_vendor_id": DESTINATION_VENDOR_ID, }, timeout=TIMEOUT, ) assert r.status_code == 201 assert r.json()["revenue_cutoff_date"] == expected delete_job(qa_base_url, auth_headers, r.json()["project_transfer_job_id"]) def test_missing_project_id_returns_400(self, qa_base_url, auth_headers): """Returns 400 when project_id is missing.""" r = requests.post( url(qa_base_url, "/transfer/job"), headers=auth_headers, json={"destination_vendor_id": DESTINATION_VENDOR_ID}, timeout=TIMEOUT, ) assert r.status_code == 400 def test_missing_destination_vendor_returns_400(self, qa_base_url, auth_headers, qa_project): """Returns 400 when destination_vendor_id is missing.""" r = requests.post( url(qa_base_url, "/transfer/job"), headers=auth_headers, json={"project_id": qa_project["project_id"]}, timeout=TIMEOUT, ) assert r.status_code == 400 def test_nonexistent_project_returns_404(self, qa_base_url, auth_headers): """Returns 404 when project does not exist.""" r = requests.post( url(qa_base_url, "/transfer/job"), headers=auth_headers, json={ "project_id": 999999999, "destination_vendor_id": DESTINATION_VENDOR_ID, }, timeout=TIMEOUT, ) assert r.status_code == 404 def test_project_with_no_releases_returns_400( self, qa_base_url, auth_headers, qa_project_no_releases): """Returns 400 when the project has no releases to snapshot.""" r = requests.post( url(qa_base_url, "/transfer/job"), headers=auth_headers, json={ "project_id": qa_project_no_releases["project_id"], "destination_vendor_id": DESTINATION_VENDOR_ID, }, timeout=TIMEOUT, ) assert r.status_code == 400