Esempio n. 1
0
    def test_course_change_updates_cache(self):
        semester = baker.make(Semester)
        course1 = baker.make(Course, semester=semester)
        course2 = baker.make(Course, semester=semester)
        evaluation = baker.make(Evaluation, course=course1)
        evaluation.general_contribution.questionnaires.set([baker.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation)
        form = EvaluationForm(form_data, instance=evaluation, semester=semester)
        self.assertTrue(form.is_valid())
        with patch('evap.results.views._delete_course_template_cache_impl') as delete_call, patch('evap.results.views.warm_up_template_cache') as warmup_call:
            # save without changes
            form.save()
            self.assertEqual(Evaluation.objects.get(pk=evaluation.pk).course, course1)
            self.assertEqual(delete_call.call_count, 0)
            self.assertEqual(warmup_call.call_count, 0)

            # change course and save
            form_data = get_form_data_from_instance(EvaluationForm, evaluation)
            form_data["course"] = course2.pk
            form = EvaluationForm(form_data, instance=evaluation, semester=semester)
            self.assertTrue(form.is_valid())
            form.save()
            self.assertEqual(Evaluation.objects.get(pk=evaluation.pk).course, course2)
            self.assertEqual(delete_call.call_count, 2)
            self.assertEqual(warmup_call.call_count, 2)
Esempio n. 2
0
    def test_evaluation_form_same_name(self):
        """
            Test whether giving an evaluation the same name as another evaluation
            in the same course in the evaluation edit form is invalid.
        """
        course = mommy.make(Course, degrees=[mommy.make(Degree)])
        evaluation1 = mommy.make(Evaluation,
                                 course=course,
                                 name_de="Evaluierung 1",
                                 name_en="Evaluation 1")
        evaluation2 = mommy.make(Evaluation,
                                 course=course,
                                 name_de="Evaluierung 2",
                                 name_en="Evaluation 2")
        evaluation1.general_contribution.questionnaires.set(
            [mommy.make(Questionnaire)])
        evaluation2.general_contribution.questionnaires.set(
            [mommy.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation1)
        form_data[
            "vote_start_datetime"] = "2098-01-01"  # needed to fix the form
        form_data["vote_end_date"] = "2099-01-01"  # needed to fix the form

        form = EvaluationForm(form_data,
                              instance=evaluation1,
                              semester=evaluation1.course.semester)
        self.assertTrue(form.is_valid())
        form_data['name_de'] = evaluation2.name_de
        form = EvaluationForm(form_data,
                              instance=evaluation1,
                              semester=evaluation1.course.semester)
        self.assertFalse(form.is_valid())
Esempio n. 3
0
    def test_course_change_updates_cache(self):
        semester = mommy.make(Semester)
        course1 = mommy.make(Course, semester=semester)
        course2 = mommy.make(Course, semester=semester)
        evaluation = mommy.make(Evaluation, course=course1)
        evaluation.general_contribution.questionnaires.set([mommy.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation)
        form = EvaluationForm(form_data, instance=evaluation, semester=semester)
        self.assertTrue(form.is_valid())
        with patch('evap.results.views._delete_course_template_cache_impl') as delete_call, patch('evap.results.views.warm_up_template_cache') as warmup_call:
            # save without changes
            form.save()
            self.assertEqual(Evaluation.objects.get(pk=evaluation.pk).course, course1)
            self.assertEqual(delete_call.call_count, 0)
            self.assertEqual(warmup_call.call_count, 0)

            # change course and save
            form_data = get_form_data_from_instance(EvaluationForm, evaluation)
            form_data["course"] = course2.pk
            form = EvaluationForm(form_data, instance=evaluation, semester=semester)
            self.assertTrue(form.is_valid())
            form.save()
            self.assertEqual(Evaluation.objects.get(pk=evaluation.pk).course, course2)
            self.assertEqual(delete_call.call_count, 2)
            self.assertEqual(warmup_call.call_count, 2)
Esempio n. 4
0
    def test_uniqueness_constraint_error_shown(self):
        """
            Tests whether errors being caused by a uniqueness constraint are shown in the form
        """
        course = mommy.make(Course)
        evaluation1 = mommy.make(Evaluation,
                                 course=course,
                                 name_de="Evaluierung 1",
                                 name_en="Evaluation 1")
        evaluation2 = mommy.make(Evaluation,
                                 course=course,
                                 name_de="Evaluierung 2",
                                 name_en="Evaluation 2")

        form_data = get_form_data_from_instance(EvaluationForm, evaluation2)
        form_data["name_de"] = evaluation1.name_de
        form = EvaluationForm(form_data,
                              instance=evaluation2,
                              semester=evaluation2.course.semester)

        self.assertFalse(form.is_valid())
        self.assertIn('name_de', form.errors)
        self.assertEqual(
            form.errors['name_de'],
            ['Evaluation with this Course and Name (german) already exists.'])
Esempio n. 5
0
    def test_evaluation_form_same_name(self):
        """
            Test whether giving an evaluation the same name as another evaluation
            in the same course in the evaluation edit form is invalid.
        """
        course = mommy.make(Course, degrees=[mommy.make(Degree)])
        evaluation1 = mommy.make(Evaluation, course=course, name_de="Evaluierung 1", name_en="Evaluation 1")
        evaluation2 = mommy.make(Evaluation, course=course, name_de="Evaluierung 2", name_en="Evaluation 2")
        evaluation1.general_contribution.questionnaires.set([mommy.make(Questionnaire)])
        evaluation2.general_contribution.questionnaires.set([mommy.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation1)
        form_data["vote_start_datetime"] = "2098-01-01"  # needed to fix the form
        form_data["vote_end_date"] = "2099-01-01"  # needed to fix the form

        form = EvaluationForm(form_data, instance=evaluation1, semester=evaluation1.course.semester)
        self.assertTrue(form.is_valid())
        form_data['name_de'] = evaluation2.name_de
        form = EvaluationForm(form_data, instance=evaluation1, semester=evaluation1.course.semester)
        self.assertFalse(form.is_valid())
Esempio n. 6
0
    def test_voter_cannot_be_removed_from_evaluation(self):
        student = baker.make(UserProfile)
        evaluation = baker.make(Evaluation, course=baker.make(Course, degrees=[baker.make(Degree)]), participants=[student], voters=[student])
        evaluation.general_contribution.questionnaires.set([baker.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation)
        form_data["participants"] = []
        form = EvaluationForm(form_data, instance=evaluation, semester=evaluation.course.semester)

        self.assertFalse(form.is_valid())
        self.assertIn('participants', form.errors)
        self.assertIn("Participants who already voted for the evaluation can't be removed", form.errors['participants'][0])
Esempio n. 7
0
    def helper_date_validation(self, EvaluationFormClass, start_date, end_date, expected_result):
        evaluation = Evaluation.objects.get()

        form_data = get_form_data_from_instance(EvaluationFormClass, evaluation)
        form_data["vote_start_datetime"] = start_date
        form_data["vote_end_date"] = end_date

        if EvaluationFormClass == EvaluationForm:
            form = EvaluationForm(form_data, instance=evaluation, semester=evaluation.course.semester)
        else:
            form = EvaluationFormClass(form_data, instance=evaluation)
        self.assertEqual(form.is_valid(), expected_result)
Esempio n. 8
0
    def test_voter_cannot_be_removed_from_evaluation(self):
        student = mommy.make(UserProfile)
        evaluation = mommy.make(Evaluation, course=mommy.make(Course, degrees=[mommy.make(Degree)]), participants=[student], voters=[student])
        evaluation.general_contribution.questionnaires.set([mommy.make(Questionnaire)])

        form_data = get_form_data_from_instance(EvaluationForm, evaluation)
        form_data["participants"] = []
        form = EvaluationForm(form_data, instance=evaluation, semester=evaluation.course.semester)

        self.assertFalse(form.is_valid())
        self.assertIn('participants', form.errors)
        self.assertIn("Participants who already voted for the evaluation can't be removed", form.errors['participants'][0])
Esempio n. 9
0
    def helper_date_validation(self, EvaluationFormClass, start_date, end_date, expected_result):
        evaluation = Evaluation.objects.get()

        form_data = get_form_data_from_instance(EvaluationFormClass, evaluation)
        form_data["vote_start_datetime"] = start_date
        form_data["vote_end_date"] = end_date

        if EvaluationFormClass == EvaluationForm:
            form = EvaluationForm(form_data, instance=evaluation, semester=evaluation.course.semester)
        else:
            form = EvaluationFormClass(form_data, instance=evaluation)
        self.assertEqual(form.is_valid(), expected_result)
Esempio n. 10
0
    def test_uniqueness_constraint_error_shown(self):
        """
            Tests whether errors being caused by a uniqueness constraint are shown in the form
        """
        course = mommy.make(Course)
        evaluation1 = mommy.make(Evaluation, course=course, name_de="Evaluierung 1", name_en="Evaluation 1")
        evaluation2 = mommy.make(Evaluation, course=course, name_de="Evaluierung 2", name_en="Evaluation 2")

        form_data = get_form_data_from_instance(EvaluationForm, evaluation2)
        form_data["name_de"] = evaluation1.name_de
        form = EvaluationForm(form_data, instance=evaluation2, semester=evaluation2.course.semester)

        self.assertFalse(form.is_valid())
        self.assertIn('name_de', form.errors)
        self.assertEqual(form.errors['name_de'], ['Evaluation with this Course and Name (german) already exists.'])