Projet

Général

Profil

Bug #40733

python3: Impossible d'ajouter un rôle

Ajouté par Nicolas Roche il y a environ 4 ans. Mis à jour il y a environ 4 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
-
Catégorie:
-
Version cible:
-
Début:
13 mars 2020
Echéance:
% réalisé:

0%

Temps estimé:
Patch proposed:
Oui
Planning:
Non

Description

Message ajax : 'Dialog box loading failed: error Internal Server Error'
et trace :

  File "/home/nroche/src/authentic/src/authentic2/manager/views.py", line 144, in dispatch
    return super(PermissionMixin, self).dispatch(request, *args, **kwargs)
  File "/home/nroche/src/authentic/src/authentic2/manager/views.py", line 266, in dispatch
    return self.return_ajax_response(request, response)
  File "/home/nroche/src/authentic/src/authentic2/manager/views.py", line 286, in return_ajax_response
    return HttpResponse(json.dumps(data), content_type='application/json')
  File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable


Fichiers


Demandes liées

Lié à Publik Installation Développeur - Development #40403: Tourner authentic2 en python3Fermé04 mars 2020

Actions

Révisions associées

Révision 5d8c2355 (diff)
Ajouté par Nicolas Roche il y a environ 4 ans

python3: build ajax response using text content (#40733)

Historique

#1

Mis à jour par Nicolas Roche il y a environ 4 ans

Je proposerai bien cette correction, mais je ne sais pas comment écrire le test adéquat.
J'ai essayé sans succès de passer derrière 'if not request.is_ajax():', comme par exemple avec :

def test_manager_create_role_using_ajax(superuser_or_admin, app):
    ou_add = login(app, superuser_or_admin, reverse('a2-manager-role-add'))
    ou_add.post('/manage/roles/add/', xhr=True)

#2

Mis à jour par Nicolas Roche il y a environ 4 ans

#3

Mis à jour par Nicolas Roche il y a environ 4 ans

  • Statut changé de Solution proposée à Information nécessaire

Je couvre le code avec ce test ; il faut à présent qu'il teste quelque-chose.

def test_manager_create_role_using_ajax(superuser_or_admin, app):
    app.set_user(superuser_or_admin.username)
    resp = app.get('/manage/roles/add/', xhr=True)

Je peux partir la dessus ?

#4

Mis à jour par Nicolas Roche il y a environ 4 ans

bof, en fait je me dis qu'il n'y a de particulier à tester concernant ce patch.

#5

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

Le assert 'Authentic' n'est pas vraiment utile, tu peux juste vérifier que ['content'] est non vide, ça fera un test plus robuste.

#6

Mis à jour par Benjamin Dauvergne il y a environ 4 ans

  • Statut changé de Solution proposée à Solution validée
#7

Mis à jour par Nicolas Roche il y a environ 4 ans

  • Statut changé de Solution validée à Résolu (à déployer)
commit 5d8c2355be4e76c118d01166d114a44f84a36d76
Author: Nicolas ROCHE <nroche@entrouvert.com>
Date:   Fri Mar 13 23:55:08 2020 +0100

    python3: build ajax response using text content (#40733)
#8

Mis à jour par Frédéric Péters il y a environ 4 ans

  • Statut changé de Résolu (à déployer) à Solution déployée

Formats disponibles : Atom PDF