Exemple #1
0
 def test_invalidate_incident(self):
     """Check that an incident when tagged as incorrect will properly be un-validated."""
     i1 = Incident(line=Line.objects.get(pk=1), reason="Probleme dans le RER B", source="Android app", level=4)
     i1.save()
     response = self.client.post(reverse("api_vote_url", args=["json", i1.id, "minus"]), "", content_type="")
     self.assertEqual(response.status_code, 201)
     self.assertFalse(Incident.objects.get(pk=i1.id).validated)   
Exemple #2
0
 def test_get_incident(self):            
     # init incident :
     i1 = Incident(line=Line.objects.get(pk=1), reason="Probleme dans le RER B", source="Android app", level=4)
     i1.save()    
     
     c = Client()
     respo = c.get("/api/incident.json/%s" % (i1.pk))
     self.assertEqual(respo.status_code, 200)
 def create(self, request):
     """
     Throttled to create only 5 incidents by 5 minutes.
     """
     if request.content_type:
         try:
             data = request.data
             line = None
             if 'line_id' in data:
                 line = Line.objects.get(pk=int(data['line_id']))
             elif 'line_name' in data:
                 line = Line.objects.get_or_create(name=data['line_name'].strip())[0]
             if not line:
                 logger.error('Incident CRUD Handler got request with no line', exc_info=sys.exc_info(),
                   extra={
                       'request': request,
                       'url': request.build_absolute_uri(),
                       'data': {
                           'content_type': request.content_type,
                           'data': data
                       }
                   })
                 return rc.BAD_REQUEST
             comment = data['reason']
             source = data['source']
             incident = Incident(line=line, source=source, reason=comment)
             if 'level' in data:
                 incident.level = int(data['level'])
             incident.save()
             return HttpResponse(str(incident.id), status=201)
         except:
             logger.error('Incident CRUD Handler failed to process external request', exc_info=sys.exc_info(),
                   extra={
                       'request': request,
                       'url': request.build_absolute_uri(),
                       'data': {
                           'content_type': request.content_type,
                           'data': data
                       }
                   })
             return rc.BAD_REQUEST
     else:
         try:
             form = AddIncidentForm(request.POST)
             if form.is_valid():
                 form.save()            
                 return render('static/thanks.html', {'number': Incident.objects.count()});
             else:
                 resp = rc.BAD_REQUEST
                 resp.write("Incorrect parameters, submitted form is invalid.")
                 return resp
         except:     
             logger.error("Incident form submitted failed to be validated",
                          exc_info=sys.exc_info(), extra= {
                              'request': request,
                              'url': request.build_absolute_uri(),
                          })
             return rc.BAD_REQUEST