Skip to content

Commit

Permalink
Restoring Snowflake tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Dec 4, 2024
1 parent de8a8e4 commit 594ebb3
Showing 1 changed file with 119 additions and 6 deletions.
125 changes: 119 additions & 6 deletions tests/ops/service/privacy_request/test_snowflake_privacy_requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Dict
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -47,6 +46,43 @@ def snowflake_resources(
assert res[0][0] == 1


@pytest.fixture(scope="function")
def snowflake_resources_with_namespace_meta(
snowflake_example_test_dataset_config_with_namespace_meta,
):
snowflake_connection_config = (
snowflake_example_test_dataset_config_with_namespace_meta.connection_config
)
snowflake_client = SnowflakeConnector(snowflake_connection_config).client()
uuid = str(uuid4())
customer_email = f"customer-{uuid}@example.com"
formatted_customer_email = f"'{customer_email}'"
customer_name = f"{uuid}"
formatted_customer_name = f"'{customer_name}'"

stmt = 'select max("id") from "FIDESOPS_TEST"."TEST"."customer";'
res = snowflake_client.execute(stmt).all()
customer_id = res[0][0] + 1

stmt = f"""
insert into "FIDESOPS_TEST"."TEST"."customer" ("id", "email", "name", "variant_eg")
select {customer_id}, {formatted_customer_email}, {formatted_customer_name}, to_variant({formatted_customer_name});
"""
res = snowflake_client.execute(stmt).all()
assert res[0][0] == 1
yield {
"email": customer_email,
"formatted_email": formatted_customer_email,
"name": customer_name,
"id": customer_id,
"client": snowflake_client,
}
# Remove test data and close Snowflake connection in teardown
stmt = f'delete from "FIDESOPS_TEST"."TEST"."customer" where "email" = {formatted_customer_email};'
res = snowflake_client.execute(stmt).all()
assert res[0][0] == 1


@pytest.mark.integration_external
@pytest.mark.integration_snowflake
@pytest.mark.parametrize(
Expand All @@ -56,7 +92,6 @@ def snowflake_resources(
def test_create_and_process_access_request_snowflake(
snowflake_resources,
db,
cache,
policy,
dsr_version,
request,
Expand All @@ -79,7 +114,7 @@ def test_create_and_process_access_request_snowflake(
task_timeout=PRIVACY_REQUEST_TASK_TIMEOUT_EXTERNAL,
)
results = pr.get_raw_access_results()
customer_table_key = f"snowflake_example_test_dataset:customer"
customer_table_key = "snowflake_example_test_dataset:customer"
assert len(results[customer_table_key]) == 1
assert results[customer_table_key][0]["email"] == customer_email
assert results[customer_table_key][0]["name"] == customer_name
Expand All @@ -94,11 +129,8 @@ def test_create_and_process_access_request_snowflake(
["use_dsr_3_0", "use_dsr_2_0"],
)
def test_create_and_process_erasure_request_snowflake(
snowflake_example_test_dataset_config,
snowflake_resources,
integration_config: Dict[str, str],
db,
cache,
dsr_version,
request,
erasure_policy,
Expand Down Expand Up @@ -128,3 +160,84 @@ def test_create_and_process_erasure_request_snowflake(
for row in res:
assert row.name is None
assert row.variant_eg is None


@pytest.mark.integration_external
@pytest.mark.integration_snowflake
@pytest.mark.parametrize(
"dsr_version",
["use_dsr_3_0", "use_dsr_2_0"],
)
def test_create_and_process_access_request_snowflake_with_namespace_meta(
snowflake_resources_with_namespace_meta,
db,
policy,
dsr_version,
request,
run_privacy_request_task,
):
request.getfixturevalue(dsr_version) # REQUIRED to test both DSR 3.0 and 2.0

customer_email = snowflake_resources_with_namespace_meta["email"]
customer_name = snowflake_resources_with_namespace_meta["name"]
data = {
"requested_at": "2021-08-30T16:09:37.359Z",
"policy_key": policy.key,
"identity": {"email": customer_email},
}
pr = get_privacy_request_results(
db,
policy,
run_privacy_request_task,
data,
task_timeout=PRIVACY_REQUEST_TASK_TIMEOUT_EXTERNAL,
)
results = pr.get_raw_access_results()
customer_table_key = "snowflake_example_test_dataset:customer"
assert len(results[customer_table_key]) == 1
assert results[customer_table_key][0]["email"] == customer_email
assert results[customer_table_key][0]["name"] == customer_name

pr.delete(db=db)


@pytest.mark.integration_external
@pytest.mark.integration_snowflake
@pytest.mark.parametrize(
"dsr_version",
["use_dsr_3_0", "use_dsr_2_0"],
)
def test_create_and_process_erasure_request_snowflake_with_namespace_meta(
snowflake_resources_with_namespace_meta,
db,
dsr_version,
request,
erasure_policy,
run_privacy_request_task,
):
request.getfixturevalue(dsr_version) # REQUIRED to test both DSR 3.0 and 2.0

customer_email = snowflake_resources_with_namespace_meta["email"]
snowflake_client = snowflake_resources_with_namespace_meta["client"]
formatted_customer_email = snowflake_resources_with_namespace_meta[
"formatted_email"
]
data = {
"requested_at": "2021-08-30T16:09:37.359Z",
"policy_key": erasure_policy.key,
"identity": {"email": customer_email},
}
pr = get_privacy_request_results(
db,
erasure_policy,
run_privacy_request_task,
data,
task_timeout=PRIVACY_REQUEST_TASK_TIMEOUT_EXTERNAL,
)
pr.delete(db=db)

stmt = f'select "name", "variant_eg" from "FIDESOPS_TEST"."TEST"."customer" where "email" = {formatted_customer_email};'
res = snowflake_client.execute(stmt).all()
for row in res:
assert row.name is None
assert row.variant_eg is None

0 comments on commit 594ebb3

Please sign in to comment.