jeudi 25 avril 2019

How to handle Django messages middleware while testing post

I'm trying to test an UpdateView that add a message to the redirected success page. It seems my issue comes from messages because pytest returns:

django.contrib.messages.api.MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

My test code is:

def test_authenticated_staff(self, rf):
    langues = LanguageCatalog.objects.create(
        lang_src='wz',
        lang_dest='en',
        percent='4'
    )
    req = rf.get(reverse("dashboard.staff:lang-update", kwargs={'pk': langues.pk}))
    data = {'lang_src': 'it',
            'lang_dest': 'en',
            'percent': '34'}
    req = rf.post(reverse(
        "dashboard.staff:lang-update", kwargs={'pk': langues.pk}), data=data)
    req.user = UserFactory()
    resp = views.LangUpdateView.as_view()(req, pk=langues.pk)


I precise that the MessageMiddleware is present in MIDDLEWARE settings. I use Django==2.0.13.

Aucun commentaire:

Enregistrer un commentaire