From d0fa0ddb93551b2b934961d0cad13557fd65a2b5 Mon Sep 17 00:00:00 2001 From: Gahyun Suh Date: Fri, 22 Sep 2023 20:47:05 +0000 Subject: [PATCH] fix: improve error message for unsupported manifest versions --- .../job_attachments/asset_manifests/decode.py | 6 +++- .../asset_manifests/test_decode.py | 36 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/deadline/job_attachments/asset_manifests/decode.py b/src/deadline/job_attachments/asset_manifests/decode.py index ac60434fb..9ce239ead 100644 --- a/src/deadline/job_attachments/asset_manifests/decode.py +++ b/src/deadline/job_attachments/asset_manifests/decode.py @@ -49,8 +49,12 @@ def decode_manifest(manifest: str) -> BaseAssetManifest: version = ManifestVersion(document["manifestVersion"]) except ValueError: # Value of the manifest version is not one we know. + supported_versions = ", ".join( + [v.value for v in ManifestVersion if v != ManifestVersion.UNDEFINED] + ) raise ManifestDecodeValidationError( - f"Unknown manifest version: {document['manifestVersion']}" + f"Unknown manifest version: {document['manifestVersion']} " + f"(Currently supported Manifest versions: {supported_versions})" ) except KeyError: raise ManifestDecodeValidationError( diff --git a/test/unit/deadline_job_attachments/asset_manifests/test_decode.py b/test/unit/deadline_job_attachments/asset_manifests/test_decode.py index 6b7f3a184..dae05f6df 100644 --- a/test/unit/deadline_job_attachments/asset_manifests/test_decode.py +++ b/test/unit/deadline_job_attachments/asset_manifests/test_decode.py @@ -2,9 +2,11 @@ """ Tests for the asset_manifests.decode module """ from __future__ import annotations +from enum import Enum import json from dataclasses import dataclass +import re from typing import Any from unittest.mock import patch @@ -116,10 +118,42 @@ def test_decode_manifest_version_not_supported(): """ Test that a ManifestDecodeValidationError is raised if the manifest passed has a version that isn't valid. """ - with pytest.raises(ManifestDecodeValidationError, match="Unknown manifest version: 1900-06-06"): + with pytest.raises( + ManifestDecodeValidationError, + match=re.escape( + "Unknown manifest version: 1900-06-06 (Currently supported Manifest versions: 2023-03-03)" + ), + ): decode.decode_manifest('{"manifestVersion": "1900-06-06"}') +def test_decode_manifest_version_not_supported_when_multiple_versions_are_supported(): + """ + Test that a ManifestDecodeValidationError is raised with a descriptive error message if the manifest passed + has a version that isn't valid. In this test, the ManifestVersion class is mocked to simulate having multple + supported manifest versions. + """ + + class MockManifestVersion(str, Enum): + UNDEFINED = "UNDEFINED" + v2023_03_03 = "2023-03-03" + v2024_04_03 = "2024-04-03" + v2025_05_03 = "2025-05-03" + + with patch( + f"{deadline.__package__}.job_attachments.asset_manifests.decode.ManifestVersion", + new=MockManifestVersion, + ): + with pytest.raises( + ManifestDecodeValidationError, + match=re.escape( + "Unknown manifest version: 1900-06-06 " + "(Currently supported Manifest versions: 2023-03-03, 2024-04-03, 2025-05-03)" + ), + ): + decode.decode_manifest('{"manifestVersion": "1900-06-06"}') + + def test_decode_manifest_not_valid_manifest(): """ Test that a ManifestDecodeValidationError is raised if the manifest passed in is not valid.