From 620d514ceaf762f1217575edebac9770bb73d26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 10 Aug 2018 14:25:03 +0200 Subject: [PATCH] api: expose boolean user attributes as booleans (#25632) --- src/authentic2/attribute_kinds.py | 1 + tests/test_api.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index b3ac4f7e4..27ae00b40 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -118,6 +118,7 @@ DEFAULT_ATTRIBUTE_KINDS = [ 'field_class': forms.BooleanField, 'serialize': lambda x: str(int(bool(x))), 'deserialize': lambda x: bool(int(x)), + 'rest_framework_field_class': serializers.NullBooleanField, }, { 'label': _('date'), diff --git a/tests/test_api.py b/tests/test_api.py index b01639b82..240b0382f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -141,6 +141,16 @@ def test_api_users_list(app, user): assert resp.json['next'] is None +def test_api_users_boolean_attribute(app, superuser): + from authentic2.models import Attribute, AttributeValue + at = Attribute.objects.create( + kind='boolean', name='boolean', label='boolean', required=True) + superuser.attributes.boolean = True + app.authorization = ('Basic', (superuser.username, superuser.username)) + resp = app.get('/api/users/%s/' % superuser.uuid) + assert resp.json['boolean'] is True + + def test_api_users_list_by_authorized_service(app, superuser): from authentic2.models import Service