@@ -484,12 +484,12 @@ async def test_list_provider_models_for_tenant_exception():
484484async def test_update_single_model_for_tenant_success ():
485485 svc = import_svc ()
486486
487- model = {"model_id" : "m1 " , "display_name" : "name" }
487+ model = {"model_id" : "1 " , "display_name" : "name" }
488488 with mock .patch .object (svc , "get_model_by_display_name" , return_value = None ) as mock_get , \
489489 mock .patch .object (svc , "update_model_record" ) as mock_update :
490490 await svc .update_single_model_for_tenant ("u1" , "t1" , model )
491491 mock_get .assert_called_once_with ("name" , "t1" )
492- mock_update .assert_called_once_with ("m1" , model , "u1" )
492+ mock_update .assert_called_once_with (1 , model , "u1" )
493493
494494
495495async def test_update_single_model_for_tenant_conflict ():
@@ -502,6 +502,45 @@ async def test_update_single_model_for_tenant_conflict():
502502 assert "Failed to update model" in str (exc .value )
503503
504504
505+ async def test_update_single_model_for_tenant_same_model_no_conflict ():
506+ """Test that updating the same model with same display name doesn't raise conflict."""
507+ svc = import_svc ()
508+
509+ model = {"model_id" : "123" , "display_name" : "existing_name" }
510+ # Return the same model_id (as int) to simulate updating the same model
511+ with mock .patch .object (svc , "get_model_by_display_name" , return_value = {"model_id" : 123 }) as mock_get , \
512+ mock .patch .object (svc , "update_model_record" ) as mock_update :
513+ await svc .update_single_model_for_tenant ("u1" , "t1" , model )
514+ mock_get .assert_called_once_with ("existing_name" , "t1" )
515+ mock_update .assert_called_once_with (123 , model , "u1" )
516+
517+
518+ async def test_update_single_model_for_tenant_type_conversion ():
519+ """Test that string model_id is properly converted to int for comparison."""
520+ svc = import_svc ()
521+
522+ model = {"model_id" : "456" , "display_name" : "test_name" }
523+ # Return the same model_id as int to test type conversion
524+ with mock .patch .object (svc , "get_model_by_display_name" , return_value = {"model_id" : 456 }) as mock_get , \
525+ mock .patch .object (svc , "update_model_record" ) as mock_update :
526+ await svc .update_single_model_for_tenant ("u1" , "t1" , model )
527+ mock_get .assert_called_once_with ("test_name" , "t1" )
528+ mock_update .assert_called_once_with (456 , model , "u1" )
529+
530+
531+ async def test_update_single_model_for_tenant_different_model_conflict ():
532+ """Test that updating with a display name used by a different model raises conflict."""
533+ svc = import_svc ()
534+
535+ model = {"model_id" : "789" , "display_name" : "conflict_name" }
536+ # Return a different model_id to simulate name conflict
537+ with mock .patch .object (svc , "get_model_by_display_name" , return_value = {"model_id" : 999 }):
538+ with pytest .raises (Exception ) as exc :
539+ await svc .update_single_model_for_tenant ("u1" , "t1" , model )
540+ assert "Failed to update model" in str (exc .value )
541+ assert "Name conflict_name is already in use" in str (exc .value )
542+
543+
505544async def test_batch_update_models_for_tenant_success ():
506545 svc = import_svc ()
507546
0 commit comments