diff --git a/tests/test_worker.py b/tests/test_worker.py index d8db81a..397918b 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -1,4 +1,5 @@ import base64 +import json import re import uuid from contextlib import contextmanager @@ -1522,16 +1523,18 @@ async def test_create_job_failure( mock_batch_client, ): response = MagicMock() - response.data = { - "kind": "Status", - "apiVersion": "v1", - "metadata": {}, - "status": "Failure", - "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', - "reason": "Forbidden", - "details": {"group": "batch", "kind": "jobs"}, - "code": 403, - } + response.data = json.dumps( + { + "kind": "Status", + "apiVersion": "v1", + "metadata": {}, + "status": "Failure", + "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', + "reason": "Forbidden", + "details": {"group": "batch", "kind": "jobs"}, + "code": 403, + } + ) response.status = 403 response.reason = "Forbidden" @@ -1563,16 +1566,18 @@ async def test_create_job_retries( ): MAX_ATTEMPTS = 3 response = MagicMock() - response.data = { - "kind": "Status", - "apiVersion": "v1", - "metadata": {}, - "status": "Failure", - "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', - "reason": "Forbidden", - "details": {"group": "batch", "kind": "jobs"}, - "code": 403, - } + response.data = json.dumps( + { + "kind": "Status", + "apiVersion": "v1", + "metadata": {}, + "status": "Failure", + "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', + "reason": "Forbidden", + "details": {"group": "batch", "kind": "jobs"}, + "code": 403, + } + ) response.status = 403 response.reason = "Forbidden" @@ -1605,16 +1610,18 @@ async def test_create_job_failure_no_reason( mock_batch_client, ): response = MagicMock() - response.data = { - "kind": "Status", - "apiVersion": "v1", - "metadata": {}, - "status": "Failure", - "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', - "reason": "Forbidden", - "details": {"group": "batch", "kind": "jobs"}, - "code": 403, - } + response.data = json.dumps( + { + "kind": "Status", + "apiVersion": "v1", + "metadata": {}, + "status": "Failure", + "message": 'jobs.batch is forbidden: User "system:serviceaccount:helm-test:prefect-worker-dev" cannot create resource "jobs" in API group "batch" in the namespace "prefect"', + "reason": "Forbidden", + "details": {"group": "batch", "kind": "jobs"}, + "code": 403, + } + ) response.status = 403 response.reason = None @@ -1645,15 +1652,17 @@ async def test_create_job_failure_no_message( mock_batch_client, ): response = MagicMock() - response.data = { - "kind": "Status", - "apiVersion": "v1", - "metadata": {}, - "status": "Failure", - "reason": "Forbidden", - "details": {"group": "batch", "kind": "jobs"}, - "code": 403, - } + response.data = json.dumps( + { + "kind": "Status", + "apiVersion": "v1", + "metadata": {}, + "status": "Failure", + "reason": "Forbidden", + "details": {"group": "batch", "kind": "jobs"}, + "code": 403, + } + ) response.status = 403 response.reason = "Test"