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))
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))
def testForExtensionWithStartAndEndDate(self): """Tests active period if there is an extension with start and end date.""" self.survey.survey_start = timeline_utils.past(delta=100) self.survey.survey_end = timeline_utils.future(delta=100) # test for an extension that is within the survey period self.extension.start_date = self.survey.survey_start + timedelta(1) self.extension.end_date = self.survey.survey_end - timedelta(1) # active period should be the same as for the survey period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.survey.survey_start) self.assertEquals(period.end, self.survey.survey_end) # test for an extension which is a superset of the survey self.extension.start_date = self.survey.survey_start - timedelta(1) self.extension.end_date = self.survey.survey_end + timedelta(1) # active period should be the same as for the extension period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.extension.start_date) self.assertEquals(period.end, self.extension.end_date) # test for an extension which starts earlier than the survey and ends # before the survey ends self.extension.start_date = self.survey.survey_start - timedelta(1) self.extension.end_date = self.survey.survey_end - timedelta(1) # active period should start as extension starts and ends as survey ends period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.extension.start_date) self.assertEquals(period.end, self.survey.survey_end) # test for an extension which starts after than the survey and ends # before the survey ends self.extension.start_date = self.survey.survey_start + timedelta(1) self.extension.end_date = self.survey.survey_end + timedelta(1) # active period should start when survey starts and end when extension ends period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.survey.survey_start) self.assertEquals(period.end, self.extension.end_date) # test for an extension that does not overlap with the survey dates self.extension.start_date = self.survey.survey_start - timedelta(10) self.extension.end_date = self.survey.survey_start - timedelta(5) # active period should span between extension start and survey end period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.extension.start_date) self.assertEquals(period.end, self.survey.survey_end)
def testForNoExtension(self): """Tests active period if there is no extension.""" # test for survey with both start and end dates self.survey.survey_start = timeline_utils.past() self.survey.survey_end = timeline_utils.future() period = survey_logic.getSurveyActivePeriod(self.survey) self.assertEquals(period.start, self.survey.survey_start) self.assertEquals(period.end, self.survey.survey_end)
def testForExtensionWithEndDate(self): """Tests active period for extensions that have only start date.""" self.survey.survey_start = timeline_utils.past(delta=100) self.survey.survey_end = timeline_utils.future(delta=100) # test for an extension that ends before survey ends self.extension.end_date = self.survey.survey_end - timedelta(1) # active period should be the same as for the survey period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.survey.survey_start) self.assertEquals(period.end, self.survey.survey_end) # test for an extension that starts after survey ends self.extension.end_date = self.survey.survey_end + timedelta(1) # active period should end when the extension ends period = survey_logic.getSurveyActivePeriod(self.survey, self.extension) self.assertEquals(period.start, self.survey.survey_start) self.assertEquals(period.end, self.extension.end_date)