Exemple #1
0
    def testGradingRecordsOverviewGet(self):
        grading_survey_group = self.createGradingSurveyGroup()
        url = '/gsoc/grading_records/overview/%s/%d' % (
            self.program.key().name(), grading_survey_group.key().id())
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertGradingRecordsOverviewTemplatesUsed(response)

        # list response without any projects
        response = self.getListResponse(url, 0)
        self.assertIsJsonResponse(response)
        data = response.context['data']['']
        self.assertEqual(0, len(data))

        # list response with projects
        student = profile_utils.seedNDBStudent(self.program)
        project = project_utils.seedProject(student,
                                            self.program.key(),
                                            org_key=self.org.key)

        other_student = profile_utils.seedNDBStudent(self.program)
        project_utils.seedProject(other_student,
                                  self.program.key(),
                                  org_key=self.org.key)

        grading_record.updateOrCreateRecordsFor(grading_survey_group,
                                                [project])

        response = self.getListResponse(url, 0)
        self.assertIsJsonResponse(response)
        data = response.context['data']['']
        self.assertEqual(1, len(data))
  def testGradingRecordsOverviewGet(self):
    grading_survey_group = self.createGradingSurveyGroup()
    url = '/gsoc/grading_records/overview/%s/%d' % (
        self.program.key().name(), grading_survey_group.key().id())
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertGradingRecordsOverviewTemplatesUsed(response)

    # list response without any projects
    response = self.getListResponse(url, 0)
    self.assertIsJsonResponse(response)
    data = response.context['data']['']
    self.assertEqual(0, len(data))

    # list response with projects
    student = profile_utils.seedNDBStudent(self.program)
    project = project_utils.seedProject(
        student, self.program.key(), org_key=self.org.key)

    other_student = profile_utils.seedNDBStudent(self.program)
    project_utils.seedProject(
        other_student, self.program.key(), org_key=self.org.key)

    grading_record.updateOrCreateRecordsFor(grading_survey_group, [project])

    response = self.getListResponse(url, 0)
    self.assertIsJsonResponse(response)
    data = response.context['data']['']
    self.assertEqual(1, len(data))
  def updateRecordsForSurveyGroup(self, request, *args, **kwargs):
    """Updates or creates GradingRecords for the given GradingSurveyGroup.

    Expects the following to be present in the POST dict:
      group_key: Specifies the GradingSurveyGroup key name.
      cursor: optional to specify where the query should continue from.

    Args:
      request: Django Request object
    """
    post_dict = request.POST

    group_key = post_dict.get('group_key')

    if not group_key:
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid updateRecordForSurveyGroup data: %s' % post_dict)

    # get the GradingSurveyGroup for the given key
    survey_group = GSoCGradingSurveyGroup.get_by_id(int(group_key))

    if not survey_group:
      # invalid GradingSurveyGroup specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid GradingSurveyGroup specified: %s' % group_key)

    q = GSoCProject.all()
    q.filter('program', survey_group.program)
    q.filter('status', 'accepted')

    if 'cursor' in post_dict:
      q.with_cursor(post_dict['cursor'])

    # get the first batch_size number of StudentProjects
    projects = q.fetch(self.DEF_BATCH_SIZE)

    if not projects:
      # task completed, update timestamp for last update complete
      survey_group.last_update_complete = datetime.datetime.now()
      survey_group.put()
      return http.HttpResponse()

    # update/create and batch put the new GradingRecords
    grading_record.updateOrCreateRecordsFor(survey_group, projects)

    # pass along these params as POST to the new task
    task_params = {'group_key': group_key,
                   'cursor': q.cursor()}

    new_task = taskqueue.Task(params=task_params, url=request.path)
    new_task.add()

    # task completed, return OK
    return http.HttpResponse('OK')