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

[SaaS Connector] SaaS fixture cleanup #335

Merged
merged 29 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e7e85f
Adding connector_param references to generate_query and generate_upda…
galvana Mar 17, 2022
16402c6
Merge branch 'main' into 276-saas-connector-add-the-ability-for-reque…
galvana Mar 17, 2022
29167d8
Cleaning up after merging in main
galvana Mar 17, 2022
3ecdca3
Updating variable name from connector_params to secrets to better ref…
galvana Mar 22, 2022
e4011a6
Merge branch 'main' into 276-saas-connector-add-the-ability-for-reque…
galvana Mar 23, 2022
b7528e6
Updating tests
galvana Mar 23, 2022
23bed42
Fixing tests
galvana Mar 23, 2022
c7394f6
Adding support for HTTP headers
galvana Mar 24, 2022
f6190b3
Updating documentation
galvana Mar 24, 2022
6eb4077
Updating Postman collection
galvana Mar 24, 2022
810f94a
Minor documentation change
galvana Mar 24, 2022
be62902
Cleaning up usages of SaaSRequestParams
galvana Mar 24, 2022
9301a6f
Fixing JSON in documentation
galvana Mar 24, 2022
459860e
Adding more info about request_params in the documentation
galvana Mar 24, 2022
ebdfa29
Fixing pagination tests
galvana Mar 25, 2022
c8395a8
Merge branch 'main' into 289-saas-connector-headers
galvana Mar 25, 2022
87cd120
Fixing tests and cleaning up based on PR review feedback
galvana Mar 26, 2022
75c8075
Changing name of request_param to param_values
galvana Mar 26, 2022
84fad31
Removing unused import
galvana Mar 26, 2022
a65d5f8
Fixing tests
galvana Mar 26, 2022
4acc7f8
Updating branch
galvana Mar 27, 2022
62a6807
Removing in-progress Stripe files
galvana Mar 27, 2022
1a6bd91
Merging in headers and param_values fixes
galvana Mar 27, 2022
2cf40b0
Fixing test
galvana Mar 27, 2022
793877a
Merging in main branch
galvana Apr 1, 2022
9159c2d
Minor formatting fix
galvana Apr 1, 2022
3bad5db
Fixing test
galvana Apr 1, 2022
1cf4bcf
Fixing integration test
galvana Apr 1, 2022
a06a42c
Removing unnecessary param
galvana Apr 1, 2022
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
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