turbaszek commented on a change in pull request #10760:
URL: https://github.com/apache/airflow/pull/10760#discussion_r487570484



##########
File path: 
tests/providers/google/cloud/transfers/test_salesforce_to_gcs_system.py
##########
@@ -0,0 +1,73 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from contextlib import contextmanager
+import json
+import os
+import pytest
+
+from airflow.exceptions import AirflowException
+from airflow.models import Connection
+from airflow.utils.process_utils import patch_environ
+from tests.providers.google.cloud.utils.gcp_authenticator import 
GCP_BIGQUERY_KEY
+from tests.test_utils.gcp_system_helpers import CLOUD_DAG_FOLDER, 
GoogleSystemTest, provide_gcp_context
+
+CREDENTIALS_DIR = os.environ.get('CREDENTIALS_DIR', 
'/files/airflow-breeze-config/keys')
+SALESFORCE_KEY = 'salesforce.json'
+SALESFORCE_CREDENTIALS_PATH = os.path.join(CREDENTIALS_DIR, SALESFORCE_KEY)
+CONFIG_REQUIRED_FIELDS = ["host", "login", "password", "security_token"]
+SALESFORCE_CONNECTION_ID = os.environ.get('FACEBOOK_CONNECTION_ID', 
'salesforce_default')
+CONNECTION_TYPE = os.environ.get('CONNECTION_TYPE', 'http')
+
+
+@contextmanager
+def provide_facebook_connection(key_file_path: str):
+    """
+    Context manager that provides a temporary value of SALESFORCE_DEFAULT 
connection.
+
+    :param key_file_path: Path to file with SALESFORCE credentials .json file.
+    :type key_file_path: str
+    """
+    if not key_file_path.endswith(".json"):
+        raise AirflowException("Use a JSON key file.")
+    with open(key_file_path, 'r') as credentials:
+        creds = json.load(credentials)
+    missing_keys = CONFIG_REQUIRED_FIELDS - creds.keys()
+    if missing_keys:
+        message = "{missing_keys} fields are 
missing".format(missing_keys=missing_keys)
+        raise AirflowException(message)
+    conn = Connection(
+        conn_id=SALESFORCE_CONNECTION_ID,
+        conn_type=CONNECTION_TYPE,
+        host=creds["host"],
+        login=creds["login"],
+        password=creds["password"],
+        extra=json.dumps({"security_token": creds["security_token"]}),
+    )
+    with patch_environ({f"AIRFLOW_CONN_{conn.conn_id.upper()}": 
conn.get_uri()}):
+        yield
+
+
+@pytest.mark.backend("mysql", "postgres")
+@pytest.mark.credential_file(GCP_BIGQUERY_KEY)
+@pytest.mark.credential_file(SALESFORCE_KEY)
+@pytest.mark.system("google.cloud")

Review comment:
       Should we also mark it as salesforce?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to