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

More tests for Salesforce Stuff #442

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
132 changes: 132 additions & 0 deletions tests/cassettes/TestSOQLDatasets.test_dataset_bad_query_bulk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
interactions:
- request:
body: <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><operation>query</operation><object>Account</object><contentType>CSV</contentType></jobInfo>
headers:
Request-Headers:
- Elided
method: POST
uri: https://orgname.my.salesforce.com/services/async/50.0/job
response:
body:
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jobInfo\n xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">\n
<id>7500R000004aJJGQA2</id>\n <operation>query</operation>\n <object>Account</object>\n
<createdById>0050R000008NsbLQAS</createdById>\n <createdDate>2021-06-21T05:38:02.000Z</createdDate>\n
<systemModstamp>2021-06-21T05:38:02.000Z</systemModstamp>\n <state>Open</state>\n
<concurrencyMode>Parallel</concurrencyMode>\n <contentType>CSV</contentType>\n
<numberBatchesQueued>0</numberBatchesQueued>\n <numberBatchesInProgress>0</numberBatchesInProgress>\n
<numberBatchesCompleted>0</numberBatchesCompleted>\n <numberBatchesFailed>0</numberBatchesFailed>\n
<numberBatchesTotal>0</numberBatchesTotal>\n <numberRecordsProcessed>0</numberRecordsProcessed>\n
<numberRetries>0</numberRetries>\n <apiVersion>50.0</apiVersion>\n <numberRecordsFailed>0</numberRecordsFailed>\n
<totalProcessingTime>0</totalProcessingTime>\n <apiActiveProcessingTime>0</apiActiveProcessingTime>\n
<apexProcessingTime>0</apexProcessingTime>\n</jobInfo>"
headers:
Content-Type:
- application/xml
Response-Headers: SF-Elided
status:
code: 201
message: Created
- request:
body: 'SELECT Xyzzy FROM Account '
headers:
Request-Headers:
- Elided
method: POST
uri: https://orgname.my.salesforce.com/services/async/50.0/job/7500R000004aJJGQA2/batch
response:
body:
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><batchInfo\n xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">\n
<id>7510R000004aCMsQAM</id>\n <jobId>7500R000004aJJGQA2</jobId>\n <state>Queued</state>\n
<createdDate>2021-06-21T05:38:02.000Z</createdDate>\n <systemModstamp>2021-06-21T05:38:02.000Z</systemModstamp>\n
<numberRecordsProcessed>0</numberRecordsProcessed>\n <numberRecordsFailed>0</numberRecordsFailed>\n
<totalProcessingTime>0</totalProcessingTime>\n <apiActiveProcessingTime>0</apiActiveProcessingTime>\n
<apexProcessingTime>0</apexProcessingTime>\n</batchInfo>"
headers:
Content-Type:
- application/xml
Response-Headers: SF-Elided
status:
code: 201
message: Created
- request:
body: null
headers:
Request-Headers:
- Elided
method: GET
uri: https://orgname.my.salesforce.com/services/async/50.0/job/7500R000004aJJGQA2
response:
body:
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jobInfo\n xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">\n
<id>7500R000004aJJGQA2</id>\n <operation>query</operation>\n <object>Account</object>\n
<createdById>0050R000008NsbLQAS</createdById>\n <createdDate>2021-06-21T05:38:02.000Z</createdDate>\n
<systemModstamp>2021-06-21T05:38:02.000Z</systemModstamp>\n <state>Open</state>\n
<concurrencyMode>Parallel</concurrencyMode>\n <contentType>CSV</contentType>\n
<numberBatchesQueued>0</numberBatchesQueued>\n <numberBatchesInProgress>0</numberBatchesInProgress>\n
<numberBatchesCompleted>0</numberBatchesCompleted>\n <numberBatchesFailed>1</numberBatchesFailed>\n
<numberBatchesTotal>1</numberBatchesTotal>\n <numberRecordsProcessed>0</numberRecordsProcessed>\n
<numberRetries>0</numberRetries>\n <apiVersion>50.0</apiVersion>\n <numberRecordsFailed>0</numberRecordsFailed>\n
<totalProcessingTime>0</totalProcessingTime>\n <apiActiveProcessingTime>0</apiActiveProcessingTime>\n
<apexProcessingTime>0</apexProcessingTime>\n</jobInfo>"
headers:
Content-Type:
- application/xml
Response-Headers: SF-Elided
status:
code: 200
message: OK
- request:
body: null
headers:
Request-Headers:
- Elided
method: GET
uri: https://orgname.my.salesforce.com/services/async/50.0/job/7500R000004aJJGQA2/batch
response:
body:
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><batchInfoList\n xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">\n
<batchInfo>\n <id>7510R000004aCMsQAM</id>\n <jobId>7500R000004aJJGQA2</jobId>\n
\ <state>Failed</state>\n <stateMessage>InvalidBatch : Failed to process
query: INVALID_FIELD: SELECT Xyzzy FROM Account ^ ERROR at Row:1:Column:8
No such column 'Xyzzy' on entity 'Account'. If you are attempting to use a
custom field, be sure to append the '__c' after the custom field name. Please
reference your WSDL or the describe call for the appropriate names.</stateMessage>\n
\ <createdDate>2021-06-21T05:38:02.000Z</createdDate>\n <systemModstamp>2021-06-21T05:38:03.000Z</systemModstamp>\n
\ <numberRecordsProcessed>0</numberRecordsProcessed>\n <numberRecordsFailed>0</numberRecordsFailed>\n
\ <totalProcessingTime>0</totalProcessingTime>\n <apiActiveProcessingTime>0</apiActiveProcessingTime>\n
\ <apexProcessingTime>0</apexProcessingTime>\n </batchInfo>\n</batchInfoList>"
headers:
Content-Type:
- application/xml
Response-Headers: SF-Elided
status:
code: 200
message: OK
- request:
body: <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><state>Closed</state></jobInfo>
headers:
Request-Headers:
- Elided
method: POST
uri: https://orgname.my.salesforce.com/services/async/50.0/job/7500R000004aJJGQA2
response:
body:
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jobInfo\n xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">\n
<id>7500R000004aJJGQA2</id>\n <operation>query</operation>\n <object>Account</object>\n
<createdById>0050R000008NsbLQAS</createdById>\n <createdDate>2021-06-21T05:38:02.000Z</createdDate>\n
<systemModstamp>2021-06-21T05:38:02.000Z</systemModstamp>\n <state>Closed</state>\n
<concurrencyMode>Parallel</concurrencyMode>\n <contentType>CSV</contentType>\n
<numberBatchesQueued>0</numberBatchesQueued>\n <numberBatchesInProgress>0</numberBatchesInProgress>\n
<numberBatchesCompleted>0</numberBatchesCompleted>\n <numberBatchesFailed>1</numberBatchesFailed>\n
<numberBatchesTotal>1</numberBatchesTotal>\n <numberRecordsProcessed>0</numberRecordsProcessed>\n
<numberRetries>0</numberRetries>\n <apiVersion>50.0</apiVersion>\n <numberRecordsFailed>0</numberRecordsFailed>\n
<totalProcessingTime>0</totalProcessingTime>\n <apiActiveProcessingTime>0</apiActiveProcessingTime>\n
<apexProcessingTime>0</apexProcessingTime>\n</jobInfo>"
headers:
Content-Type:
- application/xml
Response-Headers: SF-Elided
status:
code: 200
message: OK
version: 1
1 change: 0 additions & 1 deletion tests/conftest_extras_w_cci.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def no_services(*args, **kwargs):
# TODO: Port this back to CCI
def sf_before_record_response(response):
# salesforce_bulk needs the Content-Type header.
print(response["headers"])
content_type = response["headers"].get("Content-Type")
response["headers"] = {
"Response-Headers": "SF-Elided",
Expand Down
17 changes: 15 additions & 2 deletions tests/test_salesforce_gen.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from base64 import b64decode
from io import StringIO

import pytest

from snowfakery import generate_data
from snowfakery.standard_plugins.Salesforce import SalesforceConnection
from snowfakery import data_gen_exceptions as exc
from tests.test_with_cci import skip_if_cumulusci_missing

import pytest


class TestSalesforceGen:
def test_content_version(self, generated_rows):
Expand All @@ -17,6 +19,17 @@ def test_content_version(self, generated_rows):
assert b"Helvetica" in rawdata


class TestSalesforceConnection:
def test_bad_kwargs(self):
sfc = SalesforceConnection(None)
with pytest.raises(
exc.DataGenError, match=r"Unknown argument in context_name: \('xyzzy',\)"
):
sfc.compose_query(
"context_name", fields=["blah"], xyzzy="foo", **{"from": "blah"}
)


class TestSalesforcePlugin:
@skip_if_cumulusci_missing
@pytest.mark.vcr()
Expand Down
23 changes: 21 additions & 2 deletions tests/test_with_cci.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ def test_find_records_returns_multiple(self, org_config, sf, generated_rows):
assert generated_rows.mock_calls[0][1][1]["AccountId"] == first_user_id


# TODO: add tests for SOQLDatasets
# ensure that all documented params/methods are covered.
@skip_if_cumulusci_missing
class TestSOQLDatasets:
@pytest.mark.vcr()
Expand Down Expand Up @@ -401,6 +399,27 @@ def test_dataset_bad_query(self, org_config, sf, generated_rows):
with pytest.raises(DataGenError, match="Xyzzy"):
generate_data(StringIO(yaml), plugin_options={"org_name": org_config.name})

@pytest.mark.vcr()
@patch(
"simple_salesforce.Salesforce.restful",
return_value={
"sObjects": [{"name": "Account", "count": 3000}]
}, # forces bulk mode
)
def test_dataset_bad_query_bulk(self, restful, org_config):
yaml = """
- plugin: snowfakery.standard_plugins.Salesforce.SOQLDataset
- object: Contact
count: 10
fields:
__users_from_salesforce:
SOQLDataset.shuffle:
fields: Xyzzy
from: Account
"""
with pytest.raises(DataGenError, match="No such column 'Xyzzy' on entity"):
generate_data(StringIO(yaml), plugin_options={"org_name": org_config.name})

def test_dataset_no_fields(self, org_config, sf, generated_rows):
yaml = """
- plugin: snowfakery.standard_plugins.Salesforce.SOQLDataset
Expand Down