Exemplo n.º 1
0
  def testPersonalExtensionIsSetWithEmptyDate(self):
    """Tests that personal extension is set even if a date is empty."""
    self._seedProjectData()

    user = profile_utils.seedNDBUser(host_for=[self.program])
    profile_utils.loginNDB(user)

    # seed midterm evaluation
    properties = {'link_id': project_survey_model.MIDTERM_EVAL}
    survey = survey_utils.SurveyHelper(
        self.gsoc, False).createStudentEvaluation(override=properties)

    # set personal extension with no end date
    start_date = date.today()
    post_data = {
        project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
        'start_date': unicode(start_date),
        'end_date': unicode('')
        }
    response = self.post(self._getUrl(self.project), post_data)
    self.assertResponseRedirect(response)

    # check if personal extension is set properly
    extension = survey_logic.getPersonalExtension(
        self.student.key, survey.key())
    self.assertIsNotNone(extension)
    self.assertEqual(start_date, extension.start_date.date())
    self.assertIsNone(extension.end_date)

    # update the extension - this time with no start date
    end_date = date.today()
    post_data = {
        project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
        'start_date': unicode(''),
        'end_date': unicode(end_date)
        }
    response = self.post(self._getUrl(self.project), post_data)
    self.assertResponseRedirect(response)

    # check if personal extension is set properly
    updated_extension = survey_logic.getPersonalExtension(
        self.student.key, survey.key())
    self.assertIsNotNone(updated_extension)
    self.assertIsNone(updated_extension.start_date)
    self.assertEqual(end_date, updated_extension.end_date.date())

    # check that updated extension is represented by the same entity
    self.assertEqual(extension.key, updated_extension.key)
Exemplo n.º 2
0
    def testPersonalExtensionIsSetWithEmptyDate(self):
        """Tests that personal extension is set even if a date is empty."""
        self._seedProjectData()

        user = profile_utils.seedNDBUser(host_for=[self.program])
        profile_utils.loginNDB(user)

        # seed midterm evaluation
        properties = {'link_id': project_survey_model.MIDTERM_EVAL}
        survey = survey_utils.SurveyHelper(
            self.gsoc, False).createStudentEvaluation(override=properties)

        # set personal extension with no end date
        start_date = date.today()
        post_data = {
            project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
            'start_date': unicode(start_date),
            'end_date': unicode('')
        }
        response = self.post(self._getUrl(self.project), post_data)
        self.assertResponseRedirect(response)

        # check if personal extension is set properly
        extension = survey_logic.getPersonalExtension(self.student.key,
                                                      survey.key())
        self.assertIsNotNone(extension)
        self.assertEqual(start_date, extension.start_date.date())
        self.assertIsNone(extension.end_date)

        # update the extension - this time with no start date
        end_date = date.today()
        post_data = {
            project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
            'start_date': unicode(''),
            'end_date': unicode(end_date)
        }
        response = self.post(self._getUrl(self.project), post_data)
        self.assertResponseRedirect(response)

        # check if personal extension is set properly
        updated_extension = survey_logic.getPersonalExtension(
            self.student.key, survey.key())
        self.assertIsNotNone(updated_extension)
        self.assertIsNone(updated_extension.start_date)
        self.assertEqual(end_date, updated_extension.end_date.date())

        # check that updated extension is represented by the same entity
        self.assertEqual(extension.key, updated_extension.key)
Exemplo n.º 3
0
    def isStudentSurveyActive(self, survey, student, show_url=None):
        """Checks if the student survey can be taken by the specified student.

    Args:
      survey: a survey entity.
      student: a student profile entity.
      show_url: survey show page URL to which the user should be redirected.

    Raises:
      exception.Redirect: if the active period is over and URL to redirect
        is specified.
      exception.Forbidden: if it is not possible to access survey
        at this time.
    """
        active_period = survey_logic.getSurveyActivePeriod(survey)
        if active_period.state != survey_logic.IN_PERIOD_STATE:
            # try finding a personal extension for the student
            extension = survey_logic.getPersonalExtension(
                student.key, survey.key())
            active_period = survey_logic.getSurveyActivePeriod(
                survey, extension=extension)

            if active_period.state == survey_logic.POST_PERIOD_STATE and show_url:
                raise exception.Redirect(show_url)

            if active_period.state != survey_logic.IN_PERIOD_STATE:
                raise exception.Forbidden(
                    message=DEF_PAGE_INACTIVE_OUTSIDE %
                    (active_period.start, active_period.end))
Exemplo n.º 4
0
    def context(self, data, check, mutator):
        """See base.context for specification."""
        evaluations = project_survey_logic.getStudentEvaluations(
            data.program.key())

        extension_forms = []
        for evaluation in evaluations:
            # try getting existing extension for this evaluation
            extension = survey_logic.getPersonalExtension(
                ndb.Key.from_old_key(data.url_project.parent_key()),
                evaluation.key())
            initial = _getInitialValues(extension)

            name = _getPersonalExtensionFormName(evaluation.survey_type)
            extension_forms.append(
                PersonalExtensionForm(data=data.POST or None,
                                      name=name,
                                      title=evaluation.title,
                                      initial=initial))

        context = {
            'page_name': MANAGE_PROJECT_ADMIN_PAGE_NAME,
            'extension_forms': extension_forms,
        }

        return context
Exemplo n.º 5
0
    def testPersonalExtensionIsSet(self):
        """Tests that personal extension is set for an evaluation."""
        self._seedProjectData()

        user = profile_utils.seedNDBUser(host_for=[self.program])
        profile_utils.loginNDB(user)

        # seed midterm evaluation
        properties = {'link_id': project_survey_model.MIDTERM_EVAL}
        survey = survey_utils.SurveyHelper(
            self.gsoc, False).createStudentEvaluation(override=properties)

        # set personal extension
        start_date = date.today()
        end_date = date.today()
        post_data = {
            project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
            'start_date': unicode(start_date),
            'end_date': unicode(end_date)
        }
        response = self.post(self._getUrl(self.project), post_data)
        self.assertResponseRedirect(response)

        # check if personal extension is set properly
        extension = survey_logic.getPersonalExtension(self.student.key,
                                                      survey.key())
        self.assertIsNotNone(extension)
        self.assertEqual(start_date, extension.start_date.date())
        self.assertEqual(end_date, extension.end_date.date())
Exemplo n.º 6
0
  def testPersonalExtensionIsSet(self):
    """Tests that personal extension is set for an evaluation."""
    self._seedProjectData()

    user = profile_utils.seedNDBUser(host_for=[self.program])
    profile_utils.loginNDB(user)

    # seed midterm evaluation
    properties = {'link_id': project_survey_model.MIDTERM_EVAL}
    survey = survey_utils.SurveyHelper(
        self.gsoc, False).createStudentEvaluation(override=properties)

    # set personal extension
    start_date = date.today()
    end_date = date.today()
    post_data = {
        project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button',
        'start_date': unicode(start_date),
        'end_date': unicode(end_date)
        }
    response = self.post(self._getUrl(self.project), post_data)
    self.assertResponseRedirect(response)

    # check if personal extension is set properly
    extension = survey_logic.getPersonalExtension(
        self.student.key, survey.key())
    self.assertIsNotNone(extension)
    self.assertEqual(start_date, extension.start_date.date())
    self.assertEqual(end_date, extension.end_date.date())
Exemplo n.º 7
0
    def testPersonalExtensionDoesNotExist(self):
        """Tests that if a personal extensions does not exist, None is returned."""
        # try getting the extension
        result = survey_logic.getPersonalExtension(self.profile.key, self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 8
0
  def isStudentSurveyActive(self, survey, student, show_url=None):
    """Checks if the student survey can be taken by the specified student.

    Args:
      survey: a survey entity.
      student: a student profile entity.
      show_url: survey show page URL to which the user should be redirected.

    Raises:
      exception.Redirect: if the active period is over and URL to redirect
        is specified.
      exception.Forbidden: if it is not possible to access survey
        at this time.
    """
    active_period = survey_logic.getSurveyActivePeriod(survey)
    if active_period.state != survey_logic.IN_PERIOD_STATE:
      # try finding a personal extension for the student
      extension = survey_logic.getPersonalExtension(
          student.key, survey.key())
      active_period = survey_logic.getSurveyActivePeriod(
          survey, extension=extension)

      if active_period.state == survey_logic.POST_PERIOD_STATE and show_url:
        raise exception.Redirect(show_url)

      if active_period.state != survey_logic.IN_PERIOD_STATE:
        raise exception.Forbidden(message=DEF_PAGE_INACTIVE_OUTSIDE % (
            active_period.start, active_period.end))
Exemplo n.º 9
0
    def testPersonalExtensionDoesNotExist(self):
        """Tests that if a personal extensions does not exist, None is returned."""
        # try getting the extension
        result = survey_logic.getPersonalExtension(self.profile.key,
                                                   self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 10
0
    def testPersonalExtensionForAnotherSurvey(self):
        """Tests for no result even if extension exists for another survey."""
        # create an extension but for another survey
        other_survey = seeder_logic.seed(soc_survey_model.Survey)
        # TODO(daniel): NDB migration
        ndb_other_survey_key = ndb.Key.from_old_key(other_survey.key())
        extension = survey_model.PersonalExtension(parent=self.profile.key, survey=ndb_other_survey_key)
        extension.put()

        # try getting the extension for the main survey
        result = survey_logic.getPersonalExtension(self.profile.key, self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 11
0
    def testPersonalExtensionExists(self):
        """Tests that if a personal extension exists, it will be returned."""
        # create personal extension
        # TODO(daniel): NDB migration
        ndb_survey_key = ndb.Key.from_old_key(self.survey.key())

        extension = survey_model.PersonalExtension(parent=self.profile.key, survey=ndb_survey_key)
        extension.put()

        # try getting the extension
        result = survey_logic.getPersonalExtension(self.profile.key, self.survey.key())

        # the extension should be returned
        self.assertEqual(extension.key, result.key)
Exemplo n.º 12
0
    def testPersonalExtensionForAnotherProfile(self):
        """Tests for no result even if extension exists for another profile."""
        # TODO(daniel): NDB migration
        ndb_survey_key = ndb.Key.from_old_key(self.survey.key())

        # create an extension but for another profile
        other_profile = profile_utils.seedNDBProfile(self.program.key())
        extension = survey_model.PersonalExtension(parent=other_profile.key, survey=ndb_survey_key)
        extension.put()

        # try getting the extension for the main profile
        result = survey_logic.getPersonalExtension(self.profile.key, self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 13
0
    def testPersonalExtensionForAnotherSurvey(self):
        """Tests for no result even if extension exists for another survey."""
        # create an extension but for another survey
        other_survey = seeder_logic.seed(soc_survey_model.Survey)
        # TODO(daniel): NDB migration
        ndb_other_survey_key = ndb.Key.from_old_key(other_survey.key())
        extension = survey_model.PersonalExtension(parent=self.profile.key,
                                                   survey=ndb_other_survey_key)
        extension.put()

        # try getting the extension for the main survey
        result = survey_logic.getPersonalExtension(self.profile.key,
                                                   self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 14
0
    def testPersonalExtensionExists(self):
        """Tests that if a personal extension exists, it will be returned."""
        # create personal extension
        # TODO(daniel): NDB migration
        ndb_survey_key = ndb.Key.from_old_key(self.survey.key())

        extension = survey_model.PersonalExtension(parent=self.profile.key,
                                                   survey=ndb_survey_key)
        extension.put()

        # try getting the extension
        result = survey_logic.getPersonalExtension(self.profile.key,
                                                   self.survey.key())

        # the extension should be returned
        self.assertEqual(extension.key, result.key)
Exemplo n.º 15
0
    def testPersonalExtensionForAnotherProfile(self):
        """Tests for no result even if extension exists for another profile."""
        # TODO(daniel): NDB migration
        ndb_survey_key = ndb.Key.from_old_key(self.survey.key())

        # create an extension but for another profile
        other_profile = profile_utils.seedNDBProfile(self.program.key())
        extension = survey_model.PersonalExtension(parent=other_profile.key,
                                                   survey=ndb_survey_key)
        extension.put()

        # try getting the extension for the main profile
        result = survey_logic.getPersonalExtension(self.profile.key,
                                                   self.survey.key())

        # no extension should be returned
        self.assertIsNone(result)
Exemplo n.º 16
0
  def context(self, data, check, mutator):
    """See base.context for specification."""
    evaluations = project_survey_logic.getStudentEvaluations(
        data.program.key())

    extension_forms = []
    for evaluation in evaluations:
      # try getting existing extension for this evaluation
      extension = survey_logic.getPersonalExtension(
          ndb.Key.from_old_key(data.url_project.parent_key()),
          evaluation.key())
      initial = _getInitialValues(extension)

      name = _getPersonalExtensionFormName(evaluation.survey_type)
      extension_forms.append(PersonalExtensionForm(data=data.POST or None,
          name=name, title=evaluation.title, initial=initial))

    context = {
        'page_name': MANAGE_PROJECT_ADMIN_PAGE_NAME,
        'extension_forms': extension_forms,
        }

    return context