本文整理汇总了Python中simple_salesforce.Salesforce方法的典型用法代码示例。如果您正苦于以下问题:Python simple_salesforce.Salesforce方法的具体用法?Python simple_salesforce.Salesforce怎么用?Python simple_salesforce.Salesforce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simple_salesforce
的用法示例。
在下文中一共展示了simple_salesforce.Salesforce方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_query
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def make_query(self, query, include_deleted=False, query_params=None):
"""
Make a query to Salesforce.
:param query: The query to make to Salesforce.
:type query: str
:param include_deleted: True if the query should include deleted records.
:type include_deleted: bool
:param query_params: Additional optional arguments
:type query_params: dict
:return: The query result.
:rtype: dict
"""
conn = self.get_conn()
self.log.info("Querying for all objects")
query_params = query_params or {}
query_results = conn.query_all(query, include_deleted=include_deleted, **query_params)
self.log.info("Received results: Total size: %s; Done: %s",
query_results['totalSize'], query_results['done'])
return query_results
示例2: get_object_from_salesforce
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def get_object_from_salesforce(self, obj, fields):
"""
Get all instances of the `object` from Salesforce.
For each model, only get the fields specified in fields.
All we really do underneath the hood is run:
SELECT <fields> FROM <obj>;
:param obj: The object name to get from Salesforce.
:type obj: str
:param fields: The fields to get from the object.
:type fields: iterable
:return: all instances of the object from Salesforce.
:rtype: dict
"""
query = "SELECT {} FROM {}".format(",".join(fields), obj)
self.log.info("Making query to Salesforce: %s",
query if len(query) < 30 else " ... ".join([query[:15], query[-15:]]))
return self.make_query(query)
示例3: salesforce_request_wrapper
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def salesforce_request_wrapper(method):
"""
Annotation for querying against Salesforce. Will handle re-authorization if
the session is logged out, and raise exceptions for unsupported cases.
"""
def inner(self, *args, **kwargs):
if self.enabled:
if self.client:
try:
return method(self, *args, **kwargs)
except SalesforceExpiredSession:
self.login()
return method(self, *args, **kwargs)
# Need to catch OSError for the 'Connection aborted.' error when Salesforce reaps a connection
except OSError:
logger.warning('An OSError occurred while attempting to call {}'.format(method.__name__))
self.login()
return method(self, *args, **kwargs)
raise SalesforceNotConfiguredException(
_('Attempted to query Salesforce with no client for partner={}').format(self.partner.name)
)
return None
return inner
示例4: login
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def login(self):
# Need to instantiate a session with multiple retries to avoid OSError
session = requests.Session()
adapter = HTTPAdapter(max_retries=2)
session.mount('https://', adapter)
salesforce_config = self.partner.salesforce
sf_kwargs = {
'username': salesforce_config.username,
'password': salesforce_config.password,
'organizationId': salesforce_config.organization_id,
# security_token must be an empty string if organizationId is set
'security_token': '' if salesforce_config.organization_id else salesforce_config.token,
'domain': 'test' if salesforce_config.is_sandbox else None
}
self.client = Salesforce(session=session, **sf_kwargs)
示例5: _create_comment_return_body
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def _create_comment_return_body(user, body, course_run_key=None):
"""
Salesforce does not return the fully created Object, this method
creates the equivalent of what we would expect to return from our API
"""
return {
'user': {
'username': user.username,
'email': user.email or None,
'first_name': user.first_name or None,
'last_name': user.last_name or None,
},
'course_run_key': course_run_key,
'comment': body,
'created': datetime.now(timezone.utc).isoformat(),
}
示例6: get_simple_salesforce_connection
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def get_simple_salesforce_connection(project_config, org_config, api_version=None):
# Retry on long-running metadeploy jobs
retries = Retry(total=5, status_forcelist=(502, 503, 504), backoff_factor=0.3)
adapter = HTTPAdapter(max_retries=retries)
sf = simple_salesforce.Salesforce(
instance_url=org_config.instance_url,
session_id=org_config.access_token,
version=api_version or project_config.project__package__api_version,
)
try:
app = project_config.keychain.get_service("connectedapp")
client_name = app.client_id
except (ServiceNotValid, ServiceNotConfigured):
client_name = "CumulusCI/{}".format(__version__)
sf.headers.setdefault(CALL_OPTS_HEADER_KEY, "client={}".format(client_name))
sf.session.mount("http://", adapter)
sf.session.mount("https://", adapter)
return sf
示例7: connect
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def connect(connection_name, options):
table_name = f'salesforce_events_{connection_name}'
landing_log_table = f'data.{table_name}_connection'
comment = yaml_dump(module='salesforce_event_log', **options)
db.create_table(
name=landing_log_table,
cols=LANDING_TABLE_COLUMNS,
comment=comment,
stage_file_format='TYPE = JSON STRIP_OUTER_ARRAY = TRUE',
stage_copy_options='PURGE = TRUE',
)
db.execute(f'GRANT INSERT, SELECT ON {landing_log_table} TO ROLE {SA_ROLE}')
return {
'newStage': 'finalized',
'newMessage': "Salesforce Event Log ingestion table created!",
}
示例8: _post_validate
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def _post_validate(self):
try:
self.result.get_global_describe()
except simple_salesforce.SalesforceError as e:
self.errors.append("Unable to authenticate to Salesforce: {}".format(e))
self.result = None
示例9: jwt_login
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def jwt_login(consumer_id, username, private_key, api_version, sandbox=False):
endpoint = (
"https://test.salesforce.com"
if sandbox is True
else "https://login.salesforce.com"
)
jwt_payload = jwt.encode(
{
"exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=30),
"iss": consumer_id,
"aud": endpoint,
"sub": username,
},
private_key,
algorithm="RS256",
)
result = requests.post(
endpoint + "/services/oauth2/token",
data={
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": jwt_payload,
},
)
body = result.json()
if result.status_code != 200:
raise SalesforceAuthenticationFailed(body["error"], body["error_description"])
return simple_salesforce.Salesforce(
instance_url=body["instance_url"],
session_id=body["access_token"],
version=api_version,
)
示例10: setUpClass
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def setUpClass(cls):
cls.connection = Salesforce(
instance_url=os.environ["INSTANCE_URL"],
session_id=os.environ["ACCESS_TOKEN"],
version="48.0",
)
示例11: setUp
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def setUp(self):
self.connection = Salesforce(
instance_url=os.environ["INSTANCE_URL"],
session_id=os.environ["ACCESS_TOKEN"],
version=constants.OPTION_DEFAULTS["api-version"],
)
示例12: test_get_conn_exists
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def test_get_conn_exists(self):
self.salesforce_hook.conn = Mock(spec=Salesforce)
self.salesforce_hook.get_conn()
self.assertIsNotNone(self.salesforce_hook.conn.return_value)
示例13: test_describe_object
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def test_describe_object(self, mock_salesforce):
obj = "obj_name"
mock_salesforce.return_value.__setattr__(obj, Mock(spec=Salesforce))
self.salesforce_hook.conn = mock_salesforce.return_value
obj_description = self.salesforce_hook.describe_object(obj)
mock_salesforce.return_value.__getattr__(obj).describe.assert_called_once_with()
self.assertEqual(obj_description, mock_salesforce.return_value.__getattr__(obj).describe.return_value)
示例14: get_conn
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def get_conn(self):
"""
Sign into Salesforce, only if we are not already signed in.
"""
if not self.conn:
connection = self.get_connection(self.conn_id)
extras = connection.extra_dejson
self.conn = Salesforce(
username=connection.login,
password=connection.password,
security_token=extras['security_token'],
instance_url=connection.host,
domain=extras.get('domain', None)
)
return self.conn
示例15: describe_object
# 需要导入模块: import simple_salesforce [as 别名]
# 或者: from simple_salesforce import Salesforce [as 别名]
def describe_object(self, obj):
"""
Get the description of an object from Salesforce.
This description is the object's schema and
some extra metadata that Salesforce stores for each object.
:param obj: The name of the Salesforce object that we are getting a description of.
:type obj: str
:return: the description of the Salesforce object.
:rtype: dict
"""
conn = self.get_conn()
return conn.__getattr__(obj).describe()