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
36
from source_salesforce .api import Salesforce
36
37
from source_salesforce .exceptions import AUTHENTICATION_ERROR_MESSAGE_MAPPING
37
38
from source_salesforce .source import SourceSalesforce
46
47
47
48
_A_CHUNKED_RESPONSE = [b"first chunk" , b"second chunk" ]
48
49
_A_JSON_RESPONSE = {"id" : "any id" }
49
- _A_SUCCESSFUL_JOB_CREATION_RESPONSE = { "state" : " JobComplete"}
50
+ _A_SUCCESSFUL_JOB_CREATION_RESPONSE = SalesforceJobResponseBuilder (). with_state ( " JobComplete"). get_response ()
50
51
_A_PK = "a_pk"
51
52
_A_STREAM_NAME = "a_stream_name"
52
53
@@ -182,7 +183,7 @@ def test_bulk_sync_pagination(stream_config, stream_api, requests_mock):
182
183
stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config , stream_api )
183
184
job_id = "fake_job"
184
185
requests_mock .register_uri ("POST" , stream .path (), json = {"id" : job_id })
185
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = { "state" : " JobComplete"} )
186
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = SalesforceJobResponseBuilder (). with_id ( job_id ). with_state ( " JobComplete"). get_response () )
186
187
resp_text = ["Field1,LastModifiedDate,ID" ] + [f"test,2021-11-16,{ i } " for i in range (5 )]
187
188
result_uri = requests_mock .register_uri (
188
189
"GET" ,
@@ -217,14 +218,6 @@ def _get_result_id(stream):
217
218
return int (list (stream .read_records (sync_mode = SyncMode .full_refresh , stream_slice = stream_slices ))[0 ]["ID" ])
218
219
219
220
220
- def test_bulk_sync_successful (stream_config , stream_api ):
221
- stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config , stream_api )
222
- with requests_mock .Mocker () as m :
223
- job_id = _prepare_mock (m , stream )
224
- m .register_uri ("GET" , stream .path () + f"/{ job_id } " , [{"json" : {"state" : "JobComplete" }}])
225
- assert _get_result_id (stream ) == 1
226
-
227
-
228
221
def test_bulk_sync_successful_long_response (stream_config , stream_api ):
229
222
stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config , stream_api )
230
223
with requests_mock .Mocker () as m :
@@ -488,7 +481,7 @@ def test_given_retryable_error_when_download_data_then_retry(send_http_request_p
488
481
@patch ("source_salesforce.source.BulkSalesforceStream._non_retryable_send_http_request" )
489
482
def test_given_first_download_fail_when_download_data_then_retry_job_only_once (send_http_request_patch ):
490
483
sf_api = Mock ()
491
- sf_api .generate_schema .return_value = {}
484
+ sf_api .generate_schema .return_value = SalesforceJobResponseBuilder (). with_state ( "JobComplete" ). get_response ()
492
485
sf_api .instance_url = "http://test_given_first_download_fail_when_download_data_then_retry_job.com"
493
486
job_creation_return_values = [_A_JSON_RESPONSE , _A_SUCCESSFUL_JOB_CREATION_RESPONSE ]
494
487
send_http_request_patch .return_value .json .side_effect = job_creation_return_values * 2
@@ -876,13 +869,13 @@ def test_bulk_stream_request_params_states(stream_config_date_format, stream_api
876
869
stream : BulkIncrementalSalesforceStream = generate_stream ("Account" , stream_config_date_format , stream_api , state = state , legacy = True )
877
870
878
871
job_id_1 = "fake_job_1"
879
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } " , [{"json" : { "state" : " JobComplete"} }])
872
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } " , [{"json" : SalesforceJobResponseBuilder (). with_id ( job_id_1 ). with_state ( " JobComplete"). get_response () }])
880
873
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_1 } " )
881
874
requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_1 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-01-15,1" )
882
875
requests_mock .register_uri ("PATCH" , stream .path () + f"/{ job_id_1 } " )
883
876
884
877
job_id_2 = "fake_job_2"
885
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_2 } " , [{"json" : { "state" : " JobComplete"} }])
878
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_2 } " , [{"json" : SalesforceJobResponseBuilder (). with_id ( job_id_2 ). with_state ( " JobComplete"). get_response () }])
886
879
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_2 } " )
887
880
requests_mock .register_uri (
888
881
"GET" , stream .path () + f"/{ job_id_2 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-04-01,2\n test,2023-02-20,22"
@@ -893,7 +886,7 @@ def test_bulk_stream_request_params_states(stream_config_date_format, stream_api
893
886
queries_history = requests_mock .register_uri (
894
887
"POST" , stream .path (), [{"json" : {"id" : job_id_1 }}, {"json" : {"id" : job_id_2 }}, {"json" : {"id" : job_id_3 }}]
895
888
)
896
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } " , [{"json" : { "state" : " JobComplete"} }])
889
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } " , [{"json" : SalesforceJobResponseBuilder (). with_id ( job_id_3 ). with_state ( " JobComplete"). get_response () }])
897
890
requests_mock .register_uri ("DELETE" , stream .path () + f"/{ job_id_3 } " )
898
891
requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id_3 } /results" , text = "Field1,LastModifiedDate,ID\n test,2023-04-01,3" )
899
892
requests_mock .register_uri ("PATCH" , stream .path () + f"/{ job_id_3 } " )
@@ -952,7 +945,7 @@ def test_stream_slices_for_substream(stream_config, stream_api, requests_mock):
952
945
953
946
job_id = "fake_job"
954
947
requests_mock .register_uri ("POST" , stream .path (), json = {"id" : job_id })
955
- requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = { "state" : " JobComplete"} )
948
+ requests_mock .register_uri ("GET" , stream .path () + f"/{ job_id } " , json = SalesforceJobResponseBuilder (). with_id ( job_id ). with_state ( " JobComplete"). get_response () )
956
949
requests_mock .register_uri (
957
950
"GET" ,
958
951
stream .path () + f"/{ job_id } /results" ,
0 commit comments