From 594ebb3ada96ba010db499de9906818484d5dbf3 Mon Sep 17 00:00:00 2001 From: Adrian Galvan Date: Wed, 4 Dec 2024 14:42:36 -0800 Subject: [PATCH] Restoring Snowflake tests --- .../test_snowflake_privacy_requests.py | 125 +++++++++++++++++- 1 file changed, 119 insertions(+), 6 deletions(-) diff --git a/tests/ops/service/privacy_request/test_snowflake_privacy_requests.py b/tests/ops/service/privacy_request/test_snowflake_privacy_requests.py index 78826f1738..530eb3d5c8 100644 --- a/tests/ops/service/privacy_request/test_snowflake_privacy_requests.py +++ b/tests/ops/service/privacy_request/test_snowflake_privacy_requests.py @@ -1,4 +1,3 @@ -from typing import Dict from uuid import uuid4 import pytest @@ -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( @@ -56,7 +92,6 @@ def snowflake_resources( def test_create_and_process_access_request_snowflake( snowflake_resources, db, - cache, policy, dsr_version, request, @@ -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 @@ -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, @@ -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