@@ -111,11 +111,21 @@ def test_automatic_approval_uses_label_selector_only(
111111 mock_subscription .status .state = "AtLatestKnown"
112112 mock_subscription .status .installedCSV = "test-operator.v1.0.0"
113113
114- # First call returns empty list (no existing subscription), subsequent calls return the subscription
115- sub_api .get .side_effect = [
116- MockResourceList ([]), # Initial check for existing subscription
117- mock_subscription , # Subsequent calls when waiting for subscription to complete
118- ]
114+ # Mock to return empty list first, then the subscription for all subsequent calls
115+ def sub_get_side_effect (* args , ** kwargs ):
116+ if "label_selector" in kwargs :
117+ # First call with label_selector returns empty list
118+ if not hasattr (sub_get_side_effect , "called" ):
119+ sub_get_side_effect .called = True
120+ return MockResourceList ([])
121+ # Subsequent calls return the subscription
122+ return MockResourceList ([mock_subscription ])
123+ elif "name" in kwargs :
124+ # Direct get by name returns the subscription
125+ return mock_subscription
126+ return MockResourceList ([])
127+
128+ sub_api .get .side_effect = sub_get_side_effect
119129 sub_api .apply .return_value = Mock ()
120130
121131 # Mock InstallPlan API - label selector returns one InstallPlan
@@ -183,11 +193,18 @@ def test_manual_approval_without_starting_csv_uses_label_selector_only(
183193 mock_subscription .status .state = "UpgradePending"
184194 mock_subscription .status .installedCSV = "test-operator.v1.0.0"
185195
186- # First call returns empty list (no existing subscription), subsequent calls return the subscription
187- sub_api .get .side_effect = [
188- MockResourceList ([]), # Initial check for existing subscription
189- mock_subscription , # Subsequent calls when waiting for subscription to complete
190- ]
196+ # Mock to return empty list first, then the subscription for all subsequent calls
197+ def sub_get_side_effect (* args , ** kwargs ):
198+ if "label_selector" in kwargs :
199+ if not hasattr (sub_get_side_effect , "called" ):
200+ sub_get_side_effect .called = True
201+ return MockResourceList ([])
202+ return MockResourceList ([mock_subscription ])
203+ elif "name" in kwargs :
204+ return mock_subscription
205+ return MockResourceList ([])
206+
207+ sub_api .get .side_effect = sub_get_side_effect
191208 sub_api .apply .return_value = Mock ()
192209
193210 # Mock InstallPlan API
@@ -270,11 +287,18 @@ def test_manual_approval_with_starting_csv_label_selector_finds_match(
270287 mock_subscription .status .state = "UpgradePending"
271288 mock_subscription .status .installedCSV = "test-operator.v1.0.0"
272289
273- # First call returns empty list (no existing subscription), subsequent calls return the subscription
274- sub_api .get .side_effect = [
275- MockResourceList ([]), # Initial check for existing subscription
276- mock_subscription , # Subsequent calls when waiting for subscription to complete
277- ]
290+ # Mock to return empty list first, then the subscription for all subsequent calls
291+ def sub_get_side_effect (* args , ** kwargs ):
292+ if "label_selector" in kwargs :
293+ if not hasattr (sub_get_side_effect , "called" ):
294+ sub_get_side_effect .called = True
295+ return MockResourceList ([])
296+ return MockResourceList ([mock_subscription ])
297+ elif "name" in kwargs :
298+ return mock_subscription
299+ return MockResourceList ([])
300+
301+ sub_api .get .side_effect = sub_get_side_effect
278302 sub_api .apply .return_value = Mock ()
279303
280304 # Mock InstallPlan API - label selector returns matching InstallPlan
@@ -357,11 +381,18 @@ def test_manual_approval_with_starting_csv_fallback_to_ownership_search(
357381 mock_subscription .status .state = "UpgradePending"
358382 mock_subscription .status .installedCSV = "test-operator.v1.0.0"
359383
360- # First call returns empty list (no existing subscription), subsequent calls return the subscription
361- sub_api .get .side_effect = [
362- MockResourceList ([]), # Initial check for existing subscription
363- mock_subscription , # Subsequent calls when waiting for subscription to complete
364- ]
384+ # Mock to return empty list first, then the subscription for all subsequent calls
385+ def sub_get_side_effect (* args , ** kwargs ):
386+ if "label_selector" in kwargs :
387+ if not hasattr (sub_get_side_effect , "called" ):
388+ sub_get_side_effect .called = True
389+ return MockResourceList ([])
390+ return MockResourceList ([mock_subscription ])
391+ elif "name" in kwargs :
392+ return mock_subscription
393+ return MockResourceList ([])
394+
395+ sub_api .get .side_effect = sub_get_side_effect
365396 sub_api .apply .return_value = Mock ()
366397
367398 # Mock InstallPlan API
@@ -464,11 +495,18 @@ def test_manual_approval_filters_by_subscription_ownership(
464495 mock_subscription .status .state = "UpgradePending"
465496 mock_subscription .status .installedCSV = "test-operator.v1.0.0"
466497
467- # First call returns empty list (no existing subscription), subsequent calls return the subscription
468- sub_api .get .side_effect = [
469- MockResourceList ([]), # Initial check for existing subscription
470- mock_subscription , # Subsequent calls when waiting for subscription to complete
471- ]
498+ # Mock to return empty list first, then the subscription for all subsequent calls
499+ def sub_get_side_effect (* args , ** kwargs ):
500+ if "label_selector" in kwargs :
501+ if not hasattr (sub_get_side_effect , "called" ):
502+ sub_get_side_effect .called = True
503+ return MockResourceList ([])
504+ return MockResourceList ([mock_subscription ])
505+ elif "name" in kwargs :
506+ return mock_subscription
507+ return MockResourceList ([])
508+
509+ sub_api .get .side_effect = sub_get_side_effect
472510 sub_api .apply .return_value = Mock ()
473511
474512 # Mock InstallPlan API
0 commit comments