Projet

Général

Profil

0001-api-fix-case-of-boolean-user-s-attributs-fixes-26113.patch

Benjamin Dauvergne, 06 septembre 2018 11:14

Télécharger (2,29 ko)

Voir les différences:

Subject: [PATCH] api: fix case of boolean user's attributs (fixes #26113)

As NullBooleanField does not support the allow_null init attribute, we
must special case it and remember to never use BooleanField.
 src/authentic2/api_views.py |  6 +++++-
 tests/test_api.py           | 10 ++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
src/authentic2/api_views.py
339 339
                })
340 340
                if not at.required:
341 341
                    # setting an attribute to null will delete it
342
                    kwargs['allow_null'] = True
342
                    # NullBooleanField and BooleanField does not support allow_null
343
                    if field_class in (serializers.NullBooleanField, serializers.BooleanField):
344
                        field_class = serializers.NullBooleanField
345
                    else:
346
                        kwargs['allow_null'] = True
343 347
                    # if not stated otherwise by the definition of the kind, string alike fields
344 348
                    # accept blank values when not required
345 349
                    if (issubclass(field_class, serializers.CharField) and 'allow_blank' not in
tests/test_api.py
151 151
    assert resp.json['boolean'] is True
152 152

  
153 153

  
154
def test_api_users_boolean_attribute_optional(app, superuser):
155
    from authentic2.models import Attribute, AttributeValue
156
    at = Attribute.objects.create(
157
        kind='boolean', name='boolean', label='boolean', required=False)
158
    superuser.attributes.boolean = True
159
    app.authorization = ('Basic', (superuser.username, superuser.username))
160
    resp = app.get('/api/users/%s/' % superuser.uuid)
161
    assert resp.json['boolean'] is True
162

  
163

  
154 164
def test_api_users_list_by_authorized_service(app, superuser):
155 165
    from authentic2.models import Service
156 166

  
157
-