Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Aug 16, 2024
1 parent aa1ad40 commit 146df41
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 10 deletions.
24 changes: 16 additions & 8 deletions clients/admin-ui/cypress/fixtures/privacy-requests/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_6411a2ea-72d2-4111-aad3-9170ba5e5934",
Expand Down Expand Up @@ -96,7 +97,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_34650722-960c-4abd-b6a6-6dba4461dfbe",
Expand Down Expand Up @@ -142,7 +144,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_8750c782-3fad-4ae6-bbcf-219f70f537ee",
Expand Down Expand Up @@ -188,7 +191,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_8f719d4a-848d-42b9-8aaa-e7ac442ebba0",
Expand Down Expand Up @@ -234,7 +238,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_a0fe994d-f1ee-40d9-bbcb-dedb76a08efe",
Expand Down Expand Up @@ -280,7 +285,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_741784e9-1d75-4a6c-bdf7-66c9c814f1c1",
Expand Down Expand Up @@ -326,7 +332,8 @@
},
"action_required_details": null,
"resume_endpoint": null,
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
},
{
"id": "pri_4f87b8b0-f97e-45e7-8561-300a6a932d04",
Expand Down Expand Up @@ -376,7 +383,8 @@
"action_needed": null
},
"resume_endpoint": "/privacy-request/pri_4f87b8b0-f97e-45e7-8561-300a6a932d04/retry",
"days_left": 45
"days_left": 45,
"source": "Privacy Center"
}
],
"total": 8,
Expand Down
1 change: 1 addition & 0 deletions src/fides/api/schemas/privacy_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Config:
orm_mode = True
use_enum_values = True


class Consent(FidesSchema):
"""
Deprecated: This used to be populated and sent to the server by a `config.json` in the UI
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/application_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
MessagingServiceType,
MessagingTemplateWithPropertiesDetail,
)
from fides.api.schemas.privacy_request import PrivacyRequestSource
from fides.api.schemas.property import Property as PropertySchema
from fides.api.schemas.property import PropertyType
from fides.api.schemas.redis_cache import (
Expand Down Expand Up @@ -2745,6 +2746,7 @@ def provided_identity_and_consent_request(

consent_request_data = {
"provided_identity_id": provided_identity.id,
"source": PrivacyRequestSource.privacy_center,
}
consent_request = ConsentRequest.create(db, data=consent_request_data)

Expand Down
27 changes: 27 additions & 0 deletions tests/ops/api/v1/endpoints/test_consent_request_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ProvidedIdentity,
)
from fides.api.schemas.messaging.messaging import MessagingServiceType
from fides.api.schemas.privacy_request import PrivacyRequestSource
from fides.common.api.scope_registry import CONNECTION_READ, CONSENT_READ
from fides.common.api.v1.urn_registry import (
CONSENT_REQUEST,
Expand Down Expand Up @@ -367,6 +368,32 @@ def test_consent_request_email_and_phone_default_to_email(
).first()
assert provided_identity is not None

@pytest.mark.usefixtures(
"messaging_config",
"subject_identity_verification_required",
)
@patch("fides.api.service._verification.dispatch_message")
def test_consent_request_with_source(
self,
mock_dispatch_message,
db,
api_client,
url,
):
data = {
"identity": {"email": "[email protected]"},
"source": PrivacyRequestSource.privacy_center,
}
response = api_client.post(url, json=data)
assert response.status_code == 200
assert mock_dispatch_message.called

consent_request_id = response.json()["consent_request_id"]
consent_request = ConsentRequest.get_by_key_or_id(
db=db, data={"id": consent_request_id}
)
assert consent_request.source == PrivacyRequestSource.privacy_center

@pytest.mark.usefixtures(
"messaging_config",
"sovrn_email_connection_config",
Expand Down
52 changes: 51 additions & 1 deletion tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
generate_request_task_callback_jwe,
)
from fides.api.oauth.jwt import generate_jwe
from fides.api.oauth.roles import APPROVER, VIEWER
from fides.api.oauth.roles import APPROVER, OWNER, VIEWER
from fides.api.schemas.dataset import DryRunDatasetResponse
from fides.api.schemas.masking.masking_secrets import SecretType
from fides.api.schemas.messaging.messaging import (
Expand All @@ -53,6 +53,7 @@
SubjectIdentityVerificationBodyParams,
)
from fides.api.schemas.policy import ActionType, PolicyResponse
from fides.api.schemas.privacy_request import PrivacyRequestSource
from fides.api.schemas.redis_cache import Identity, LabeledIdentity
from fides.api.task.graph_runners import access_runner
from fides.api.tasks import MESSAGING_QUEUE_NAME
Expand Down Expand Up @@ -95,6 +96,7 @@
V1_URL_PREFIX,
)
from fides.config import CONFIG
from tests.conftest import generate_auth_header_for_user, generate_role_header_for_user

page_size = Params().size

Expand Down Expand Up @@ -6114,6 +6116,54 @@ def test_create_privacy_request(
assert len(response_data) == 1
assert run_access_request_mock.called

@pytest.mark.parametrize(
"source, expected_submitted_by",
[
(PrivacyRequestSource.request_manager, lambda user: user.client.user_id),
(PrivacyRequestSource.privacy_center, lambda _: None),
(None, lambda _: None),
],
)
@mock.patch(
"fides.api.service.privacy_request.request_runner_service.run_privacy_request.delay"
)
def test_request_manager_privacy_request_stores_submitted_by(
self,
run_access_request_mock,
db,
url,
api_client,
owner_user,
policy,
source,
expected_submitted_by,
):
auth_header = generate_role_header_for_user(
owner_user, roles=owner_user.permissions.roles
)
data = [
{
"policy_key": policy.key,
"identity": {"email": "[email protected]"},
"source": source,
}
]
resp = api_client.post(
url,
headers=auth_header,
json=data,
)
assert resp.status_code == 200

response_data = resp.json()["succeeded"]
assert len(response_data) == 1

pr = PrivacyRequest.get(db=db, object_id=response_data[0]["id"])
assert pr.submitted_by == expected_submitted_by(owner_user)

pr.delete(db=db)
assert run_access_request_mock.called

@pytest.mark.usefixtures("verification_config")
@mock.patch(
"fides.api.service.privacy_request.request_runner_service.run_privacy_request.delay"
Expand Down
15 changes: 14 additions & 1 deletion tests/ops/schemas/test_privacy_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from pydantic import ValidationError

from fides.api.models.privacy_request import PrivacyRequestStatus
from fides.api.schemas.privacy_request import PrivacyRequestFilter
from fides.api.schemas.privacy_request import (
PrivacyRequestCreate,
PrivacyRequestFilter,
PrivacyRequestSource,
)


class TestPrivacyRequestFilter:
Expand All @@ -26,3 +30,12 @@ def test_none_status(self):
def test_invalid_status(self):
with pytest.raises(ValidationError):
PrivacyRequestFilter(status="invalid_status")


class TestPrivacyRequestCreate:
def test_valid_source(self):
PrivacyRequestCreate(source=PrivacyRequestSource.privacy_center)

def test_invalid_source(self):
with pytest.raises(ValidationError):
PrivacyRequestCreate(source="Email")

0 comments on commit 146df41

Please sign in to comment.