Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_connection to SalesforceHook #27921

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions airflow/providers/salesforce/hooks/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,15 @@ def object_to_df(
df["time_fetched_from_salesforce"] = fetched_time

return df

def test_connection(self):
"""Test the Salesforce connectivity"""
try:
self.describe_object("Account")
status = True
message = "Connection successfully tested"
except Exception as e:
status = False
message = str(e)

return status, message
20 changes: 20 additions & 0 deletions tests/providers/salesforce/hooks/test_salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,23 @@ def test_backcompat_prefix_both_prefers_short(self, mock_client):
username=None,
version="52.0",
)

@patch(
"airflow.providers.salesforce.hooks.salesforce.SalesforceHook.describe_object",
return_value={"fields": [{"name": "field_1"}, {"name": "field_2"}]},
)
def test_connection_success(self, mock_describe_object):
hook = SalesforceHook("my_conn")
status, msg = hook.test_connection()
assert status is True
assert msg == "Connection successfully tested"

@patch(
"airflow.providers.salesforce.hooks.salesforce.SalesforceHook.describe_object",
side_effect=Exception("Test"),
)
def test_connection_failure(self, mock_describe_object):
hook = SalesforceHook("my_conn")
status, msg = hook.test_connection()
assert status is False
assert msg == "Test"