Ejemplo n.º 1
0
def insert_test_result(request):
    if request.method == 'POST':
        logger.debug("insert load test request with body:" + request.body)
        data = request.POST if request.POST else convert_request_body_to_form_validation(request.body)
        test_date = get_current_day_start_date() if data['test_date'] is None else get_current_day_start_date(data['test_date'])
        
        try:
            exist_test_result = get_object_or_404(LoadTestResult, test_date=test_date, test_type=data['test_type'], test_version=data['test_version'])
            logger.info("Test result for %s[%s][%s] is existed, just update it", data['test_type'], data['test_version'], test_date)
            
            exist_test_result.test_result_bitrate = data['test_result_bitrate']
            exist_test_result.test_result_error = data['test_result_error']
            exist_test_result.test_result_index = data['test_result_index']
            exist_test_result.save()
            return HttpResponse("Test result has been updated.")
        except:
            # 这里没有验证。如果需要验证,可以采用form验证的方式
            result = LoadTestResult()
            result.test_type = data['test_type']
            result.test_version = data['test_version']
            result.test_date = test_date
            result.test_result_index = data['test_result_index']
            result.test_result_bitrate = data['test_result_bitrate']
            result.test_result_error = data['test_result_error']
            result.save()
            return HttpResponse("Test result has been saved.")
    else:   
        return HttpResponse("Must be post with XML body", status=400)
Ejemplo n.º 2
0
 def test_unique(self):
     try:
         with transaction.atomic():
             instance = LoadTestResult() 
             instance.test_date = self.test_date
             instance.test_type = self.test_type
             instance.test_version = self.test_version
             instance.test_result_index = self.test_result_index
             instance.test_result_bitrate = self.test_result_bitrate
             instance.save()
     except Exception, e:
         self.assertIsInstance(e, IntegrityError)