-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated integration testing infrastructure.
In other words: end-to-end, Org-based integration testing will happen now if you pass a --org flag to pytest. Otherwise, requests and responses will be mocked.
- Loading branch information
Paul Prescod
committed
Jun 16, 2020
1 parent
4caba20
commit eec8904
Showing
9 changed files
with
2,922 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2,744 changes: 2,744 additions & 0 deletions
2,744
cumulusci/tests/cassettes/TestIntegrationInfrastructure.test_integration_tests.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from pytest import fixture | ||
|
||
from cumulusci.cli.runtime import CliRuntime | ||
from cumulusci.salesforce_api.utils import get_simple_salesforce_connection | ||
from cumulusci.core.config import TaskConfig | ||
|
||
|
||
def pytest_addoption(parser, pluginmanager): | ||
parser.addoption("--org", action="store", default=None, help="org to use") | ||
|
||
|
||
def sf_pytest_orgname(request): | ||
return request.config.getoption("--org") or "qa" | ||
|
||
|
||
@fixture(scope="session") | ||
def runtime(): | ||
"""Get the CumulusCI runtime for the current working directory.""" | ||
import os | ||
|
||
print("YYY test_error_handling", os.getcwd()) | ||
|
||
return CliRuntime() | ||
|
||
|
||
@fixture(scope="session") | ||
def project_config(runtime): | ||
"""Get the project config for the current working directory.""" | ||
return runtime.project_config | ||
|
||
|
||
@fixture(scope="session") | ||
def org_config(request, runtime): | ||
"""Get an org config with an active access token. | ||
Specify the org name using the --org option when running pytest. | ||
Or else it will use your default CCI org. | ||
""" | ||
org_name = sf_pytest_orgname(request) | ||
assert org_name | ||
org_name, org_config = runtime.get_org(org_name) | ||
org_config.refresh_oauth_token(runtime.keychain) | ||
return org_config | ||
|
||
|
||
@fixture | ||
def sf(request, project_config, org_config): | ||
"""Get a simple-salesforce client for org_config.""" | ||
sf = get_simple_salesforce_connection(project_config, org_config) | ||
return sf | ||
|
||
|
||
@fixture | ||
def create_task(request, project_config, org_config): | ||
"""Get a task _factory_ which can be used to construct task instances. | ||
""" | ||
session_project_config = project_config | ||
session_org_config = org_config | ||
|
||
def create_task(task_class, options=None, project_config=None, org_config=None): | ||
project_config = project_config or session_project_config | ||
org_config = org_config or session_org_config | ||
options = options or {} | ||
|
||
task_config = TaskConfig({"options": options}) | ||
|
||
return task_class(project_config, task_config, org_config) | ||
|
||
return create_task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
|
||
from .pytest_sf_orgconnect import sf_pytest_orgname | ||
|
||
|
||
def sf_before_record_cb(request): | ||
if request.body and "<sessionId>" in request.body.decode(): | ||
request.body = re.sub( | ||
"<sessionId>.*</sessionId>", | ||
"<sessionId>**Elided**</sessionId>", | ||
request.body.decode(), | ||
).encode() | ||
request.uri = re.sub( | ||
"//.*.my.salesforce.com", "//orgname.salesforce.com", request.uri | ||
) | ||
request.uri = re.sub( | ||
"//cs.*.salesforce.com", "//podname.salesforce.com", request.uri | ||
) | ||
request.uri = re.sub( | ||
"Organization/00D3B000000F7hh", "Organization/ORGID", request.uri | ||
) | ||
|
||
request.headers = {"Request-Headers": "Elided"} | ||
|
||
return request | ||
|
||
|
||
# junk_headers = ["Public-Key-Pins-Report-Only", ] | ||
def sf_before_record_response(response): | ||
# for header in junk_headers: | ||
# if response["headers"].get(header): | ||
# del response["headers"][header] | ||
response["headers"] = {"Response-Headers": "Elided"} | ||
return response | ||
|
||
|
||
def vcr_config(request): | ||
"Fixture for configuring VCR" | ||
|
||
orgname = sf_pytest_orgname(request) | ||
|
||
if orgname: | ||
record_mode = "all" | ||
else: | ||
record_mode = "none" | ||
|
||
return { | ||
"record_mode": record_mode, | ||
"decode_compressed_response": True, | ||
"before_record_response": sf_before_record_response, | ||
"before_record_request": sf_before_record_cb, | ||
"filter_headers": [ | ||
"Authorization", | ||
"Cookie", | ||
"Public-Key-Pins-Report-Only", | ||
"Last-Modified", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from cumulusci.tasks.salesforce.GetInstalledPackages import GetInstalledPackages | ||
from pathlib import Path | ||
|
||
|
||
class TestIntegrationInfrastructure: | ||
"Test our two plugins for doing integration testing" | ||
|
||
@pytest.mark.vcr() | ||
def test_integration_tests(self, create_task): | ||
task = create_task(GetInstalledPackages, {}) | ||
assert task() is not None | ||
|
||
def test_file_was_created(self): | ||
filename = ( | ||
Path(__file__).parent | ||
/ "cassettes/TestIntegrationInfrastructure.test_integration_tests.yaml" | ||
) | ||
|
||
assert filename.exists(), filename | ||
with filename.open() as f: | ||
data = f.read() | ||
assert "Bearer 0" not in data | ||
assert "Public-Key-Pins-Report-Only" not in data | ||
assert "<sessionId>00" not in data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[pytest] | ||
testpaths = cumulusci | ||
addopts = --typeguard-packages=cumulusci | ||
addopts = --typeguard-packages=cumulusci -p cumulusci.tests.pytest_plugins.pytest_sf_vcr -p cumulusci.tests.pytest_plugins.pytest_sf_orgconnect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters