Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Jan 7, 2025
1 parent bf03464 commit 8d552b0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
30 changes: 30 additions & 0 deletions tests/fixtures/postgres_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uuid import uuid4

import pytest
from fideslang.models import Dataset as FideslangDataset
from sqlalchemy.orm import Session
from sqlalchemy.orm.exc import ObjectDeletedError
from sqlalchemy_utils.functions import drop_database
Expand All @@ -23,6 +24,7 @@
from fides.api.models.sql_models import System
from fides.api.service.connectors import PostgreSQLConnector
from fides.config import CONFIG
from tests.ops.test_helpers.dataset_utils import remove_primary_keys
from tests.ops.test_helpers.db_utils import seed_postgres_data

from .application_fixtures import integration_secrets
Expand Down Expand Up @@ -111,6 +113,34 @@ def postgres_example_test_dataset_config_read_access(
ctl_dataset.delete(db=db)


@pytest.fixture
def postgres_example_test_dataset_config_read_access_without_primary_keys(
read_connection_config: ConnectionConfig,
db: Session,
example_datasets: List[Dict],
) -> Generator:
postgres_dataset = example_datasets[0]
fides_key = postgres_dataset["fides_key"]

dataset = FideslangDataset(**postgres_dataset)
updated_dataset = remove_primary_keys(dataset)
ctl_dataset = CtlDataset.create_from_dataset_dict(
db, updated_dataset.model_dump(mode="json")
)

dataset = DatasetConfig.create(
db=db,
data={
"connection_config_id": read_connection_config.id,
"fides_key": fides_key,
"ctl_dataset_id": ctl_dataset.id,
},
)
yield dataset
dataset.delete(db=db)
ctl_dataset.delete(db=db)


@pytest.fixture
def postgres_example_test_dataset_config_skipped_login_collection(
read_connection_config: ConnectionConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ def test_upload_access_results_has_data_use_map(
"dsr_version",
["use_dsr_3_0", "use_dsr_2_0"],
)
@pytest.mark.parametrize(
"dataset_config",
[
"postgres_example_test_dataset_config_read_access",
"postgres_example_test_dataset_config_read_access_without_primary_keys",
],
)
def test_create_and_process_access_request_postgres(
trigger_webhook_mock,
postgres_example_test_dataset_config_read_access,
dataset_config,
postgres_integration_db,
db,
cache,
Expand All @@ -174,6 +181,7 @@ def test_create_and_process_access_request_postgres(
run_privacy_request_task,
):
request.getfixturevalue(dsr_version) # REQUIRED to test both DSR 3.0 and 2.0
request.getfixturevalue(dataset_config)

customer_email = "[email protected]"
data = {
Expand All @@ -196,7 +204,7 @@ def test_create_and_process_access_request_postgres(
assert results[key] is not None
assert results[key] != {}

result_key_prefix = f"postgres_example_test_dataset:"
result_key_prefix = "postgres_example_test_dataset:"
customer_key = result_key_prefix + "customer"
assert results[customer_key][0]["email"] == customer_email

Expand Down Expand Up @@ -278,14 +286,14 @@ def test_create_and_process_access_request_with_custom_identities_postgres(
assert results[key] is not None
assert results[key] != {}

result_key_prefix = f"postgres_example_test_dataset:"
result_key_prefix = "postgres_example_test_dataset:"
customer_key = result_key_prefix + "customer"
assert results[customer_key][0]["email"] == customer_email

visit_key = result_key_prefix + "visit"
assert results[visit_key][0]["email"] == customer_email

loyalty_key = f"postgres_example_test_extended_dataset:loyalty"
loyalty_key = "postgres_example_test_extended_dataset:loyalty"
assert results[loyalty_key][0]["id"] == loyalty_id

log_id = pr.execution_logs[0].id
Expand Down Expand Up @@ -355,7 +363,7 @@ def test_create_and_process_access_request_with_valid_skipped_collection(

assert "login" not in results.keys()

result_key_prefix = f"postgres_example_test_dataset:"
result_key_prefix = "postgres_example_test_dataset:"
customer_key = result_key_prefix + "customer"
assert results[customer_key][0]["email"] == customer_email

Expand Down Expand Up @@ -712,9 +720,16 @@ def test_create_and_process_erasure_request_with_table_joins(
"dsr_version",
["use_dsr_3_0", "use_dsr_2_0"],
)
@pytest.mark.parametrize(
"dataset_config",
[
"postgres_example_test_dataset_config_read_access",
"postgres_example_test_dataset_config_read_access_without_primary_keys",
],
)
def test_create_and_process_erasure_request_read_access(
postgres_integration_db,
postgres_example_test_dataset_config_read_access,
dataset_config,
db,
cache,
erasure_policy,
Expand All @@ -723,6 +738,7 @@ def test_create_and_process_erasure_request_read_access(
run_privacy_request_task,
):
request.getfixturevalue(dsr_version) # REQUIRED to test both DSR 3.0 and 2.0
request.getfixturevalue(dataset_config)

customer_email = "[email protected]"
customer_id = 2
Expand Down

0 comments on commit 8d552b0

Please sign in to comment.