-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow always allowed data fields regardless of service
Unfortunately, couldn't find a way to test this properly. Setting the service to None in the GQL client causes an error. However, somehow the unknown service warning can still trigger. Refs: HP-2469
- Loading branch information
Showing
3 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
|
||
from profiles.models import AllowedDataFieldsMixin, Profile | ||
from services.models import Service | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_field_allowed_when_in_always_allow_fields(monkeypatch): | ||
monkeypatch.setattr(AllowedDataFieldsMixin, "always_allow_fields", ["id"]) | ||
service = Service.objects.create(name="Test Service") | ||
|
||
assert AllowedDataFieldsMixin.is_field_allowed_for_service("id", service) is True | ||
|
||
|
||
def test_field_allowed_when_service_is_none_and_in_always_allow_fields(monkeypatch): | ||
monkeypatch.setattr(AllowedDataFieldsMixin, "always_allow_fields", ["id"]) | ||
|
||
assert AllowedDataFieldsMixin.is_field_allowed_for_service("id", None) is True | ||
|
||
|
||
def test_field_not_allowed_when_service_is_not_defined(monkeypatch): | ||
monkeypatch.setattr(AllowedDataFieldsMixin, "always_allow_fields", []) | ||
|
||
assert AllowedDataFieldsMixin.is_field_allowed_for_service("id", None) is False | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_field_allowed_when_in_allowed_data_fields(monkeypatch): | ||
monkeypatch.setattr(Profile, "always_allow_fields", []) | ||
monkeypatch.setattr(Profile, "allowed_data_fields_map", {"id": ("id",)}) | ||
service = Service.objects.create(name="Test Service") | ||
service.allowed_data_fields.create(field_name="id") | ||
|
||
assert Profile.is_field_allowed_for_service("id", service) is True | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_field_not_allowed_when_not_in_allowed_data_fields(monkeypatch): | ||
monkeypatch.setattr(Profile, "always_allow_fields", []) | ||
monkeypatch.setattr(Profile, "allowed_data_fields_map", {}) | ||
service = Service.objects.create(name="Test Service") | ||
|
||
assert Profile.is_field_allowed_for_service("id", service) is False |