def testDataExtractorMustReturnAListOfTuplesContainingTheDataToBeExported(self):
     db_deliveries_extractor = DbDeliveriesExtractor()
     db_deliveries_extractor.course = self.course
     
     result_list = db_deliveries_extractor.get_data()
     
     first_entry = (self.practice_uid, self.student_name_1, self.student_first_name_1, self.student_last_name_1, self.automatic_result_successfull, 8)
     second_entry = (self.practice_uid,self.student_name_2 , self.student_first_name_2, self.student_last_name_2, self.automatic_result_failed,None)
     
     self.assertEquals(result_list[0], first_entry)
     self.assertEquals(result_list[1], second_entry)
Exemple #2
0
    def testDataExtractorMustReturnAListOfTuplesContainingTheDataToBeExported(
            self):
        db_deliveries_extractor = DbDeliveriesExtractor()
        db_deliveries_extractor.course = self.course

        result_list = db_deliveries_extractor.get_data()

        first_entry = (self.practice_uid, self.student_name_1,
                       self.student_first_name_1, self.student_last_name_1,
                       self.automatic_result_successfull, 8)
        second_entry = (self.practice_uid, self.student_name_2,
                        self.student_first_name_2, self.student_last_name_2,
                        self.automatic_result_failed, None)

        self.assertEquals(result_list[0], first_entry)
        self.assertEquals(result_list[1], second_entry)
Exemple #3
0
def download(request, idcourse):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        course = Course.objects.get(pk=idcourse)
        db_data_extractor = DbDeliveriesExtractor()
        db_data_extractor.course = course
        data = db_data_extractor.get_data()
        csv_tuple_printer = CsvTuplePrinter()
        output_file_name = get_output_file_name(course.name)
        csv_tuple_printer.open(output_file_name)
        for line in data:
            csv_tuple_printer.put(line)
        csv_tuple_printer.close()
        file = open(output_file_name)
        response = HttpResponse(file, content_type=TYPECSV)
        response['Content-Disposition'] = 'attachment; filename=%s' % output_file_name
        return response
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE