32
32
from airbyte_cdk .utils import AirbyteTracedException
33
33
from conftest import encoding_symbols_parameters , generate_stream
34
34
from requests .exceptions import ChunkedEncodingError , HTTPError
35
- from salesforce_job_response_builder import SalesforceJobResponseBuilder
35
+ from salesforce_job_response_builder import JobInfoResponseBuilder
36
36
from source_salesforce .api import Salesforce
37
37
from source_salesforce .exceptions import AUTHENTICATION_ERROR_MESSAGE_MAPPING
38
38
from source_salesforce .source import SourceSalesforce
47
47
48
48
_A_CHUNKED_RESPONSE = [b"first chunk" , b"second chunk" ]
49
49
_A_JSON_RESPONSE = {"id" : "any id" }
50
- _A_SUCCESSFUL_JOB_CREATION_RESPONSE = SalesforceJobResponseBuilder ().with_state ("JobComplete" ).get_response ()
50
+ _A_SUCCESSFUL_JOB_CREATION_RESPONSE = JobInfoResponseBuilder ().with_state ("JobComplete" ).get_response ()
51
51
_A_PK = "a_pk"
52
52
_A_STREAM_NAME = "a_stream_name"
53
53
@@ -179,31 +179,6 @@ def test_stream_contains_unsupported_properties_by_bulk(stream_config, stream_ap
179
179
assert not isinstance (stream , BulkSalesforceStream )
180
180
181
181
182
- def test_bulk_sync_pagination (stream_config , stream_api , requests_mock ):
183
- stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config , stream_api )
184
- job_id = "fake_job"
185
- requests_mock .register_uri ("POST" , stream .path (), json = {"id" : job_id })
186
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = SalesforceJobResponseBuilder ().with_id (job_id ).with_state ("JobComplete" ).get_response ())
187
- resp_text = ["Field1,LastModifiedDate,ID" ] + [f"test,2021-11-16,{ i } " for i in range (5 )]
188
- result_uri = requests_mock .register_uri (
189
- "GET" ,
190
- stream .path () + f"/{ job_id } /results" ,
191
- [
192
- {"text" : "\n " .join (resp_text ), "headers" : {"Sforce-Locator" : "somelocator_1" }},
193
- {"text" : "\n " .join (resp_text ), "headers" : {"Sforce-Locator" : "somelocator_2" }},
194
- {"text" : "\n " .join (resp_text ), "headers" : {"Sforce-Locator" : "null" }},
195
- ],
196
- )
197
- requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id } " )
198
-
199
- stream_slices = next (iter (stream .stream_slices (sync_mode = SyncMode .incremental )))
200
- loaded_ids = [int (record ["ID" ]) for record in stream .read_records (sync_mode = SyncMode .full_refresh , stream_slice = stream_slices )]
201
- assert loaded_ids == [0 , 1 , 2 , 3 , 4 , 0 , 1 , 2 , 3 , 4 , 0 , 1 , 2 , 3 , 4 ]
202
- assert result_uri .call_count == 3
203
- assert result_uri .request_history [1 ].query == "locator=somelocator_1"
204
- assert result_uri .request_history [2 ].query == "locator=somelocator_2"
205
-
206
-
207
182
def _prepare_mock (m , stream ):
208
183
job_id = "fake_job_1"
209
184
m .register_uri ("POST" , stream .path (), json = {"id" : job_id })
@@ -481,7 +456,7 @@ def test_given_retryable_error_when_download_data_then_retry(send_http_request_p
481
456
@patch ("source_salesforce.source.BulkSalesforceStream._non_retryable_send_http_request" )
482
457
def test_given_first_download_fail_when_download_data_then_retry_job_only_once (send_http_request_patch ):
483
458
sf_api = Mock ()
484
- sf_api .generate_schema .return_value = SalesforceJobResponseBuilder ().with_state ("JobComplete" ).get_response ()
459
+ sf_api .generate_schema .return_value = JobInfoResponseBuilder ().with_state ("JobComplete" ).get_response ()
485
460
sf_api .instance_url = "http://test_given_first_download_fail_when_download_data_then_retry_job.com"
486
461
job_creation_return_values = [_A_JSON_RESPONSE , _A_SUCCESSFUL_JOB_CREATION_RESPONSE ]
487
462
send_http_request_patch .return_value .json .side_effect = job_creation_return_values * 2
@@ -869,13 +844,13 @@ def test_bulk_stream_request_params_states(stream_config_date_format, stream_api
869
844
stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config_date_format , stream_api , state = state , legacy = True )
870
845
871
846
job_id_1 = "fake_job_1"
872
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } " , [{"json" : SalesforceJobResponseBuilder ().with_id (job_id_1 ).with_state ("JobComplete" ).get_response ()}])
847
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } " , [{"json" : JobInfoResponseBuilder ().with_id (job_id_1 ).with_state ("JobComplete" ).get_response ()}])
873
848
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_1 } " )
874
849
requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-01-15,1" )
875
850
requests_mock .register_uri ("PATCH" , stream .path () + f"/{ job_id_1 } " )
876
851
877
852
job_id_2 = "fake_job_2"
878
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_2 } " , [{"json" : SalesforceJobResponseBuilder ().with_id (job_id_2 ).with_state ("JobComplete" ).get_response ()}])
853
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_2 } " , [{"json" : JobInfoResponseBuilder ().with_id (job_id_2 ).with_state ("JobComplete" ).get_response ()}])
879
854
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_2 } " )
880
855
requests_mock .register_uri (
881
856
"GET" , stream .path () + f"/{ job_id_2 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-04-01,2\n test,2023-02-20,22"
@@ -886,7 +861,7 @@ def test_bulk_stream_request_params_states(stream_config_date_format, stream_api
886
861
queries_history = requests_mock .register_uri (
887
862
"POST" , stream .path (), [{"json" : {"id" : job_id_1 }}, {"json" : {"id" : job_id_2 }}, {"json" : {"id" : job_id_3 }}]
888
863
)
889
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } " , [{"json" : SalesforceJobResponseBuilder ().with_id (job_id_3 ).with_state ("JobComplete" ).get_response ()}])
864
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } " , [{"json" : JobInfoResponseBuilder ().with_id (job_id_3 ).with_state ("JobComplete" ).get_response ()}])
890
865
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_3 } " )
891
866
requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-04-01,3" )
892
867
requests_mock .register_uri ("PATCH" , stream .path () + f"/{ job_id_3 } " )
@@ -945,7 +920,7 @@ def test_stream_slices_for_substream(stream_config, stream_api, requests_mock):
945
920
946
921
job_id = "fake_job"
947
922
requests_mock .register_uri ("POST" , stream .path (), json = {"id" : job_id })
948
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = SalesforceJobResponseBuilder ().with_id (job_id ).with_state ("JobComplete" ).get_response ())
923
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = JobInfoResponseBuilder ().with_id (job_id ).with_state ("JobComplete" ).get_response ())
949
924
requests_mock .register_uri (
950
925
"GET" ,
951
926
stream .path () + f"/{ job_id } /results" ,
0 commit comments