1
0
mirror of synced 2025-12-25 02:09:19 -05:00

Source Salesforce: Migrating to non-deprecated authenticator (#38065)

This commit is contained in:
Maxime Carbonneau-Leclerc
2024-05-09 14:36:29 -04:00
committed by GitHub
parent d26bd10c87
commit 676b52e467
9 changed files with 24 additions and 16 deletions

View File

@@ -64,7 +64,7 @@ class BulkStreamTest(TestCase):
self._http_mocker = HttpMocker()
self._http_mocker.__enter__()
given_authentication(self._http_mocker, _CLIENT_ID, _CLIENT_SECRET, _REFRESH_TOKEN, _INSTANCE_URL)
given_authentication(self._http_mocker, _CLIENT_ID, _CLIENT_SECRET, _REFRESH_TOKEN, _INSTANCE_URL, _ACCESS_TOKEN)
def tearDown(self) -> None:
self._http_mocker.__exit__(None, None, None)
@@ -197,7 +197,7 @@ class BulkStreamTest(TestCase):
JobInfoResponseBuilder().with_id(_JOB_ID).with_state("Failed").build(),
)
self._http_mocker.get(
create_standard_http_request(_STREAM_NAME, [_A_FIELD_NAME]),
create_standard_http_request(_STREAM_NAME, [_A_FIELD_NAME], _ACCESS_TOKEN),
create_standard_http_response([_A_FIELD_NAME]),
)
self._mock_delete_job(_JOB_ID)

View File

@@ -28,8 +28,11 @@ _REFRESH_TOKEN = "a_refresh_token"
_STREAM_NAME = UNSUPPORTED_BULK_API_SALESFORCE_OBJECTS[0]
def create_http_request(stream_name: str, field_names: List[str]) -> HttpRequest:
return HttpRequest(f"{_BASE_URL}/queryAll?q=SELECT+{','.join(field_names)}+FROM+{stream_name}+")
def create_http_request(stream_name: str, field_names: List[str], access_token: Optional[str] = None) -> HttpRequest:
return HttpRequest(
f"{_BASE_URL}/queryAll?q=SELECT+{','.join(field_names)}+FROM+{stream_name}+",
headers={"Authorization": f"Bearer {access_token}"} if access_token else None
)
def create_http_response(field_names: List[str], record_count: int = 1) -> HttpResponse:

View File

@@ -43,14 +43,14 @@ def read(
return entrypoint_read(_source(catalog, config, state), config, catalog, state, expecting_exception)
def given_authentication(http_mocker: HttpMocker, client_id: str, client_secret: str, refresh_token: str, instance_url: str) -> None:
def given_authentication(http_mocker: HttpMocker, client_id: str, client_secret: str, refresh_token: str, instance_url: str, access_token: str = "any_access_token") -> None:
http_mocker.post(
HttpRequest(
"https://login.salesforce.com/services/oauth2/token",
query_params=ANY_QUERY_PARAMS,
body=f"grant_type=refresh_token&client_id={client_id}&client_secret={client_secret}&refresh_token={refresh_token}"
),
HttpResponse(json.dumps({"access_token": "any_access_token", "instance_url": instance_url})),
HttpResponse(json.dumps({"access_token": access_token, "instance_url": instance_url})),
)