diff --git a/tests/cassettes/TestSOQLDatasets.test_dataset_bad_query_bulk.yaml b/tests/cassettes/TestSOQLDatasets.test_dataset_bad_query_bulk.yaml new file mode 100644 index 00000000..9d6bd867 --- /dev/null +++ b/tests/cassettes/TestSOQLDatasets.test_dataset_bad_query_bulk.yaml @@ -0,0 +1,132 @@ +interactions: +- request: + body: queryAccountCSV + headers: + Request-Headers: + - Elided + method: POST + uri: https://orgname.my.salesforce.com/services/async/50.0/job + response: + body: + string: "\n + 7500R000004aJJGQA2\n query\n Account\n + 0050R000008NsbLQAS\n 2021-06-21T05:38:02.000Z\n + 2021-06-21T05:38:02.000Z\n Open\n + Parallel\n CSV\n + 0\n 0\n + 0\n 0\n + 0\n 0\n + 0\n 50.0\n 0\n + 0\n 0\n + 0\n" + 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: "\n + 7510R000004aCMsQAM\n 7500R000004aJJGQA2\n Queued\n + 2021-06-21T05:38:02.000Z\n 2021-06-21T05:38:02.000Z\n + 0\n 0\n + 0\n 0\n + 0\n" + 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: "\n + 7500R000004aJJGQA2\n query\n Account\n + 0050R000008NsbLQAS\n 2021-06-21T05:38:02.000Z\n + 2021-06-21T05:38:02.000Z\n Open\n + Parallel\n CSV\n + 0\n 0\n + 0\n 1\n + 1\n 0\n + 0\n 50.0\n 0\n + 0\n 0\n + 0\n" + 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: "\n + \n 7510R000004aCMsQAM\n 7500R000004aJJGQA2\n + \ Failed\n 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.\n + \ 2021-06-21T05:38:02.000Z\n 2021-06-21T05:38:03.000Z\n + \ 0\n 0\n + \ 0\n 0\n + \ 0\n \n" + headers: + Content-Type: + - application/xml + Response-Headers: SF-Elided + status: + code: 200 + message: OK +- request: + body: Closed + headers: + Request-Headers: + - Elided + method: POST + uri: https://orgname.my.salesforce.com/services/async/50.0/job/7500R000004aJJGQA2 + response: + body: + string: "\n + 7500R000004aJJGQA2\n query\n Account\n + 0050R000008NsbLQAS\n 2021-06-21T05:38:02.000Z\n + 2021-06-21T05:38:02.000Z\n Closed\n + Parallel\n CSV\n + 0\n 0\n + 0\n 1\n + 1\n 0\n + 0\n 50.0\n 0\n + 0\n 0\n + 0\n" + headers: + Content-Type: + - application/xml + Response-Headers: SF-Elided + status: + code: 200 + message: OK +version: 1 diff --git a/tests/conftest_extras_w_cci.py b/tests/conftest_extras_w_cci.py index 72d051f0..637b5144 100644 --- a/tests/conftest_extras_w_cci.py +++ b/tests/conftest_extras_w_cci.py @@ -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", diff --git a/tests/test_salesforce_gen.py b/tests/test_salesforce_gen.py index d6b1b583..3ad2efff 100644 --- a/tests/test_salesforce_gen.py +++ b/tests/test_salesforce_gen.py @@ -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): @@ -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() diff --git a/tests/test_with_cci.py b/tests/test_with_cci.py index 1f44292c..58b77a5f 100644 --- a/tests/test_with_cci.py +++ b/tests/test_with_cci.py @@ -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() @@ -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