77import json
88import tempfile
99import os
10- from unittest .mock import Mock , patch
10+ from unittest .mock import MagicMock , patch
1111from azext_fleet .custom import get_update_run_strategy
12+ from azext_fleet .vendored_sdks .v2025_04_01_preview .models import UpdateRunStrategy , UpdateStage , UpdateGroup
1213from azure .cli .core .azclierror import (
1314 InvalidArgumentValueError ,
1415)
1516
16-
17- def mock_get_file_json (file_path ):
18- """Mock implementation of get_file_json."""
19- with open (file_path , 'r' , encoding = 'utf-8' ) as fp :
20- return json .load (fp )
21-
22-
23- def mock_shell_safe_json_parse (json_string ):
24- """Mock implementation of shell_safe_json_parse."""
25- return json .loads (json_string )
26-
27-
28-
29- class MockUpdateGroup :
30- """Mock UpdateGroup model."""
31- def __init__ (self , name ):
32- self .name = name
33-
34-
35- class MockUpdateStage :
36- """Mock UpdateStage model."""
37- def __init__ (self , name , groups , after_stage_wait_in_seconds = 0 ):
38- self .name = name
39- self .groups = groups
40- self .after_stage_wait_in_seconds = after_stage_wait_in_seconds
41-
42-
43- class MockUpdateRunStrategy :
44- """Mock UpdateRunStrategy model."""
45- def __init__ (self , stages ):
46- self .stages = stages
47-
48-
4917class TestStagesJsonHandling (unittest .TestCase ):
5018 """Test inline JSON support for --stages argument in fleet commands."""
5119
@@ -65,18 +33,18 @@ def setUp(self):
6533 }
6634
6735 # Mock cmd object that provides get_models method
68- self .mock_cmd = Mock ()
36+ self .mock_cmd = MagicMock ()
6937
7038 # Set up get_models to return our mock classes
7139 def mock_get_models (model_name , ** kwargs ):
7240 if model_name == "UpdateGroup" :
73- return MockUpdateGroup
41+ return UpdateGroup
7442 elif model_name == "UpdateStage" :
75- return MockUpdateStage
43+ return UpdateStage
7644 elif model_name == "UpdateRunStrategy" :
77- return MockUpdateRunStrategy
45+ return UpdateRunStrategy
7846 else :
79- return Mock
47+ return MagicMock ()
8048
8149 self .mock_cmd .get_models = mock_get_models
8250
@@ -93,18 +61,18 @@ def test_file_path_stages(self):
9361
9462 # Verify the returned strategy
9563 self .assertIsNotNone (result )
96- self .assertIsInstance (result , MockUpdateRunStrategy )
64+ self .assertIsInstance (result , UpdateRunStrategy )
9765 self .assertEqual (len (result .stages ), 1 )
9866
9967 # Verify first stage
10068 stage = result .stages [0 ]
101- self .assertIsInstance (stage , MockUpdateStage )
69+ self .assertIsInstance (stage , UpdateStage )
10270 self .assertEqual (stage .name , "stage1" )
10371 self .assertEqual (stage .after_stage_wait_in_seconds , 3600 )
10472 self .assertEqual (len (stage .groups ), 2 )
10573
10674 # Verify groups
107- self .assertIsInstance (stage .groups [0 ], MockUpdateGroup )
75+ self .assertIsInstance (stage .groups [0 ], UpdateGroup )
10876 self .assertEqual (stage .groups [0 ].name , "group1" )
10977 self .assertEqual (stage .groups [1 ].name , "group2" )
11078
@@ -121,18 +89,18 @@ def test_inline_json_stages(self):
12189
12290 # Verify the returned strategy
12391 self .assertIsNotNone (result )
124- self .assertIsInstance (result , MockUpdateRunStrategy )
92+ self .assertIsInstance (result , UpdateRunStrategy )
12593 self .assertEqual (len (result .stages ), 1 )
12694
12795 # Verify first stage
12896 stage = result .stages [0 ]
129- self .assertIsInstance (stage , MockUpdateStage )
97+ self .assertIsInstance (stage , UpdateStage )
13098 self .assertEqual (stage .name , "stage1" )
13199 self .assertEqual (stage .after_stage_wait_in_seconds , 3600 )
132100 self .assertEqual (len (stage .groups ), 2 )
133101
134102 # Verify groups
135- self .assertIsInstance (stage .groups [0 ], MockUpdateGroup )
103+ self .assertIsInstance (stage .groups [0 ], UpdateGroup )
136104 self .assertEqual (stage .groups [0 ].name , "group1" )
137105 self .assertEqual (stage .groups [1 ].name , "group2" )
138106
0 commit comments