@@ -516,41 +516,26 @@ def test_in_cluster_config_default_port(self, _):
516516 sc = SandboxClient (connection_config = config )
517517 self .assertEqual (sc .connection_config .server_port , 8888 )
518518
519- @patch ('uuid.uuid4' )
520- @patch ('k8s_agent_sandbox.sandbox_client.K8sHelper' )
521- def test_sandbox_created_with_in_cluster_config (self , MockK8sHelper , mock_uuid ):
522- mock_uuid .return_value .hex = 'aabbccdd'
523- in_cluster_config = SandboxInClusterConnectionConfig ()
524- client = SandboxClient (connection_config = in_cluster_config )
525- client .k8s_helper .resolve_sandbox_name .return_value = 'my-sandbox'
526-
527- mock_sandbox_class = MagicMock ()
528- mock_sandbox_class .return_value = MagicMock ()
529- client .sandbox_class = mock_sandbox_class
530-
531- with patch .object (client , '_create_claim' ), \
532- patch .object (client , '_wait_for_sandbox_ready' ):
533- client .create_sandbox ('my-template' )
534-
535- call_kwargs = mock_sandbox_class .call_args .kwargs
519+ def _create_sandbox_with_in_cluster_config (self , namespace = 'default' ):
520+ with patch ('k8s_agent_sandbox.sandbox_client.K8sHelper' ), \
521+ patch ('uuid.uuid4' ) as mock_uuid :
522+ mock_uuid .return_value .hex = 'aabbccdd'
523+ client = SandboxClient (connection_config = SandboxInClusterConnectionConfig ())
524+ client .k8s_helper .resolve_sandbox_name .return_value = 'my-sandbox'
525+ mock_sandbox_class = MagicMock ()
526+ mock_sandbox_class .return_value = MagicMock ()
527+ client .sandbox_class = mock_sandbox_class
528+ with patch .object (client , '_create_claim' ), \
529+ patch .object (client , '_wait_for_sandbox_ready' ):
530+ client .create_sandbox ('my-template' , namespace = namespace )
531+ return mock_sandbox_class .call_args .kwargs
532+
533+ def test_sandbox_created_with_in_cluster_config (self ):
534+ call_kwargs = self ._create_sandbox_with_in_cluster_config ()
536535 self .assertIsInstance (call_kwargs ['connection_config' ], SandboxInClusterConnectionConfig )
537536
538- @patch ('uuid.uuid4' )
539- @patch ('k8s_agent_sandbox.sandbox_client.K8sHelper' )
540- def test_sandbox_namespace_passed_correctly (self , MockK8sHelper , mock_uuid ):
541- mock_uuid .return_value .hex = 'aabbccdd'
542- client = SandboxClient (connection_config = SandboxInClusterConnectionConfig ())
543- client .k8s_helper .resolve_sandbox_name .return_value = 'my-sandbox'
544-
545- mock_sandbox_class = MagicMock ()
546- mock_sandbox_class .return_value = MagicMock ()
547- client .sandbox_class = mock_sandbox_class
548-
549- with patch .object (client , '_create_claim' ), \
550- patch .object (client , '_wait_for_sandbox_ready' ):
551- client .create_sandbox ('my-template' , namespace = 'prod' )
552-
553- call_kwargs = mock_sandbox_class .call_args .kwargs
537+ def test_sandbox_namespace_passed_correctly (self ):
538+ call_kwargs = self ._create_sandbox_with_in_cluster_config (namespace = 'prod' )
554539 self .assertEqual (call_kwargs ['namespace' ], 'prod' )
555540
556541
0 commit comments