88from tests .contants_test import HETA_APPLICATION_ID
99
1010
11- @pytest .mark .e2e
11+ @pytest .mark .unit
1212def test_application_version_valid_semver_formats (runner : CliRunner ) -> None :
1313 """Test that valid semver formats are accepted."""
1414 from aignostics .application import Service as ApplicationService
@@ -75,6 +75,7 @@ def test_application_version_invalid_semver_formats(runner: CliRunner) -> None:
7575
7676
7777@pytest .mark .e2e
78+ @pytest .mark .timeout (timeout = 60 )
7879def test_application_version_use_latest_fallback (runner : CliRunner ) -> None :
7980 """Test that use_latest_if_no_version_given works correctly."""
8081 service = ApplicationService ()
@@ -91,3 +92,77 @@ def test_application_version_use_latest_fallback(runner: CliRunner) -> None:
9192
9293 with pytest .raises (ValueError , match = r"Invalid application version id format" ):
9394 service .application_version ("invalid-format" , use_latest_if_no_version_given = False )
95+
96+
97+ @pytest .mark .e2e
98+ @pytest .mark .flaky (retries = 1 , delay = 5 )
99+ @pytest .mark .timeout (timeout = 60 )
100+ def test_application_versions_with_str_arg (runner : CliRunner , silent_logging : None ) -> None :
101+ """Test that application_versions works correctly when passed a string application ID."""
102+ service = ApplicationService ()
103+
104+ # Test with valid application ID as string
105+ versions = service .application_versions (HETA_APPLICATION_ID )
106+ assert isinstance (versions , list )
107+ # If there are versions, verify they are ApplicationVersion objects
108+ if versions :
109+ from aignostics .platform import ApplicationVersion
110+
111+ assert all (isinstance (v , ApplicationVersion ) for v in versions )
112+
113+
114+ @pytest .mark .e2e
115+ @pytest .mark .flaky (retries = 1 , delay = 5 )
116+ @pytest .mark .timeout (timeout = 60 )
117+ def test_application_version_latest_with_str_arg (runner : CliRunner , silent_logging : None ) -> None :
118+ """Test that application_version_latest works correctly when passed a string application ID."""
119+ service = ApplicationService ()
120+
121+ # Test with valid application ID as string
122+ latest = service .application_version_latest (HETA_APPLICATION_ID )
123+ # May be None if no versions exist, but should not raise an error
124+ if latest is not None :
125+ from aignostics .platform import ApplicationVersion
126+
127+ assert isinstance (latest , ApplicationVersion )
128+ assert latest .application_version_id .startswith (f"{ HETA_APPLICATION_ID } :v" )
129+
130+
131+ @pytest .mark .unit
132+ def test_application_versions_exception_handling_with_str_arg () -> None :
133+ """Test that exception handling correctly uses string application ID in error message."""
134+ from unittest .mock import MagicMock , patch
135+
136+ service = ApplicationService ()
137+
138+ # Mock the platform client to raise an exception
139+ with patch .object (service , "_get_platform_client" ) as mock_client :
140+ mock_versions = MagicMock ()
141+ mock_versions .list_sorted .side_effect = Exception ("Test error" )
142+ mock_client .return_value .applications .versions = mock_versions
143+
144+ # Test with string application ID
145+ test_app_id = "test-application-id"
146+ expected_error = rf"Failed to retrieve application versions for application '{ test_app_id } '"
147+ with pytest .raises (RuntimeError , match = expected_error ):
148+ service .application_versions (test_app_id )
149+
150+
151+ @pytest .mark .unit
152+ def test_application_version_latest_exception_handling_with_str_arg () -> None :
153+ """Test exception handling in application_version_latest with string application ID."""
154+ from unittest .mock import MagicMock , patch
155+
156+ service = ApplicationService ()
157+
158+ # Mock the platform client to raise an exception
159+ with patch .object (service , "_get_platform_client" ) as mock_client :
160+ mock_versions = MagicMock ()
161+ mock_versions .list_sorted .side_effect = Exception ("Test error" )
162+ mock_client .return_value .applications .versions = mock_versions
163+
164+ # Test with string application ID
165+ test_app_id = "test-application-id"
166+ expected_error = rf"Failed to retrieve application versions for application '{ test_app_id } '"
167+ with pytest .raises (RuntimeError , match = expected_error ):
168+ service .application_version_latest (test_app_id )
0 commit comments