@@ -504,8 +504,9 @@ class TestRestClientSyncAssignment:
504504 Generated by Claude Sonnet 4.5
505505 """
506506
507- def test_sync_assignment_sends_only_object_ansible_id_for_registered_objects (self , rando , organization , org_admin_rd , mocker ):
507+ def test_sync_assignment_sends_only_object_ansible_id_for_registered_objects (self , rando , organization , org_admin_rd ):
508508 """Test that sync_assignment removes object_id when object_ansible_id is present"""
509+ from unittest .mock import MagicMock , patch
509510 from ansible_base .resource_registry .rest_client import ResourceAPIClient
510511
511512 # Create an assignment to an organization (which has a resource)
@@ -515,24 +516,24 @@ def test_sync_assignment_sends_only_object_ansible_id_for_registered_objects(sel
515516 client = ResourceAPIClient (service_url = 'http://example.com' , service_path = '/api/v1/service-index/' )
516517
517518 # Mock the _sync_assignment method to capture what data is sent
518- mock_sync = mocker .patch .object (client , '_sync_assignment' )
519+ with patch .object (client , '_sync_assignment' , return_value = MagicMock ()) as mock_sync :
520+ # Call sync_assignment
521+ client .sync_assignment (assignment )
519522
520- # Call sync_assignment
521- client .sync_assignment (assignment )
523+ # Verify _sync_assignment was called
524+ assert mock_sync .called
525+ sent_data = mock_sync .call_args [0 ][0 ]
522526
523- # Verify _sync_assignment was called
524- assert mock_sync . called
525- sent_data = mock_sync . call_args [ 0 ][ 0 ]
527+ # Should have object_ansible_id
528+ assert 'object_ansible_id' in sent_data
529+ assert sent_data [ 'object_ansible_id' ] == str ( organization . resource . ansible_id )
526530
527- # Should have object_ansible_id
528- assert 'object_ansible_id' in sent_data
529- assert sent_data ['object_ansible_id' ] == str (organization .resource .ansible_id )
531+ # Should NOT have object_id (removed by sync_assignment)
532+ assert 'object_id' not in sent_data , "object_id should not be sent for registered objects"
530533
531- # Should NOT have object_id (removed by sync_assignment)
532- assert 'object_id' not in sent_data , "object_id should not be sent for registered objects"
533-
534- def test_sync_assignment_sends_only_object_id_for_non_registered_objects (self , rando , inventory , inv_rd , mocker ):
534+ def test_sync_assignment_sends_only_object_id_for_non_registered_objects (self , rando , inventory , inv_rd ):
535535 """Test that sync_assignment keeps object_id when object_ansible_id is None"""
536+ from unittest .mock import MagicMock , patch
536537 from ansible_base .resource_registry .rest_client import ResourceAPIClient
537538
538539 # Create an assignment to an inventory (which doesn't have a resource)
@@ -542,21 +543,20 @@ def test_sync_assignment_sends_only_object_id_for_non_registered_objects(self, r
542543 client = ResourceAPIClient (service_url = 'http://example.com' , service_path = '/api/v1/service-index/' )
543544
544545 # Mock the _sync_assignment method to capture what data is sent
545- mock_sync = mocker .patch .object (client , '_sync_assignment' )
546-
547- # Call sync_assignment
548- client .sync_assignment (assignment )
546+ with patch .object (client , '_sync_assignment' , return_value = MagicMock ()) as mock_sync :
547+ # Call sync_assignment
548+ client .sync_assignment (assignment )
549549
550- # Verify _sync_assignment was called
551- assert mock_sync .called
552- sent_data = mock_sync .call_args [0 ][0 ]
550+ # Verify _sync_assignment was called
551+ assert mock_sync .called
552+ sent_data = mock_sync .call_args [0 ][0 ]
553553
554- # Should have object_id
555- assert 'object_id' in sent_data
556- assert sent_data ['object_id' ] == str (inventory .id )
554+ # Should have object_id
555+ assert 'object_id' in sent_data
556+ assert sent_data ['object_id' ] == str (inventory .id )
557557
558- # object_ansible_id should either be absent or None
559- assert sent_data .get ('object_ansible_id' ) is None
558+ # object_ansible_id should either be absent or None
559+ assert sent_data .get ('object_ansible_id' ) is None
560560
561561
562562@pytest .mark .django_db
0 commit comments