コード例 #1
0
def test_exec_anon_negative():
    testutil.add_response("login_response_200")
    testutil.add_response("exec_anon_response_no_body")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    ea_result = client.execute_anonymous("system.debug('Hello world.');")
    assert ea_result[0] is None
コード例 #2
0
def test_client_kwargs__in_sobjects_at_function_level():
    """
    Test that the keywords level args are still maintained at the sobject level
    """
    proxy = {"https": "someproxy.net:8080"}
    testutil.add_response("login_response_200")
    testutil.add_response("update_response_204_v42")
    testutil.add_response("logout_response_200")
    client_args = {
        "username": testutil.username,
        "password": testutil.password,
        "client_id": testutil.client_id,
        "client_secret": testutil.client_secret,
        "version": "37.0",
        "proxies": proxy
    }
    fn_level_kwarg = {'version': '42.0'}
    with sfdc.client(**client_args) as client:
        update_result = client.sobjects(id="0010Y0000055YG7QAM",
                                        object_type="Account").update(
                                            {"Name": "sfdc_py 2"},
                                            **fn_level_kwarg)
        assert update_result[0] == testutil.mock_responses[
            "update_response_204_v42"]["body"]
        assert update_result[1].status == 204
        assert update_result[1].proxies['https'] is 'someproxy.net:8080'
コード例 #3
0
def test_function_kwarg_overrides_client_kwarg():
    """
    Test that kwargs value defined at the function level are used in favour of the client kwargs if
    the latter are defined
    """
    testutil.add_response("login_response_200")
    testutil.add_response("query_response_200")
    testutil.add_response("logout_response_200")
    client_timeout = 15
    function_timeout = 30

    client_args = {
        "username": testutil.username,
        "password": testutil.password,
        "client_id": testutil.client_id,
        "client_secret": testutil.client_secret,
        "version": "37.0",
        "timeout": client_timeout
    }

    function_kwargs = {"timeout": function_timeout}

    with sfdc.client(**client_args) as client:
        # kwarg defined at function level
        qr = client.query("SELECT Id, Name FROM Account LIMIT 10",
                          **function_kwargs)
        assert qr[1].timeout == float(
            function_timeout), 'Timeout value in function was not used'
        # kwarg defined at client level
        qr = client.query("SELECT Id, Name FROM Account LIMIT 10")
        assert qr[1].timeout == float(
            client_timeout), 'Timeout value in client was not used'
コード例 #4
0
ファイル: test_logout.py プロジェクト: zympz/SalesforcePy
def test_logout():
    testutil.add_response("login_response_200")
    testutil.add_response("logout_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    logout = client.logout()
    assert logout[0] is None
    assert logout[1].status == 200
コード例 #5
0
def test_query_sobj_row_with_blob_negative():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("query_attachments_before_blob_200")
    testutil.add_response("query_attachments_blob_no_body")
    client = testutil.get_client()
    query_result = client.sobjects(
        object_type="Attachment",
        id="00P0Y000000hUviUAE",
        binary_field="Body").query()

    assert query_result[0] == testutil.mock_responses["query_attachments_before_blob_200"]["body"]
    assert query_result[1].status == 200
    assert query_result[2].status == 200
    assert query_result[2].response is None
コード例 #6
0
def test_get_job_info():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("jobs_create_200")
    testutil.add_response("jobs_get_job_info_200")

    client = testutil.get_client()
    job = ACCOUNTS_INSERT_JOB
    create_result = client.jobs.ingest.create(job_resource=job)
    job_id = create_result[0].get("id")
    get_result = client.jobs.ingest.get(job_id=job_id)

    assert get_result[0] == testutil.mock_responses.get(
        "jobs_get_job_info_200").get("body")
    assert get_result[1].status == 200
コード例 #7
0
def test_describe_global():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("describe_global_response_200")
    client = testutil.get_client()
    describe_result = client.sobjects().describe_global()
    assert describe_result[0] == testutil.mock_responses["describe_global_response_200"]["body"]
    assert describe_result[1].status == 200
コード例 #8
0
def test_update_close_job():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("jobs_create_200")
    testutil.add_response("jobs_update_close_200")

    client = testutil.get_client()
    job = ACCOUNTS_INSERT_JOB
    create_result = client.jobs.ingest.create(job_resource=job)
    job_id = create_result[0].get("id")
    update_result = client.jobs.ingest.update(job_id=job_id,
                                              state=UPLOAD_COMPLETED)

    assert update_result[0] == testutil.mock_responses.get(
        "jobs_update_close_200").get("body")
    assert update_result[1].status == 200
コード例 #9
0
def test_context_manager_negative():

    testutil.add_response("login_response_200")
    testutil.add_response("query_response_200")

    client_args = {
        "username": testutil.username,
        "password": testutil.password,
        "client_id": testutil.client_id,
        "client_secret": testutil.client_secret,
        "version": "37.0"
    }

    def logout():
        raise Exception("Monkey patchin'...")

    with sfdc.client(**client_args) as client:
        client.query("SELECT Id, Name FROM Account LIMIT 10")
        client.logout = logout
    """
        The above should have made 2 calls: login, query
    """
    assert len(responses.calls) == 2
コード例 #10
0
def test_update():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("update_response_204")
    client = testutil.get_client()
    update_result = client.sobjects(
        id="0010Y0000055YG7QAM", object_type="Account").update({"Name": "sfdc_py 2"})
    assert update_result[0] == testutil.mock_responses["update_response_204"]["body"]
    assert update_result[1].status == 204
コード例 #11
0
def test_exec_anon():
    testutil.add_response("login_response_200")
    testutil.add_response("exec_anon_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    ea_result = client.execute_anonymous("system.debug('Hello world.');")
    assert ea_result[0] == testutil.mock_responses["exec_anon_response_200"][
        "body"]
    assert ea_result[1].status == 200
コード例 #12
0
def test_query_more_singlebatch():
    testutil.add_response("login_response_200")
    testutil.add_response("query_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    query_result = client.query_more("SELECT Id, Name FROM Account LIMIT 10")
    assert query_result[0][0] == testutil.mock_responses["query_response_200"][
        "body"]
    assert query_result[0][0].get("done")
コード例 #13
0
ファイル: test_logout.py プロジェクト: zympz/SalesforcePy
def test_logout_with_proxy():
    testutil.add_response("login_response_200")
    testutil.add_response("logout_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client_with_proxy()
    logout = client.logout()
    assert logout[0] is None
    assert logout[1].status == 200
    assert logout[1].proxies.get("https") is testutil.proxies.get("https")
コード例 #14
0
def test_upsert_non_existing_record():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("upsert_non_existing_record_response_201")
    client = testutil.get_client()
    update_result = client.sobjects(
        id="333", object_type="Upsert_Object__c", external_id='External_Field__c').upsert({"Name": "Test Upsert Name"})
    assert update_result[0] == testutil.mock_responses["upsert_non_existing_record_response_201"]["body"]
    assert update_result[1].status == 201
コード例 #15
0
def test_describe_with_proxy():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("describe_response_200")
    client = testutil.get_client_with_proxy()
    describe_result = client.sobjects(object_type="Idea").describe()
    assert describe_result[0] == testutil.mock_responses["describe_response_200"]["body"]
    assert describe_result[1].status == 200
    assert describe_result[1].proxies.get("https") is testutil.proxies.get("https")
コード例 #16
0
def test_query():
    testutil.add_response("login_response_200")
    testutil.add_response("query_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    query_result = client.query("SELECT Id, Name FROM Account LIMIT 10")
    assert query_result[0] == testutil.mock_responses["query_response_200"][
        "body"]
    assert query_result[1].status == 200
コード例 #17
0
def test_query_sobj_row_negative():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("query_sobj_row_response_no_body")
    client = testutil.get_client()
    query_result = client.sobjects(
        object_type="Account",
        id="0010Y0000056ljcQAA").query()
    assert query_result[0] is None
コード例 #18
0
def test_query_sobj_row_with_blob():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("query_attachments_before_blob_200")
    testutil.add_response("query_attachments_blob_200")
    client = testutil.get_client()
    query_result = client.sobjects(
        object_type="Attachment",
        id="00P0Y000000hUviUAE",
        binary_field="Body").query()
    blob_body = '"%s"' % (
        testutil.mock_responses["query_attachments_blob_200"]["body"])

    assert query_result[0] == testutil.mock_responses["query_attachments_before_blob_200"]["body"]
    assert query_result[1].status == 200
    assert query_result[2].status == 200
    assert query_result[2].response.content.decode("utf-8") == blob_body
コード例 #19
0
def test_query_approvals():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("approvals_response_200")
    client = testutil.get_client()
    ar = client.approvals()
    sfdc_response = ar[0]
    assert ar[1].status == 200
    assert ar[1].http_method is "GET"
    assert "approvals" in sfdc_response
コード例 #20
0
def test_upsert_existing_record_with_proxy():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("upsert_existing_record_response_204")
    client = testutil.get_client_with_proxy()
    update_result = client.sobjects(
        id="999", object_type="Upsert_Object__c", external_id='External_Field__c').upsert({"Name": "Test Upsert Name"})
    assert update_result[0] == testutil.mock_responses["upsert_existing_record_response_204"]["body"]
    assert update_result[1].status == 204
    assert update_result[1].proxies.get("https") is testutil.proxies.get("https")
コード例 #21
0
def test_query_sobj_row():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("query_sobj_row_response")
    client = testutil.get_client()
    query_result = client.sobjects(
        object_type="Account",
        id="0010Y0000056ljcQAA").query()
    assert query_result[0] == testutil.mock_responses["query_sobj_row_response"]["body"]
    assert query_result[1].status == 200
コード例 #22
0
def test_delete():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("delete_response_204")
    client = testutil.get_client()
    delete_result = client.sobjects(
        id="0010Y0000055YG7QAM",
        object_type="Account").delete()
    assert delete_result[0] == testutil.mock_responses["delete_response_204"]["body"]
    assert delete_result[1].status == 204
コード例 #23
0
def test_search():
    testutil.add_response("login_response_200")
    testutil.add_response("search_response_200")
    testutil.add_response("api_version_response_200")
    client = testutil.get_client()
    search_result = client.search(
        "FIND {sfdc_py} RETURNING Account(Id, Name) LIMIT 5")
    assert search_result[0] == testutil.mock_responses["search_response_200"][
        "body"]
    assert search_result[1].status == 200
コード例 #24
0
def test_insert():
    testutil.add_response("login_response_200")
    testutil.add_response("insert_response_201")
    testutil.add_response("api_version_response_200")

    client = testutil.get_client()
    create_result = client.sobjects(
        object_type="Account").insert({"Name": "sfdc_py"})
    assert create_result[0] == testutil.mock_responses["insert_response_201"]["body"]
    assert create_result[1].status == 201
コード例 #25
0
def test_wave_dataset():
    testutil.add_response("login_response_200")
    testutil.add_response("wave_dataset_response_200")
    testutil.add_response("api_version_response_200")

    client = testutil.get_client()
    wave_result = client.wave.dataset("opportunities")

    assert wave_result[0] == testutil.mock_responses[
        "wave_dataset_response_200"]["body"]
    assert wave_result[1].status is 200
コード例 #26
0
def test_wave_query_no_response_body():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("wave_query_no_body")

    client = testutil.get_client()
    wave_result = client.wave.query(None)

    assert wave_result[0] is None
    assert wave_result[1].status == 500
    assert wave_result[1].exceptions[0].args[0] == 'Request body is null'
コード例 #27
0
def test_chatter_feed_item():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("chatter_feed_item_201")
    client = testutil.get_client()
    body = create_message_segments("005B0000001mOGj", ["005B0000001nDnV"],
                                   "Money, get away ")
    ch = client.chatter.feed_item(body)
    assert ch[1].status == 201
    chatter_response = ch[0]
    assert chatter_response.get("actor").get("type") == "TextPost"
コード例 #28
0
def test_wave_query():
    testutil.add_response("login_response_200")
    testutil.add_response("wave_query_response_200")
    testutil.add_response("api_version_response_200")

    client = testutil.get_client()
    wave_result = client.wave.query(query)

    assert wave_result[0] == testutil.mock_responses[
        "wave_query_response_200"]["body"]
    assert wave_result[1].status is 200
コード例 #29
0
def test_batches():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("jobs_create_200")
    testutil.add_response("jobs_batches_201")

    client = testutil.get_client()
    job = ACCOUNTS_INSERT_JOB
    create_result = client.jobs.ingest.create(job_resource=job)

    with open(ACCOUNTS_INSERT_BULK_CSV) as f:
        csv_file = f.read()
        job_id = create_result[0].get("id")
        batches_result = client.jobs.ingest.batches(job_id=job_id,
                                                    csv_file=csv_file)

        assert batches_result[0] == testutil.mock_responses.get(
            "jobs_batches_201").get("body")
        assert batches_result[1].status == 201
コード例 #30
0
def test_insert_blob_missing_body():
    testutil.add_response("login_response_200")
    testutil.add_response("api_version_response_200")
    testutil.add_response("insert_blob_response_400")
    client = testutil.get_client()
    # Create a file tuple ordered like so: ( filename, body, content_type )
    _file = ("sfdc_py.txt", "Hello world", "text/plain")

    insert_result = client.sobjects(object_type="Attachment").insert({  # Missing binary field "Body"
        "Name": "sfdc_py",
        "ParentId": "0010Y0000056ljcQAA",
        "Description": "An excellent package"
    }, binary=_file)    # Pass your file through using the binary kwarg
    assert insert_result[0] == testutil.mock_responses["insert_blob_response_400"]["body"]
    assert insert_result[1].status == 400