@@ -377,27 +377,44 @@ def test_timeout_raises(self):
377377
378378
379379class TestCreateDeployment :
380- def test_polls_then_creates (self ):
380+ def test_polls_model_then_creates_then_polls_deployment (self ):
381381 b = _builder ()
382382 b ._bedrock_client = Mock ()
383383 b ._bedrock_client .get_custom_model .return_value = {"modelStatus" : "Active" }
384384 b ._bedrock_client .create_custom_model_deployment .return_value = {
385385 "customModelDeploymentArn" : "arn:dep"
386386 }
387+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
388+
387389 result = b .create_deployment (model_arn = "arn:model" , deployment_name = "dep" )
390+
388391 b ._bedrock_client .get_custom_model .assert_called_once ()
389392 b ._bedrock_client .create_custom_model_deployment .assert_called_once ()
393+ b ._bedrock_client .get_custom_model_deployment .assert_called_once ()
390394 assert result ["customModelDeploymentArn" ] == "arn:dep"
391395
392396 def test_passes_extra_kwargs (self ):
393397 b = _builder ()
394398 b ._bedrock_client = Mock ()
395399 b ._bedrock_client .get_custom_model .return_value = {"modelStatus" : "Active" }
396- b ._bedrock_client .create_custom_model_deployment .return_value = {}
400+ b ._bedrock_client .create_custom_model_deployment .return_value = {
401+ "customModelDeploymentArn" : "arn:dep"
402+ }
403+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
404+
397405 b .create_deployment (model_arn = "arn:model" , deployment_name = "d" , commitmentDuration = "ONE_MONTH" )
398406 kw = b ._bedrock_client .create_custom_model_deployment .call_args [1 ]
399407 assert kw ["commitmentDuration" ] == "ONE_MONTH"
400408
409+ def test_skips_deployment_polling_when_no_arn_in_response (self ):
410+ b = _builder ()
411+ b ._bedrock_client = Mock ()
412+ b ._bedrock_client .get_custom_model .return_value = {"modelStatus" : "Active" }
413+ b ._bedrock_client .create_custom_model_deployment .return_value = {}
414+
415+ b .create_deployment (model_arn = "arn:model" , deployment_name = "d" )
416+ b ._bedrock_client .get_custom_model_deployment .assert_not_called ()
417+
401418 def test_empty_model_arn_raises (self ):
402419 with pytest .raises (ValueError , match = "model_arn is required" ):
403420 _builder ().create_deployment (model_arn = "" , deployment_name = "d" )
@@ -407,6 +424,47 @@ def test_none_model_arn_raises(self):
407424 _builder ().create_deployment (model_arn = None , deployment_name = "d" )
408425
409426
427+ # ── _wait_for_deployment_active ─────────────────────────────────────────────
428+
429+
430+ class TestWaitForDeploymentActive :
431+ def test_immediate_active (self ):
432+ b = _builder ()
433+ b ._bedrock_client = Mock ()
434+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
435+ b ._wait_for_deployment_active ("arn:dep" )
436+ b ._bedrock_client .get_custom_model_deployment .assert_called_once_with (
437+ customModelDeploymentIdentifier = "arn:dep"
438+ )
439+
440+ def test_polls_then_active (self ):
441+ b = _builder ()
442+ b ._bedrock_client = Mock ()
443+ b ._bedrock_client .get_custom_model_deployment .side_effect = [
444+ {"status" : "Creating" },
445+ {"status" : "Creating" },
446+ {"status" : "Active" },
447+ ]
448+ with patch (f"{ MODULE } .time.sleep" ):
449+ b ._wait_for_deployment_active ("arn:dep" , poll_interval = 1 , max_wait = 10 )
450+ assert b ._bedrock_client .get_custom_model_deployment .call_count == 3
451+
452+ def test_failed_raises (self ):
453+ b = _builder ()
454+ b ._bedrock_client = Mock ()
455+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Failed" }
456+ with pytest .raises (RuntimeError , match = "failed" ):
457+ b ._wait_for_deployment_active ("arn:dep" )
458+
459+ def test_timeout_raises (self ):
460+ b = _builder ()
461+ b ._bedrock_client = Mock ()
462+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Creating" }
463+ with patch (f"{ MODULE } .time.sleep" ):
464+ with pytest .raises (RuntimeError , match = "Timed out" ):
465+ b ._wait_for_deployment_active ("arn:dep" , poll_interval = 1 , max_wait = 2 )
466+
467+
410468# ── deploy ──────────────────────────────────────────────────────────────────
411469
412470
@@ -432,10 +490,13 @@ def test_nova_full_chain(self):
432490 b ._bedrock_client .create_custom_model_deployment .return_value = {
433491 "customModelDeploymentArn" : "arn:dep"
434492 }
493+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
494+
435495 result = b .deploy (custom_model_name = "nova-m" , role_arn = "r" )
436496 b ._bedrock_client .create_custom_model .assert_called_once ()
437497 b ._bedrock_client .get_custom_model .assert_called_once ()
438498 b ._bedrock_client .create_custom_model_deployment .assert_called_once ()
499+ b ._bedrock_client .get_custom_model_deployment .assert_called_once ()
439500 assert result ["customModelDeploymentArn" ] == "arn:dep"
440501
441502 def test_nova_via_hub_content_name (self ):
@@ -449,6 +510,8 @@ def test_nova_via_hub_content_name(self):
449510 b ._bedrock_client .create_custom_model_deployment .return_value = {
450511 "customModelDeploymentArn" : "arn:dep"
451512 }
513+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
514+
452515 result = b .deploy (custom_model_name = "n" , role_arn = "r" )
453516 assert result ["customModelDeploymentArn" ] == "arn:dep"
454517
@@ -463,6 +526,8 @@ def test_nova_default_deployment_name(self):
463526 b ._bedrock_client .create_custom_model_deployment .return_value = {
464527 "customModelDeploymentArn" : "dep"
465528 }
529+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
530+
466531 b .deploy (custom_model_name = "my-model" , role_arn = "r" )
467532 kw = b ._bedrock_client .create_custom_model_deployment .call_args [1 ]
468533 assert kw ["modelDeploymentName" ] == "my-model-deployment"
@@ -478,6 +543,8 @@ def test_nova_with_tags(self):
478543 b ._bedrock_client .create_custom_model_deployment .return_value = {
479544 "customModelDeploymentArn" : "dep"
480545 }
546+ b ._bedrock_client .get_custom_model_deployment .return_value = {"status" : "Active" }
547+
481548 tags = [{"Key" : "env" , "Value" : "test" }]
482549 b .deploy (custom_model_name = "m" , role_arn = "r" , model_tags = tags )
483550 kw = b ._bedrock_client .create_custom_model .call_args [1 ]
0 commit comments