예제 #1
0
def check_survey_required_and_unanswered(user, course_descriptor):
    """
    Checks whether a user is required to answer the survey and has yet to do so.

    Returns:
        AccessResponse: Either ACCESS_GRANTED or SurveyRequiredAccessError.
    """

    if not is_survey_required_for_course(course_descriptor):
        return ACCESS_GRANTED

    # anonymous users do not need to answer the survey
    if user.is_anonymous:
        return ACCESS_GRANTED

    # course staff do not need to answer survey
    has_staff_access = has_access(user, 'staff', course_descriptor)
    if has_staff_access:
        return ACCESS_GRANTED

    # survey is required and it exists, let's see if user has answered the survey
    survey = SurveyForm.get(course_descriptor.course_survey_name)
    answered_survey = SurveyAnswer.do_survey_answers_exist(survey, user)
    if answered_survey:
        return ACCESS_GRANTED

    return SurveyRequiredAccessError()
    def test_retire_user_not_exist(self):
        survey = self._create_test_survey()
        assert survey is not None

        survey.save_user_answers(self.student, self.student_answers,
                                 self.course_id)

        retire_result = SurveyAnswer.retire_user(self.student2.id)
        assert not retire_result
        answers = survey.get_answers(self.student)
        assert answers[self.student.id] == self.student_answers
예제 #3
0
    def test_retire_user_not_exist(self):
        survey = self._create_test_survey()
        self.assertIsNotNone(survey)

        survey.save_user_answers(self.student, self.student_answers,
                                 self.course_id)

        retire_result = SurveyAnswer.retire_user(self.student2.id)
        self.assertFalse(retire_result)
        answers = survey.get_answers(self.student)
        self.assertEqual(answers[self.student.id], self.student_answers)
    def test_retire_user_successful(self):
        survey = self._create_test_survey()
        assert survey is not None

        survey.save_user_answers(self.student, self.student_answers,
                                 self.course_id)
        survey.save_user_answers(self.student2, self.student2_answers,
                                 self.course_id)

        retire_result = SurveyAnswer.retire_user(self.student.id)
        assert retire_result
        answers = survey.get_answers(self.student)
        blanked_out_student_answser = {key: '' for key in self.student_answers}
        assert answers[self.student.id] == blanked_out_student_answser
        assert survey.get_answers(
            self.student2)[self.student2.id] == self.student2_answers
예제 #5
0
    def test_retire_user_successful(self):
        survey = self._create_test_survey()
        self.assertIsNotNone(survey)

        survey.save_user_answers(self.student, self.student_answers,
                                 self.course_id)
        survey.save_user_answers(self.student2, self.student2_answers,
                                 self.course_id)

        retire_result = SurveyAnswer.retire_user(self.student.id)
        self.assertTrue(retire_result)
        answers = survey.get_answers(self.student)
        blanked_out_student_answser = {key: '' for key in self.student_answers}
        self.assertEqual(answers[self.student.id], blanked_out_student_answser)
        self.assertEqual(
            survey.get_answers(self.student2)[self.student2.id],
            self.student2_answers)
def _listen_for_lms_retire(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Listener for the USER_RETIRE_LMS_MISC signal, just does the SurveyAnswer retirement
    """
    user = kwargs.get('user')
    SurveyAnswer.retire_user(user.id)