1👍
✅
Two things you could check:
- When you create the request
self.client.post(url, {"name": ""})
is a Thing instance returned here:thing = Thing.objects.get(id=thing_id)
If not it will not reach the line of code where you set your error message:messages.error(request, "Oops!")
as Thing.objects.get will throw an error.
If there are no results that match the query, get() will raise a
DoesNotExist exception.
- If the first thing does return a Thing instance, you could check whether a redirect return
redirect("/wherever")
after setting the error messagemessages.error(request, "Oops!")
does change anything.
Source:stackexchange.com