Skip to content

Commit

Permalink
Misc cleanup and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed May 20, 2024
1 parent 9a23e97 commit 2c9433e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()

Expand Down Expand Up @@ -56,6 +57,7 @@ def upgrade():
"ON servednoticehistory (property_id)'"
)


def downgrade():
op.drop_index(
op.f("ix_servednoticehistory_property_id"), table_name="servednoticehistory"
Expand Down
18 changes: 6 additions & 12 deletions src/fides/api/models/privacy_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ class ConsentReportingMixinV2(ConsentIdentitiesMixin):

notice_name = Column(String, index=True) # Privacy Notice name or "TCF"

property_id = Column(
String,
index=True,
nullable=True,
)

# The specific version of the experience config the user was shown to present the relevant notice
# Contains the version, language, button labels, description, etc.
@declared_attr
Expand Down Expand Up @@ -327,12 +333,6 @@ def __tablename__(self) -> str:
MutableDict.as_mutable(JSONB)
) # Dict of all the TCF attributes served if applicable

property_id = Column(
String,
index=True,
nullable=True,
)

@staticmethod
def get_by_served_id(db: Session, served_id: str) -> Query:
"""Retrieves all ServedNoticeHistory records with a common served_notice_history_id - generated
Expand Down Expand Up @@ -394,12 +394,6 @@ def __tablename__(self) -> str:
MutableDict.as_mutable(JSONB)
) # Dict of TCF attributes saved, for a TCF notice

property_id = Column(
String,
index=True,
nullable=True,
)

privacy_request = relationship(PrivacyRequest, backref="privacy_preferences")

def cache_system_status(
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/application_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
ProvidedIdentity,
RequestTask,
)
from fides.api.models.property import Property
from fides.api.models.registration import UserRegistration
from fides.api.models.sql_models import DataCategory as DataCategoryDbModel
from fides.api.models.sql_models import Dataset as CtlDataset
Expand All @@ -81,6 +82,8 @@
MessagingServiceSecrets,
MessagingServiceType,
)
from fides.api.schemas.property import Property as PropertySchema
from fides.api.schemas.property import PropertyType
from fides.api.schemas.redis_cache import CustomPrivacyRequestField, Identity
from fides.api.schemas.storage.storage import (
FileNaming,
Expand Down Expand Up @@ -3245,3 +3248,15 @@ def postgres_and_mongo_dataset_graph(
dataset_mongo = Dataset(**example_datasets[1])
mongo_graph = convert_dataset_to_graph(dataset_mongo, mongo_connection_config.key)
return DatasetGraph(*[graph, mongo_graph])


@pytest.fixture(scope="function")
def property_a(db) -> Generator:
prop_a = Property.create(
db=db,
data=PropertySchema(
name="New Property", type=PropertyType.website, experiences=[]
).dict(),
)
yield prop_a
prop_a.delete(db=db)
12 changes: 7 additions & 5 deletions tests/ops/models/test_privacy_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@


class TestPrivacyPreference:

def test_privacy_notice_preference(
self,
db,
privacy_experience_privacy_center,
privacy_notice_us_ca_provide,
served_notice_history,
property_a,
):
preference_history_record = PrivacyPreferenceHistory.create(
db=db,
Expand All @@ -33,6 +35,7 @@ def test_privacy_notice_preference(
"user_geography": "us_ca",
"url_recorded": "https://example.com/privacy_center",
"served_notice_history_id": served_notice_history.served_notice_history_id,
"property_id": property_a.id,
},
check_name=False,
)
Expand All @@ -46,14 +49,11 @@ def test_privacy_notice_preference(
preference_history_record.privacy_notice_history
== privacy_notice_us_ca_provide.translations[0].histories[0]
)
assert preference_history_record.property_id == property_a.id

preference_history_record.delete(db)

def test_tcf_preference(
self,
db,
privacy_experience_france_overlay,
):
def test_tcf_preference(self, db, privacy_experience_france_overlay, property_a):
preference_history_record = PrivacyPreferenceHistory.create(
db=db,
data={
Expand Down Expand Up @@ -83,6 +83,7 @@ def test_tcf_preference(
"feature_preferences": [],
"system_legitimate_interests_preferences": [],
},
"property_id": property_a.id,
},
)
assert preference_history_record.preference == UserConsentPreference.tcf
Expand All @@ -100,6 +101,7 @@ def test_tcf_preference(
"feature_preferences": [],
"system_legitimate_interests_preferences": [],
}
assert preference_history_record.property_id == property_a.id

preference_history_record.delete(db)

Expand Down
13 changes: 1 addition & 12 deletions tests/ops/models/test_property.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Generator
from typing import Any, Dict

import pytest
from sqlalchemy.orm import Session
Expand All @@ -9,17 +9,6 @@


class TestProperty:
@pytest.fixture(scope="function")
def property_a(self, db) -> Generator:
prop_a = Property.create(
db=db,
data=PropertySchema(
name="New Property", type=PropertyType.website, experiences=[]
).dict(),
)
yield prop_a
prop_a.delete(db=db)

@pytest.fixture(scope="function")
def minimal_experience(
self, db, privacy_experience_privacy_center
Expand Down

0 comments on commit 2c9433e

Please sign in to comment.