Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating assertions and adding a wait before asserting erasures #5692

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions tests/fixtures/bigquery_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,14 @@ def bigquery_enterprise_resources(
"""
connection.execute(stmt)

# Create test stackoverflow_posts_partitioned data. Posts are responses to questions on Stackoverflow, and does not include original question.
# Create test stackoverflow_posts data. Posts are responses to questions on Stackoverflow, and does not include original question.
post_body = "For me, the solution was to adopt 3 cats and dance with them under the full moon at midnight."
stmt = "select max(id) from enterprise_dsr_testing.stackoverflow_posts_partitioned;"
stmt = "select max(id) from enterprise_dsr_testing.stackoverflow_posts;"
res = connection.execute(stmt)
random_increment = random.randint(0, 99999)
post_id = res.all()[0][0] + random_increment
stmt = f"""
insert into enterprise_dsr_testing.stackoverflow_posts_partitioned (body, creation_date, id, owner_user_id, owner_display_name)
insert into enterprise_dsr_testing.stackoverflow_posts (body, creation_date, id, owner_user_id, owner_display_name)
values ('{post_body}', '{creation_date}', {post_id}, {user_id}, '{display_name}');
"""
connection.execute(stmt)
Expand Down Expand Up @@ -589,7 +589,7 @@ def bigquery_enterprise_resources(
stmt = f"delete from enterprise_dsr_testing.comments where id = {comment_id};"
connection.execute(stmt)

stmt = f"delete from enterprise_dsr_testing.stackoverflow_posts_partitioned where id = {post_id};"
stmt = f"delete from enterprise_dsr_testing.stackoverflow_posts where id = {post_id};"
connection.execute(stmt)

stmt = f"delete from enterprise_dsr_testing.users where id = {user_id};"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from time import sleep
from unittest import mock

import pytest
from loguru import logger

from fides.api.models.audit_log import AuditLog, AuditLogAction
from fides.api.models.privacy_request import ExecutionLog
from tests.ops.service.privacy_request.test_request_runner_service import (
get_privacy_request_results,
)
from tests.ops.test_helpers.saas_test_utils import poll_for_existence

PRIVACY_REQUEST_TASK_TIMEOUT = 5
# External services take much longer to return
PRIVACY_REQUEST_TASK_TIMEOUT_EXTERNAL = 150


@pytest.mark.skip
@pytest.mark.integration_bigquery
@pytest.mark.integration_external
@pytest.mark.parametrize(
Expand Down Expand Up @@ -68,7 +72,7 @@ def test_access_request(
)

results = pr.get_raw_access_results()
assert len(results.keys()) == 4
assert len(results.keys()) == 5

for key in results.keys():
assert results[key] is not None
Expand Down Expand Up @@ -185,7 +189,7 @@ def test_erasure_request(
)

results = pr.get_raw_access_results()
assert len(results.keys()) == 4
assert len(results.keys()) == 5

for key in results.keys():
assert results[key] is not None
Expand Down Expand Up @@ -249,34 +253,49 @@ def test_erasure_request(
post_history_id = bigquery_enterprise_resources["post_history_id"]
comment_id = bigquery_enterprise_resources["comment_id"]
post_id = bigquery_enterprise_resources["post_id"]
with bigquery_client.connect() as connection:
stmt = f"select text from enterprise_dsr_testing.post_history where id = {post_history_id};"
res = connection.execute(stmt).all()
for row in res:
assert row.text is None

stmt = f"select user_display_name, text from enterprise_dsr_testing.comments where id = {comment_id};"
res = connection.execute(stmt).all()
for row in res:
assert row.user_display_name is None
assert row.text is None

stmt = f"select owner_user_id, owner_display_name, body from enterprise_dsr_testing.stackoverflow_posts_partitioned where id = {post_id};"
res = connection.execute(stmt).all()
for row in res:
assert (
row.owner_user_id == bigquery_enterprise_resources["user_id"]
) # not targeted by policy
assert row.owner_display_name is None
assert row.body is None

stmt = f"select display_name, location from enterprise_dsr_testing.users where id = {user_id};"
res = connection.execute(stmt).all()
for row in res:
assert row.display_name is None
assert row.location is None
def bigquery_data_present(
bigquery_client, post_history_id, comment_id, post_id
) -> bool:
with bigquery_client.connect() as connection:
stmt = f"select text from enterprise_dsr_testing.post_history where id = {post_history_id};"
res = connection.execute(stmt).all()
for row in res:
if row.text is not None:
logger.info(f"row.text {row.text}")
return True

stmt = f"select user_display_name, text from enterprise_dsr_testing.comments where id = {comment_id};"
res = connection.execute(stmt).all()
for row in res:
if row.user_display_name is not None or row.text is not None:
return True

stmt = f"select owner_user_id, owner_display_name, body from enterprise_dsr_testing.stackoverflow_posts_partitioned where id = {post_id};"
res = connection.execute(stmt).all()
for row in res:
assert (
row.owner_user_id == bigquery_enterprise_resources["user_id"]
) # not targeted by policy
if row.owner_display_name is not None or row.body is not None:
return True

stmt = f"select display_name, location from enterprise_dsr_testing.users where id = {user_id};"
res = connection.execute(stmt).all()
for row in res:
if row.display_name is not None or row.location is not None:
return True

return False

poll_for_existence(
bigquery_data_present,
(bigquery_client, post_history_id, comment_id, post_id),
existence_desired=False,
)


@pytest.mark.skip
@pytest.mark.integration_bigquery
@pytest.mark.integration_external
@pytest.mark.parametrize(
Expand Down Expand Up @@ -322,7 +341,7 @@ def test_access_request_multiple_custom_identities(
)

results = pr.get_raw_access_results()
assert len(results.keys()) == 4
assert len(results.keys()) == 5

for key in results.keys():
assert results[key] is not None
Expand Down Expand Up @@ -388,6 +407,7 @@ def test_access_request_multiple_custom_identities(
assert ExecutionLog.get(db, object_id=log_id).privacy_request_id == pr_id


@pytest.mark.skip
@pytest.mark.integration_external
@pytest.mark.integration_bigquery
@pytest.mark.parametrize(
Expand Down Expand Up @@ -438,7 +458,7 @@ def test_erasure_request_multiple_custom_identities(
)

results = pr.get_raw_access_results()
assert len(results.keys()) == 4
assert len(results.keys()) == 5

for key in results.keys():
assert results[key] is not None
Expand Down
Loading