From 0da921c5f46b3c63aff3a8fdcd892701447900b6 Mon Sep 17 00:00:00 2001 From: Caden Marofke Date: Wed, 20 Mar 2024 17:08:05 -0500 Subject: [PATCH] fix: Make StorageProfileOperatingSystemFamily enum case-insensitive Signed-off-by: Caden Marofke --- src/deadline/job_attachments/models.py | 10 ++++++ .../deadline_job_attachments/test_models.py | 33 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/deadline/job_attachments/models.py b/src/deadline/job_attachments/models.py index 153488df..d82f9915 100644 --- a/src/deadline/job_attachments/models.py +++ b/src/deadline/job_attachments/models.py @@ -111,10 +111,20 @@ class OutputFile: class StorageProfileOperatingSystemFamily(str, Enum): + """Case-insensitive enum for the storage profile operating system family type.""" + WINDOWS = "windows" LINUX = "linux" MACOS = "macos" + @classmethod + def _missing_(cls, value): + value = value.lower() + for member in cls: + if member == value: + return member + return None + class PathFormat(str, Enum): WINDOWS = "windows" diff --git a/test/unit/deadline_job_attachments/test_models.py b/test/unit/deadline_job_attachments/test_models.py index a1b38064..d21af972 100644 --- a/test/unit/deadline_job_attachments/test_models.py +++ b/test/unit/deadline_job_attachments/test_models.py @@ -1,7 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. from unittest.mock import patch -from deadline.job_attachments.models import PathFormat +from deadline.job_attachments.models import PathFormat, StorageProfileOperatingSystemFamily import pytest @@ -17,3 +17,34 @@ def test_get_host_path_format_string(self, sys_os: str, expected_output: str): """ with patch("sys.platform", sys_os): assert PathFormat.get_host_path_format_string() == expected_output + + @pytest.mark.parametrize( + ("input", "output"), + [ + ("windows", StorageProfileOperatingSystemFamily.WINDOWS), + ("WINDOWS", StorageProfileOperatingSystemFamily.WINDOWS), + ("wInDoWs", StorageProfileOperatingSystemFamily.WINDOWS), + ("linux", StorageProfileOperatingSystemFamily.LINUX), + ("LINUX", StorageProfileOperatingSystemFamily.LINUX), + ("LiNuX", StorageProfileOperatingSystemFamily.LINUX), + ("macos", StorageProfileOperatingSystemFamily.MACOS), + ("MACOS", StorageProfileOperatingSystemFamily.MACOS), + ("maCOs", StorageProfileOperatingSystemFamily.MACOS), + ], + ) + def test_storage_profile_operating_system_family_case( + self, input: str, output: StorageProfileOperatingSystemFamily + ) -> None: + """ + Tests that the correct enum types are created regardless of input string casing. + """ + assert StorageProfileOperatingSystemFamily(input) == output + + @pytest.mark.parametrize(("input"), [("linuxx"), ("darwin"), ("oSx"), ("MSDOS")]) + def test_storage_profile_operating_system_raises_type_error(self, input): + """ + Tests that a ValueError is raised when a non-valid string is given. + I.e. our case-insensitivity isn't causing false-positives. + """ + with pytest.raises(ValueError): + StorageProfileOperatingSystemFamily(input)