From d8461ded39ba11c491e06ef8a52215ffe0fcb227 Mon Sep 17 00:00:00 2001 From: Jade Wibbels Date: Fri, 17 Jan 2025 15:49:29 -0700 Subject: [PATCH 1/2] added sorting for system.privacy_declarations and a test to verify --- src/fides/api/models/sql_models.py | 1 + tests/ctl/models/test_sql_models.py | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/ctl/models/test_sql_models.py diff --git a/src/fides/api/models/sql_models.py b/src/fides/api/models/sql_models.py index c89e90c526..ff45fd8b7a 100644 --- a/src/fides/api/models/sql_models.py +++ b/src/fides/api/models/sql_models.py @@ -416,6 +416,7 @@ class System(Base, FidesBase): cascade="all, delete", back_populates="system", lazy="selectin", + order_by="PrivacyDeclaration.name", ) data_stewards = relationship( diff --git a/tests/ctl/models/test_sql_models.py b/tests/ctl/models/test_sql_models.py new file mode 100644 index 0000000000..637e7dd9e5 --- /dev/null +++ b/tests/ctl/models/test_sql_models.py @@ -0,0 +1,32 @@ +from fides.api.models.sql_models import PrivacyDeclaration +from fides.api.db.system import get_system + + +def test_system_privacy_declarations_in_alphabetical_order(db, system): + """ + Ensure that the system privacy declarations are in alphabetical order by name + """ + # Add more privacy declarations to the system + new_privacy_declarations = [ + { + "data_use": "marketing.advertising.profiling", + "name": "Declaration Name", + "system_id": system.id, + }, + { + "data_use": "essential", + "name": "Another Declaration Name", + "system_id": system.id, + } + ] + for data in new_privacy_declarations: + PrivacyDeclaration.create(db=db, data=data) + db.commit() + + db.refresh(system) + updated_system = get_system(db, system.fides_key) + + privacy_declarations = updated_system.privacy_declarations + sorted_privacy_declarations = sorted(privacy_declarations, key=lambda x: x.name) + + assert privacy_declarations == sorted_privacy_declarations, "Privacy declarations are not in alphabetical order by name" From 7713582824b8fd6b184e33c5c5f2e667cc801d59 Mon Sep 17 00:00:00 2001 From: Jade Wibbels Date: Fri, 17 Jan 2025 16:33:52 -0700 Subject: [PATCH 2/2] linting --- tests/ctl/models/test_sql_models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/ctl/models/test_sql_models.py b/tests/ctl/models/test_sql_models.py index 637e7dd9e5..707c5f51f4 100644 --- a/tests/ctl/models/test_sql_models.py +++ b/tests/ctl/models/test_sql_models.py @@ -1,5 +1,5 @@ -from fides.api.models.sql_models import PrivacyDeclaration from fides.api.db.system import get_system +from fides.api.models.sql_models import PrivacyDeclaration def test_system_privacy_declarations_in_alphabetical_order(db, system): @@ -17,7 +17,7 @@ def test_system_privacy_declarations_in_alphabetical_order(db, system): "data_use": "essential", "name": "Another Declaration Name", "system_id": system.id, - } + }, ] for data in new_privacy_declarations: PrivacyDeclaration.create(db=db, data=data) @@ -29,4 +29,6 @@ def test_system_privacy_declarations_in_alphabetical_order(db, system): privacy_declarations = updated_system.privacy_declarations sorted_privacy_declarations = sorted(privacy_declarations, key=lambda x: x.name) - assert privacy_declarations == sorted_privacy_declarations, "Privacy declarations are not in alphabetical order by name" + assert ( + privacy_declarations == sorted_privacy_declarations + ), "Privacy declarations are not in alphabetical order by name"