Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
[SaaS Connector] SaaS fixture cleanup (#335)
Browse files Browse the repository at this point in the history
Separating SaaS example and Mailchimp fixtures

Co-authored-by: Adrian Galvan <[email protected]>
  • Loading branch information
galvana and galvana authored Apr 1, 2022
1 parent cc6b8bd commit 0f69648
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 419 deletions.
2 changes: 1 addition & 1 deletion docs/fidesops/docs/guides/saas_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ This is where we define how we are going to access and update each collection in
- `pagination` An optional strategy used to get the next set of results from APIs with resources spanning multiple pages. Details can be found under [SaaS Pagination](saas_pagination.md).
- `grouped_inputs` An optional list of reference fields whose inputs are dependent upon one another. For example, an endpoint may need both an `organization_id` and a `project_id` from another endpoint. These aren't independent values, as a `project_id` belongs to an `organization_id`. You would specify this as ["organization_id", "project_id"].

## Request params in more detail
## Param values in more detail
The `param_values` list is what provides the values to our various placeholders in the path, headers, query params and body. Values can be `identities` such as email or phone number, `references` to fields in other collections, or `connector_params` which are defined as part of configuring a SaaS connector. Whenever a placeholder is encountered, the placeholder name is looked up in the list of `param_values` and corresponding value is used instead. Here is an example of placeholders being used in various locations:

```yaml
Expand Down
9 changes: 8 additions & 1 deletion saas_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ page_limit = "10"
domain = ""
username = ""
api_key = ""
identity_email = ""
identity_email = ""

[stripe]
host = ""
api_key = ""
payment_types = ""
page_limit = ""
identity_email = ""
30 changes: 15 additions & 15 deletions tests/api/v1/endpoints/test_connection_config_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,17 +815,17 @@ def test_put_http_connection_config_secrets(
assert https_connection_config.last_test_succeeded is None

@pytest.mark.unit_saas
def test_put_connection_config_saas_example_secrets(
def test_put_saas_example_connection_config_secrets(
self,
api_client: TestClient,
db: Session,
generate_auth_header,
connection_config_saas_example,
saas_secrets,
saas_example_connection_config,
saas_example_secrets,
):
auth_header = generate_auth_header(scopes=[CONNECTION_CREATE_OR_UPDATE])
url = f"{V1_URL_PREFIX}{CONNECTIONS}/{connection_config_saas_example.key}/secret"
payload = saas_secrets["saas_example"]
url = f"{V1_URL_PREFIX}{CONNECTIONS}/{saas_example_connection_config.key}/secret"
payload = saas_example_secrets

resp = api_client.put(
url + "?verify=False",
Expand All @@ -837,25 +837,25 @@ def test_put_connection_config_saas_example_secrets(
body = json.loads(resp.text)
assert (
body["msg"]
== f"Secrets updated for ConnectionConfig with key: {connection_config_saas_example.key}."
== f"Secrets updated for ConnectionConfig with key: {saas_example_connection_config.key}."
)

db.refresh(connection_config_saas_example)
assert connection_config_saas_example.secrets == saas_secrets["saas_example"]
assert connection_config_saas_example.last_test_timestamp is None
assert connection_config_saas_example.last_test_succeeded is None
db.refresh(saas_example_connection_config)
assert saas_example_connection_config.secrets == saas_example_secrets
assert saas_example_connection_config.last_test_timestamp is None
assert saas_example_connection_config.last_test_succeeded is None

@pytest.mark.unit_saas
def test_put_connection_config_saas_example_secrets_missing_saas_config(
def test_put_saas_example_connection_config_secrets_missing_saas_config(
self,
api_client: TestClient,
generate_auth_header,
connection_config_saas_example_without_saas_config,
saas_secrets,
saas_example_connection_config_without_saas_config,
saas_example_secrets,
):
auth_header = generate_auth_header(scopes=[CONNECTION_CREATE_OR_UPDATE])
url = f"{V1_URL_PREFIX}{CONNECTIONS}/{connection_config_saas_example_without_saas_config.key}/secret"
payload = saas_secrets["saas_example"]
url = f"{V1_URL_PREFIX}{CONNECTIONS}/{saas_example_connection_config_without_saas_config.key}/secret"
payload = saas_example_secrets

resp = api_client.put(
url + "?verify=False",
Expand Down
42 changes: 21 additions & 21 deletions tests/api/v1/endpoints/test_dataset_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,22 @@ def test_validate_dataset_that_references_another_dataset(
def test_validate_saas_dataset_invalid_traversal(
self,
db,
connection_config_saas_example_with_invalid_saas_config,
saas_datasets,
saas_example_connection_config_with_invalid_saas_config,
saas_example_dataset,
api_client: TestClient,
generate_auth_header,
):
path = V1_URL_PREFIX + DATASET_VALIDATE
path_params = {
"connection_key": connection_config_saas_example_with_invalid_saas_config.key
"connection_key": saas_example_connection_config_with_invalid_saas_config.key
}
validate_dataset_url = path.format(**path_params)

auth_header = generate_auth_header(scopes=[DATASET_READ])
response = api_client.put(
validate_dataset_url,
headers=auth_header,
json=saas_datasets["saas_example"],
json=saas_example_dataset,
)
assert response.status_code == 200

Expand Down Expand Up @@ -669,19 +669,19 @@ def test_patch_datasets_bulk_update(
@pytest.mark.unit_saas
def test_patch_datasets_missing_saas_config(
self,
connection_config_saas_example_without_saas_config,
saas_datasets,
saas_example_connection_config_without_saas_config,
saas_example_dataset,
api_client: TestClient,
db: Session,
generate_auth_header,
):
path = V1_URL_PREFIX + DATASETS
path_params = {"connection_key": connection_config_saas_example_without_saas_config.key}
path_params = {"connection_key": saas_example_connection_config_without_saas_config.key}
datasets_url = path.format(**path_params)

auth_header = generate_auth_header(scopes=[DATASET_CREATE_OR_UPDATE])
response = api_client.patch(
datasets_url, headers=auth_header, json=[saas_datasets["saas_example"]]
datasets_url, headers=auth_header, json=[saas_example_dataset]
)
assert response.status_code == 200

Expand All @@ -690,24 +690,24 @@ def test_patch_datasets_missing_saas_config(
assert len(response_body["failed"]) == 1
assert (
response_body["failed"][0]["message"]
== f"Connection config '{connection_config_saas_example_without_saas_config.key}' "
== f"Connection config '{saas_example_connection_config_without_saas_config.key}' "
"must have a SaaS config before validating or adding a dataset"
)

@pytest.mark.unit_saas
def test_patch_datasets_extra_reference(
self,
connection_config_saas_example,
saas_datasets,
saas_example_connection_config,
saas_example_dataset,
api_client: TestClient,
db: Session,
generate_auth_header,
):
path = V1_URL_PREFIX + DATASETS
path_params = {"connection_key": connection_config_saas_example.key}
path_params = {"connection_key": saas_example_connection_config.key}
datasets_url = path.format(**path_params)

invalid_dataset = saas_datasets["saas_example"]
invalid_dataset = saas_example_dataset
invalid_dataset["collections"][0]["fields"][0]["fidesops_meta"] = {
"references": [
{
Expand Down Expand Up @@ -736,17 +736,17 @@ def test_patch_datasets_extra_reference(
@pytest.mark.unit_saas
def test_patch_datasets_extra_identity(
self,
connection_config_saas_example,
saas_datasets,
saas_example_connection_config,
saas_example_dataset,
api_client: TestClient,
db: Session,
generate_auth_header,
):
path = V1_URL_PREFIX + DATASETS
path_params = {"connection_key": connection_config_saas_example.key}
path_params = {"connection_key": saas_example_connection_config.key}
datasets_url = path.format(**path_params)

invalid_dataset = saas_datasets["saas_example"]
invalid_dataset = saas_example_dataset
invalid_dataset["collections"][0]["fields"][0]["fidesops_meta"] = {
"identity": "email"
}
Expand All @@ -769,17 +769,17 @@ def test_patch_datasets_extra_identity(
@pytest.mark.unit_saas
def test_patch_datasets_fides_key_mismatch(
self,
connection_config_saas_example,
saas_datasets,
saas_example_connection_config,
saas_example_dataset,
api_client: TestClient,
db: Session,
generate_auth_header,
):
path = V1_URL_PREFIX + DATASETS
path_params = {"connection_key": connection_config_saas_example.key}
path_params = {"connection_key": saas_example_connection_config.key}
datasets_url = path.format(**path_params)

invalid_dataset = saas_datasets["saas_example"]
invalid_dataset = saas_example_dataset
invalid_dataset["fides_key"] = "different_key"

auth_header = generate_auth_header(scopes=[DATASET_CREATE_OR_UPDATE])
Expand Down
Loading

0 comments on commit 0f69648

Please sign in to comment.