@@ -591,6 +591,47 @@ def test_select_records_standard_strategy_success(self, download_mock):
591591 == 3
592592 )
593593
594+ @mock .patch ("cumulusci.tasks.bulkdata.step.download_file" )
595+ def test_select_records_zero_load_records (self , download_mock ):
596+ # Set up mock context and BulkApiDmlOperation
597+ context = mock .Mock ()
598+ step = BulkApiDmlOperation (
599+ sobject = "Contact" ,
600+ operation = DataOperationType .QUERY ,
601+ api_options = {"batch_size" : 10 , "update_key" : "LastName" },
602+ context = context ,
603+ fields = ["LastName" ],
604+ selection_strategy = SelectStrategy .STANDARD ,
605+ content_type = "JSON" ,
606+ )
607+
608+ # Mock Bulk API responses
609+ step .bulk .endpoint = "https://test"
610+ step .bulk .create_query_job .return_value = "JOB"
611+ step .bulk .query .return_value = "BATCH"
612+ step .bulk .get_query_batch_result_ids .return_value = ["RESULT" ]
613+
614+ # Mock the downloaded CSV content with a single record
615+ download_mock .return_value = io .StringIO ('[{"Id":"003000000000001"}]' )
616+
617+ # Mock the _wait_for_job method to simulate a successful job
618+ step ._wait_for_job = mock .Mock ()
619+ step ._wait_for_job .return_value = DataOperationJobResult (
620+ DataOperationStatus .SUCCESS , [], 0 , 0
621+ )
622+
623+ # Prepare input records
624+ records = iter ([])
625+
626+ # Execute the select_records operation
627+ step .start ()
628+ step .select_records (records )
629+ step .end ()
630+
631+ # Get the results and assert their properties
632+ results = list (step .get_results ())
633+ assert len (results ) == 0 # Expect 0 results (no records to process)
634+
594635 @mock .patch ("cumulusci.tasks.bulkdata.step.download_file" )
595636 def test_select_records_standard_strategy_failure__no_records (self , download_mock ):
596637 # Set up mock context and BulkApiDmlOperation
@@ -1927,6 +1968,45 @@ def test_select_records_standard_strategy_success(self):
19271968 == 3
19281969 )
19291970
1971+ @responses .activate
1972+ def test_select_records_zero_load_records (self ):
1973+ mock_describe_calls ()
1974+ task = _make_task (
1975+ LoadData ,
1976+ {
1977+ "options" : {
1978+ "database_url" : "sqlite:///test.db" ,
1979+ "mapping" : "mapping.yml" ,
1980+ }
1981+ },
1982+ )
1983+ task .project_config .project__package__api_version = CURRENT_SF_API_VERSION
1984+ task ._init_task ()
1985+
1986+ step = RestApiDmlOperation (
1987+ sobject = "Contact" ,
1988+ operation = DataOperationType .UPSERT ,
1989+ api_options = {"batch_size" : 10 , "update_key" : "LastName" },
1990+ context = task ,
1991+ fields = ["LastName" ],
1992+ selection_strategy = SelectStrategy .STANDARD ,
1993+ )
1994+
1995+ results = {
1996+ "records" : [],
1997+ "done" : True ,
1998+ }
1999+ step .sf .restful = mock .Mock ()
2000+ step .sf .restful .return_value = results
2001+ records = iter ([])
2002+ step .start ()
2003+ step .select_records (records )
2004+ step .end ()
2005+
2006+ # Get the results and assert their properties
2007+ results = list (step .get_results ())
2008+ assert len (results ) == 0 # Expect 0 results (matching the input records count)
2009+
19302010 @responses .activate
19312011 def test_select_records_standard_strategy_success_pagination (self ):
19322012 mock_describe_calls ()
0 commit comments