From db9c567ab57bf0ce50d9e876edb193c9ff8b0fca Mon Sep 17 00:00:00 2001 From: Nico Virkki Date: Wed, 3 Apr 2024 16:06:54 +0300 Subject: [PATCH] feat: add privacy policy and terms of use urls to gql api Refs HP-2332 --- .../snapshots/snap_test_graphql_api_schema.py | 3 ++ services/schema.py | 2 + services/tests/test_gql_services_query.py | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py b/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py index 3175e2bf..4b7a1291 100644 --- a/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py +++ b/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py @@ -4,6 +4,7 @@ from snapshottest import Snapshot + snapshots = Snapshot() snapshots['test_graphql_schema_matches_the_reference 1'] = '''type Query { @@ -50,6 +51,8 @@ isPureKeycloak: Boolean! title(language: TranslationLanguage): String description(language: TranslationLanguage): String + privacyPolicyUrl(language: TranslationLanguage): String + termsOfUseUrl(language: TranslationLanguage): String } interface Node { diff --git a/services/schema.py b/services/schema.py index 705cac61..d8fca740 100644 --- a/services/schema.py +++ b/services/schema.py @@ -78,6 +78,8 @@ class Meta: "gdpr_url", "gdpr_query_scope", "gdpr_delete_scope", + "privacy_policy_url", + "terms_of_use_url", ) filter_fields = [] interfaces = (relay.Node,) diff --git a/services/tests/test_gql_services_query.py b/services/tests/test_gql_services_query.py index d0520c69..219e4ad8 100644 --- a/services/tests/test_gql_services_query.py +++ b/services/tests/test_gql_services_query.py @@ -1,5 +1,7 @@ +import pytest from guardian.shortcuts import assign_perm +from open_city_profile import settings from open_city_profile.tests.asserts import assert_match_error_code from services.models import Service @@ -97,3 +99,47 @@ def test_requires_view_service_permission(user_gql_client): assert executed["data"] == {"services": None} assert_match_error_code(executed, "PERMISSION_DENIED_ERROR") + + +@pytest.mark.parametrize("language", dict(settings.LANGUAGES).keys()) +def test_query_service_terms_of_use_url(user_gql_client, language): + terms_of_use_url = f"https://example.com/terms-of-use/{language}/" + service = ServiceFactory() + service.set_current_language(language) + service.terms_of_use_url = terms_of_use_url + service.save() + service.set_current_language("fr") + + assign_perm("services.view_service", user_gql_client.user) + query = ( + """ + query { + services { + edges { + node { + name + termsOfUseUrl(language: %s) + } + } + } + } + """ + % language.upper() + ) + + executed = user_gql_client.execute(query, service=None) + + assert executed["data"] == { + "services": { + "edges": [ + { + "node": { + "name": service.name, + "termsOfUseUrl": terms_of_use_url, + } + } + ] + } + } + + assert "errors" not in executed