api: expose boolean user attributes as booleans (#25632)

This commit is contained in:
Frédéric Péters 2018-08-10 14:25:03 +02:00
parent 031db4a72d
commit 620d514cea
2 changed files with 11 additions and 0 deletions

View File

@ -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'),

View File

@ -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