I have the following function:
def destroy(self, request, *args, **kwargs):
id_act = kwargs.get('pk', None)
userObject = User.objects.get(pk=self.request.user.pk)
try:
ocurrencia = Ocurrencia.objects.get(pk=id_act)
if ComprobarPermisos.es_creador(ocurrencia, userObject) or ComprobarPermisos.es_jefe(ocurrencia,
userObject):
repeticion = Repeticion.objects.get(ocurrencia=ocurrencia)
if repeticion.__isnull== True:
self.perform_destroy(ocurrencia)
return Response({'Actividad eliminada'}, status=status.HTTP_301_MOVED_PERMANENTLY)
else:
evento = ocurrencia.event
Ocurrencia.objects.filter(event_id=evento.pk).delete()
self.perform_destroy(evento)
return Response({'Actividad eliminada'}, status=status.HTTP_301_MOVED_PERMANENTLY)
else:
return Response({'Usted no puede ejecutar esta operacion'}, status=HTTP_403_FORBIDDEN)
except Http404:
return Response({'Not Found'}, status=status.HTTP_404_NOT_FOUND)
My problem is as follows: I am doing a test to test this function and my "scenario" is that repeticion = Repeticion.objects.get(ocurrencia=ocurrencia)
fails. That is, if there is no repetition, what is coming in the else must be executed. When I run the test, the if fails but does not execute what comes in the else. Any idea what may be happening?