Skip to content

Commit

Permalink
fix: improve error message for unsupported manifest versions (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Gahyun Suh <[email protected]>
Co-authored-by: Gahyun Suh <[email protected]>
  • Loading branch information
gahyusuh and Gahyun Suh authored Sep 22, 2023
1 parent 890a011 commit 04b43c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/deadline/job_attachments/asset_manifests/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 04b43c1

Please sign in to comment.