Beispiel #1
0
    def test_degrees_are_merged(self):
        excel_content = excel_data.create_memory_excel_file(excel_data.test_enrollment_data_degree_merge_filedata)

        success_messages, warnings_test, errors = EnrollmentImporter.process(
            excel_content, self.semester, None, None, test_run=True
        )
        self.assertIn("The import run will create 1 courses/evaluations and 3 users", "".join(success_messages))
        self.assertEqual(errors, {})
        self.assertEqual(
            warnings_test[ImporterWarning.DEGREE],
            [
                'Sheet "MA Belegungen", row 3: The course\'s "Build" degree differs from it\'s degree in a previous row. '
                "Both degrees have been set for the course."
            ],
        )
        self.assertEqual(len(warnings_test), 1)

        success_messages, warnings_no_test, errors = EnrollmentImporter.process(
            excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )
        self.assertIn(
            "Successfully created 1 courses/evaluations, 2 participants and 1 contributors", "".join(success_messages)
        )
        self.assertEqual(errors, {})
        self.assertEqual(warnings_no_test, warnings_test)

        self.assertEqual(Course.objects.all().count(), 1)
        self.assertEqual(Evaluation.objects.all().count(), 1)

        course = Course.objects.get(name_de="Bauen")
        self.assertSetEqual(set(course.degrees.all()), set(Degree.objects.filter(name_de__in=["Master", "Bachelor"])))
Beispiel #2
0
def semester_import(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(semester)

    form = ImportForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        operation = request.POST.get('operation')
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        # extract data from form
        excel_file = form.cleaned_data['excel_file']
        vote_start_date = form.cleaned_data['vote_start_date']
        vote_end_date = form.cleaned_data['vote_end_date']

        test_run = operation == 'test'

        # parse table
        EnrollmentImporter.process(request, excel_file, semester,
                                   vote_start_date, vote_end_date, test_run)
        if test_run:
            return render(request, "staff_import.html",
                          dict(semester=semester, form=form))
        return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_import.html",
                      dict(semester=semester, form=form))
Beispiel #3
0
    def test_existing_course_is_not_recreated_messages(self):
        self.create_existing_course()

        success_messages_test, test_warnings_test, __ = EnrollmentImporter.process(
            self.default_excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=True
        )

        success_messages, warnings, __ = EnrollmentImporter.process(
            self.default_excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )

        self.assertIn(
            "Course Shake (Schütteln) already exists. Course will not be created, instead users are imported into the evaluation of the existing course and any additional degrees are added.",
            warnings[ImporterWarning.EXISTS],
        )
        self.assertListEqual(
            test_warnings_test[ImporterWarning.EXISTS],
            warnings[ImporterWarning.EXISTS],
        )
        self.assertIn(
            "The import run will create 22 courses/evaluations",
            "".join(success_messages_test),
        )
        self.assertIn(
            "Successfully created 22 courses/evaluations",
            "".join(success_messages),
        )
Beispiel #4
0
def semester_import(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(semester)

    form = ImportForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        operation = request.POST.get("operation")
        if operation not in ("test", "import"):
            raise PermissionDenied

        # extract data from form
        excel_file = form.cleaned_data["excel_file"]
        vote_start_date = form.cleaned_data["vote_start_date"]
        vote_end_date = form.cleaned_data["vote_end_date"]

        test_run = operation == "test"

        # parse table
        EnrollmentImporter.process(request, excel_file, semester, vote_start_date, vote_end_date, test_run)
        if test_run:
            return render(request, "staff_import.html", dict(semester=semester, form=form))
        return redirect("staff:semester_view", semester_id)
    else:
        return render(request, "staff_import.html", dict(semester=semester, form=form))
Beispiel #5
0
def semester_import(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(semester)

    form = ImportForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        operation = request.POST.get('operation')
        if operation not in ('test', 'import'):
            raise SuspiciousOperation("Invalid POST operation")

        # extract data from form
        excel_file = form.cleaned_data['excel_file']
        vote_start_date = form.cleaned_data['vote_start_date']
        vote_end_date = form.cleaned_data['vote_end_date']

        test_run = operation == 'test'

        # parse table
        EnrollmentImporter.process(request, excel_file, semester, vote_start_date, vote_end_date, test_run)
        if test_run:
            return render(request, "staff_semester_import.html", dict(semester=semester, form=form))
        return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_semester_import.html", dict(semester=semester, form=form))
Beispiel #6
0
    def test_valid_file_import(self):
        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content, self.semester, None, None, test_run=True)
        self.assertIn(
            "The import run will create 23 courses/evaluations and 23 users:",
            "".join(success_messages))
        # check for one random user instead of for all 23
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})

        old_user_count = UserProfile.objects.all().count()

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content,
            self.semester,
            self.vote_start_datetime,
            self.vote_end_date,
            test_run=False)
        self.assertIn(
            "Successfully created 23 courses/evaluations, 6 students and 17 contributors:",
            "".join(success_messages))
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})

        self.assertEqual(Evaluation.objects.all().count(), 23)
        expected_user_count = old_user_count + 23
        self.assertEqual(UserProfile.objects.all().count(),
                         expected_user_count)
Beispiel #7
0
    def test_invalid_file_error(self):
        with open(self.filename_invalid, "rb") as excel_file:
            excel_content = excel_file.read()

        original_user_count = UserProfile.objects.count()

        __, __, errors_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        __, __, errors_no_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=False)

        self.assertEqual(errors_test, errors_no_test)
        self.assertCountEqual(errors_test[ImporterError.USER], {
            'Sheet "MA Belegungen", row 3: The users\'s data (email: [email protected]) differs from it\'s data in a previous row.',
            'Sheet "MA Belegungen", row 7: Email address is missing.',
            'Sheet "MA Belegungen", row 10: Email address is missing.'})
        self.assertCountEqual(errors_test[ImporterError.COURSE], {
            'Sheet "MA Belegungen", row 18: The German name for course "Bought" already exists for another course.',
            'Sheet "MA Belegungen", row 20: The course\'s "Cost" data differs from it\'s data in a previous row.'})
        self.assertEqual(errors_test[ImporterError.DEGREE_MISSING], [
            'Error: No degree is associated with the import name "Diploma". Please manually create it first.'])
        self.assertEqual(errors_test[ImporterError.COURSE_TYPE_MISSING], [
            'Error: No course type is associated with the import name "Praktikum". Please manually create it first.'])
        self.assertEqual(errors_test[ImporterError.IS_GRADED], [
            '"is_graded" of course Deal is maybe, but must be yes or no'])
        self.assertEqual(errors_test[ImporterError.GENERAL], [
            'Errors occurred while parsing the input data. No data was imported.'])
        self.assertEqual(len(errors_test), 6)
        self.assertEqual(UserProfile.objects.count(), original_user_count)
Beispiel #8
0
    def test_enrollment_importer_high_enrollment_warning(self):
        excel_content = excel_data.create_memory_excel_file(
            excel_data.test_enrollment_data_filedata)

        __, warnings_test, __ = EnrollmentImporter.process(excel_content,
                                                           self.semester,
                                                           None,
                                                           None,
                                                           test_run=True)
        __, warnings_no_test, __ = EnrollmentImporter.process(
            excel_content,
            self.semester,
            self.vote_start_datetime,
            self.vote_end_date,
            test_run=False)

        self.assertEqual(warnings_test, warnings_no_test)
        self.assertCountEqual(
            warnings_test[ImporterWarning.MANY], {
                "Warning: User [email protected] has 6 enrollments, which is a lot.",
                "Warning: User [email protected] has 6 enrollments, which is a lot.",
                "Warning: User [email protected] has 6 enrollments, which is a lot.",
                "Warning: User [email protected] has 6 enrollments, which is a lot.",
                "Warning: User [email protected] has 5 enrollments, which is a lot.",
                "Warning: User [email protected] has 4 enrollments, which is a lot."
            })
Beispiel #9
0
    def test_valid_file_import(self):
        semester = mommy.make(Semester)
        vote_start_datetime = datetime(2017, 1, 10)
        vote_end_date = date(2017, 3, 10)
        mommy.make(CourseType, name_de="Seminar")
        mommy.make(CourseType, name_de="Vorlesung")

        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content, semester, None, None, test_run=True)
        self.assertIn(
            "The import run will create 23 evaluations and 23 users:",
            "".join(success_messages))
        # check for one random user instead of for all 23
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content,
            semester,
            vote_start_datetime,
            vote_end_date,
            test_run=False)
        self.assertIn(
            "Successfully created 23 evaluation(s), 6 student(s) and 17 contributor(s):",
            "".join(success_messages))
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})
Beispiel #10
0
    def test_valid_file_import(self):
        excel_content = excel_data.create_memory_excel_file(excel_data.test_enrollment_data_filedata)

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content, self.semester, None, None, test_run=True
        )
        self.assertIn("The import run will create 23 courses/evaluations and 23 users:", "".join(success_messages))
        # check for one random user instead of for all 23
        self.assertIn("Ferdi Itaque ([email protected])", "".join(success_messages))
        self.assertEqual(errors, {})
        self.assertEqual(warnings, {})

        old_user_count = UserProfile.objects.all().count()

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )
        self.assertIn(
            "Successfully created 23 courses/evaluations, 6 participants and 17 contributors:",
            "".join(success_messages),
        )
        self.assertIn("Ferdi Itaque ([email protected])", "".join(success_messages))
        self.assertEqual(errors, {})
        self.assertEqual(warnings, {})

        self.assertEqual(Evaluation.objects.all().count(), 23)
        expected_user_count = old_user_count + 23
        self.assertEqual(UserProfile.objects.all().count(), expected_user_count)
Beispiel #11
0
    def test_random_file_error(self):
        with open(self.filename_random, "rb") as excel_file:
            excel_content = excel_file.read()

        original_user_count = UserProfile.objects.count()

        __, __, errors_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        __, __, errors_no_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=False)

        self.assertEqual(errors_test, errors_no_test)
        self.assertEqual(errors_test[ImporterError.SCHEMA], [
            "Couldn't read the file. Error: Unsupported format, or corrupt file: Expected BOF record; found b'42\\n'"])
        self.assertEqual(UserProfile.objects.count(), original_user_count)
Beispiel #12
0
    def test_existing_course_degree_is_added(self):
        existing_course, __ = self.create_existing_course()

        # The existing course exactly matches one course in the import data by default. To create a conflict, the degrees are changed
        existing_course.degrees.set([Degree.objects.get(name_de="Master")])

        EnrollmentImporter.process(
            self.default_excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )

        self.assertSetEqual(
            set(existing_course.degrees.all()), set(Degree.objects.filter(name_de__in=["Master", "Bachelor"]))
        )
Beispiel #13
0
    def test_enrollment_importer_high_enrollment_warning(self):
        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        __, warnings_test, __ = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        __, warnings_no_test, __ = EnrollmentImporter.process(excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False)

        self.assertEqual(warnings_test, warnings_no_test)
        warnings_many = warnings_test[EnrollmentImporter.W_MANY]
        self.assertIn("Warning: User [email protected] has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 5 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 4 enrollments, which is a lot.", warnings_many)
Beispiel #14
0
    def test_random_file_error(self):
        with open(self.filename_random, "rb") as excel_file:
            excel_content = excel_file.read()

        original_user_count = UserProfile.objects.count()

        __, __, errors_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        __, __, errors_no_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=False)

        self.assertEqual(errors_test, errors_no_test)
        self.assertEqual(
            errors_test[ImporterError.SCHEMA],
            ["Couldn't read the file. Error: File is not a zip file"],
        )
        self.assertEqual(UserProfile.objects.count(), original_user_count)
Beispiel #15
0
    def test_existing_course_is_not_recreated(self):
        existing_course, existing_course_evaluation = self.create_existing_course(
        )

        old_course_count = Course.objects.count()
        old_dict = model_to_dict(existing_course)
        self.assertFalse(existing_course_evaluation.participants.exists())

        __, warnings, __ = EnrollmentImporter.process(
            self.default_excel_content,
            self.semester,
            self.vote_start_datetime,
            self.vote_end_date,
            test_run=False)

        self.assertIn(
            "Course Shake (Schütteln) already exists. Course will not be created, instead users are imported into the evaluation of the existing course and any additional degrees are added.",
            warnings[ImporterWarning.EXISTS],
        )
        expected_course_count = old_course_count + 22
        self.assertEqual(Course.objects.count(), expected_course_count)
        existing_course.refresh_from_db()
        self.assertEqual(old_dict, model_to_dict(existing_course))
        self.assertIn(
            UserProfile.objects.get(
                email="*****@*****.**"),
            existing_course_evaluation.participants.all(),
        )
Beispiel #16
0
    def test_existing_course_different_attributes(self):
        existing_course, __ = self.create_existing_course()
        existing_course.type = CourseType.objects.get(name_de="Seminar")
        existing_course.responsibles.set([
            baker.make(UserProfile,
                       email="*****@*****.**")
        ])
        existing_course.save()

        old_course_count = Course.objects.count()
        old_dict = model_to_dict(existing_course)

        __, __, errors = EnrollmentImporter.process(self.default_excel_content,
                                                    self.semester,
                                                    self.vote_start_datetime,
                                                    self.vote_end_date,
                                                    test_run=False)

        self.assertIn("the course type does not match",
                      "".join(errors[ImporterError.COURSE]))
        self.assertIn("the responsibles of the course do not match",
                      "".join(errors[ImporterError.COURSE]))
        self.assertEqual(Course.objects.count(), old_course_count)
        existing_course.refresh_from_db()
        self.assertEqual(old_dict, model_to_dict(existing_course))
Beispiel #17
0
    def test_existing_course_equal_except_evaluations(self):
        existing_course, __ = self.create_existing_course()
        baker.make(Evaluation,
                   course=existing_course,
                   name_de="Zweite Evaluation",
                   name_en="Second Evaluation")

        old_course_count = Course.objects.count()
        old_dict = model_to_dict(existing_course)

        __, __, errors = EnrollmentImporter.process(self.default_excel_content,
                                                    self.semester,
                                                    self.vote_start_datetime,
                                                    self.vote_end_date,
                                                    test_run=False)

        self.assertIn(
            "Course Shake (Schütteln) already exists in this semester, but the courses can not be merged for the following reasons:"
            +
            "<br /> - the existing course does not have exactly one evaluation",
            errors[ImporterError.COURSE],
        )
        self.assertEqual(Course.objects.count(), old_course_count)
        existing_course.refresh_from_db()
        self.assertEqual(old_dict, model_to_dict(existing_course))
Beispiel #18
0
    def test_replace_consecutive_and_trailing_spaces(self):
        excel_content = excel_data.create_memory_excel_file(
            excel_data.test_enrollment_data_consecutive_and_trailing_spaces_filedata
        )

        success_messages, __, __ = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        self.assertIn("The import run will create 1 courses/evaluations and 3 users", "".join(success_messages))
Beispiel #19
0
    def test_course_type_and_degrees_are_retrieved_with_import_names(self):
        excel_content = excel_data.create_memory_excel_file(
            excel_data.test_enrollment_data_import_names_filedata)

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content,
            self.semester,
            self.vote_start_datetime,
            self.vote_end_date,
            test_run=False)
        self.assertIn(
            "Successfully created 2 courses/evaluations, 4 students and 2 contributors:",
            "".join(success_messages))
        self.assertEqual(errors, {})
        self.assertEqual(warnings, {})

        self.assertEqual(Course.objects.all().count(), 2)
        course_spelling = Course.objects.get(name_en="Spelling")
        self.assertEqual(course_spelling.type.name_de, "Vorlesung")
        self.assertEqual(
            list(course_spelling.degrees.values_list("name_en", flat=True)),
            ["Bachelor"])
        course_build = Course.objects.get(name_en="Build")
        self.assertEqual(course_build.type.name_de, "Seminar")
        self.assertEqual(
            list(course_build.degrees.values_list("name_en", flat=True)),
            ["Master"])
Beispiel #20
0
    def test_invalid_file_error(self):
        with open(self.filename_invalid, "rb") as excel_file:
            excel_content = excel_file.read()

        original_user_count = UserProfile.objects.count()

        __, __, errors_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=True)
        __, __, errors_no_test = EnrollmentImporter.process(excel_content, self.semester, None, None, test_run=False)

        self.assertEqual(errors_test, errors_no_test)
        self.assertIn('Sheet "MA Belegungen", row 3: The users\'s data (email: [email protected]) differs from it\'s data in a previous row.', errors_test)
        self.assertIn('Sheet "MA Belegungen", row 7: Email address is missing.', errors_test)
        self.assertIn('Sheet "MA Belegungen", row 10: Email address is missing.', errors_test)
        self.assertIn('Sheet "MA Belegungen", row 18: The German name for course "Bought" already exists for another course.', errors_test)
        self.assertIn('Sheet "MA Belegungen", row 20: The course\'s "Cost" data differs from it\'s data in a previous row.', errors_test)
        self.assertIn('Errors occurred while parsing the input data. No data was imported.', errors_test)
        self.assertEqual(UserProfile.objects.count(), original_user_count)
Beispiel #21
0
 def test_errors_are_merged(self):
     excel_content = excel_data.create_memory_excel_file(excel_data.test_enrollment_data_error_merge_filedata)
     __, warnings, errors = EnrollmentImporter.process(
         excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
     )
     self.assertIn("Both degrees have been set for the course", "".join(warnings[ImporterWarning.DEGREE]))
     self.assertIn("is probably not, but must be", "".join(errors[ImporterError.IS_GRADED]))
     self.assertIn("jaminar", "".join(errors[ImporterError.COURSE_TYPE_MISSING]))
     self.assertIn("Beginner", "".join(errors[ImporterError.DEGREE_MISSING]))
     self.assertIn("Grandmaster", "".join(errors[ImporterError.DEGREE_MISSING]))
Beispiel #22
0
    def test_invalid_file_error(self):
        semester = mommy.make(Semester)
        mommy.make(CourseType, name_de="Seminar")
        mommy.make(CourseType, name_de="Vorlesung")
        original_user_count = UserProfile.objects.count()

        with open(self.filename_invalid, "rb") as excel_file:
            excel_content = excel_file.read()

        __, __, errors_test = EnrollmentImporter.process(excel_content,
                                                         semester,
                                                         None,
                                                         None,
                                                         test_run=True)
        __, __, errors_no_test = EnrollmentImporter.process(excel_content,
                                                            semester,
                                                            None,
                                                            None,
                                                            test_run=False)

        self.assertEqual(errors_test, errors_no_test)
        self.assertIn(
            'Sheet "MA Belegungen", row 3: The users\'s data (email: [email protected]) differs from it\'s data in a previous row.',
            errors_test)
        self.assertIn(
            'Sheet "MA Belegungen", row 7: Email address is missing.',
            errors_test)
        self.assertIn(
            'Sheet "MA Belegungen", row 10: Email address is missing.',
            errors_test)
        self.assertIn(
            'Sheet "MA Belegungen", row 18: The German name for evaluation "Bought" already exists for another evaluation.',
            errors_test)
        self.assertIn(
            'Sheet "MA Belegungen", row 20: The evaluation\'s "Cost" data differs from it\'s data in a previous row.',
            errors_test)
        self.assertIn(
            'The imported data contains two email addresses with the same username (\'[email protected]\' and \'[email protected]\').',
            errors_test)
        self.assertIn(
            'Errors occurred while parsing the input data. No data was imported.',
            errors_test)
        self.assertEqual(UserProfile.objects.count(), original_user_count)
Beispiel #23
0
    def test_enrollment_importer_high_enrollment_warning(self):
        semester = mommy.make(Semester)
        vote_start_datetime = datetime(2017, 1, 10)
        vote_end_date = datetime(2017, 3, 10)

        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        __, warnings_test, __ = EnrollmentImporter.process(excel_content, semester, None, None, test_run=True)
        __, warnings_no_test, __ = EnrollmentImporter.process(excel_content, semester, vote_start_datetime, vote_end_date, test_run=False)

        self.assertEqual(warnings_test, warnings_no_test)
        warnings_many = warnings_test[EnrollmentImporter.W_MANY]
        self.assertIn("Warning: User ipsum.lorem has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User lucilia.manilium has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User diam.synephebos has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User torquate.metrodorus has 6 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User latinas.menandri has 5 enrollments, which is a lot.", warnings_many)
        self.assertIn("Warning: User [email protected] has 3 enrollments, which is a lot.", warnings_many)
Beispiel #24
0
 def test_unknown_degree_error(self):
     excel_content = excel_data.create_memory_excel_file(
         excel_data.test_unknown_degree_error_filedata)
     __, __, errors = EnrollmentImporter.process(excel_content,
                                                 baker.make(Semester),
                                                 None,
                                                 None,
                                                 test_run=False)
     missing_degree_errors = errors[ImporterError.DEGREE_MISSING]
     self.assertEqual(len(missing_degree_errors), 1)
     self.assertIn("manually create it first", missing_degree_errors[0])
Beispiel #25
0
 def test_replace_consecutive_and_trailing_spaces(self):
     with open(self.filename_valid_consecutive_and_trailing_spaces,
               "rb") as excel_file:
         excel_content = excel_file.read()
     success_messages, __, __ = EnrollmentImporter.process(excel_content,
                                                           self.semester,
                                                           None,
                                                           None,
                                                           test_run=True)
     self.assertIn(
         "The import run will create 1 courses/evaluations and 3 users",
         "".join(success_messages))
Beispiel #26
0
    def test_valid_file_import(self):
        semester = mommy.make(Semester)
        vote_start_date = datetime(2017, 1, 10)
        vote_end_date = datetime(2017, 3, 10)
        mommy.make(CourseType, name_de="Seminar")
        mommy.make(CourseType, name_de="Vorlesung")

        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        success_messages, warnings, errors = EnrollmentImporter.process(excel_content, semester, None, None, test_run=True)
        self.assertIn("The import run will create 23 courses and 23 users:", "".join(success_messages))
        # check for one random user instead of for all 23
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})

        success_messages, warnings, errors = EnrollmentImporter.process(excel_content, semester, vote_start_date, vote_end_date, test_run=False)
        self.assertIn("Successfully created 23 course(s), 6 student(s) and 17 contributor(s):", "".join(success_messages))
        self.assertIn("Ferdi Itaque (ferdi.itaque)", "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, {})
Beispiel #27
0
    def test_duplicate_course_error(self):
        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        semester = baker.make(Semester)
        baker.make(Course, name_de="Stehlen", name_en="Stehlen", semester=semester)
        baker.make(Course, name_de="Shine", name_en="Shine", semester=semester)

        __, __, errors = EnrollmentImporter.process(excel_content, semester, None, None, test_run=False)

        self.assertCountEqual(errors[ImporterError.COURSE], {
            "Course Stehlen does already exist in this semester.",
            "Course Shine does already exist in this semester."})
Beispiel #28
0
def semester_import(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    form = ImportForm(request.POST or None, request.FILES or None)
    operation = request.POST.get('operation')

    if form.is_valid():
        if operation not in ('test', 'import'):
            raise PermissionDenied

        # extract data from form
        excel_file = form.cleaned_data['excel_file']
        vote_start_date = form.cleaned_data['vote_start_date']
        vote_end_date = form.cleaned_data['vote_end_date']

        test_run = operation == 'test'

        # parse table
        EnrollmentImporter.process(request, excel_file, semester, vote_start_date, vote_end_date, test_run)
        if test_run:
            return render(request, "staff_import.html", dict(semester=semester, form=form))
        return redirect('evap.staff.views.semester_view', semester_id)
    else:
        return render(request, "staff_import.html", dict(semester=semester, form=form))
Beispiel #29
0
    def test_duplicate_course_error(self):
        semester = baker.make(Semester)
        baker.make(Course, name_de="Stehlen", name_en="Stehlen", semester=semester)
        baker.make(Course, name_de="Shine", name_en="Shine", semester=semester)

        __, __, errors = EnrollmentImporter.process(self.default_excel_content, semester, None, None, test_run=False)

        self.assertCountEqual(
            errors[ImporterError.COURSE],
            {
                "Course Shine (EN) already exists in this semester with different german name.",
                "Course Stehlen (DE) already exists in this semester with different english name.",
            },
        )
Beispiel #30
0
    def test_enrollment_importer_high_enrollment_warning(self):
        semester = mommy.make(Semester)
        vote_start_date = datetime.datetime(2017, 1, 10)
        vote_end_date = datetime.datetime(2017, 3, 10)

        with open(self.filename_valid, "rb") as excel_file:
            excel_content = excel_file.read()

        __, warnings_test, __ = EnrollmentImporter.process(excel_content,
                                                           semester,
                                                           None,
                                                           None,
                                                           test_run=True)
        __, warnings_no_test, __ = EnrollmentImporter.process(excel_content,
                                                              semester,
                                                              vote_start_date,
                                                              vote_end_date,
                                                              test_run=False)

        self.assertEqual(warnings_test, warnings_no_test)
        warnings_many = warnings_test[EnrollmentImporter.W_MANY]
        self.assertIn(
            "Warning: User ipsum.lorem has 6 enrollments, which is a lot.",
            warnings_many)
        self.assertIn(
            "Warning: User lucilia.manilium has 6 enrollments, which is a lot.",
            warnings_many)
        self.assertIn(
            "Warning: User diam.synephebos has 6 enrollments, which is a lot.",
            warnings_many)
        self.assertIn(
            "Warning: User torquate.metrodorus has 6 enrollments, which is a lot.",
            warnings_many)
        self.assertIn(
            "Warning: User latinas.menandri has 5 enrollments, which is a lot.",
            warnings_many)
Beispiel #31
0
    def test_degrees_are_merged(self):
        with open(self.filename_valid_degree_merge, "rb") as excel_file:
            excel_content = excel_file.read()

        expected_warnings = defaultdict(list)
        expected_warnings[EnrollmentImporter.W_DEGREE].append(
            'Sheet "MA Belegungen", row 3: The course\'s "Build" degree differs from it\'s degree in a previous row. Both degrees have been set for the course.'
        )

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content, self.semester, None, None, test_run=True)
        self.assertIn(
            "The import run will create 1 courses/evaluations and 3 users",
            "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, expected_warnings)

        success_messages, warnings, errors = EnrollmentImporter.process(
            excel_content,
            self.semester,
            self.vote_start_datetime,
            self.vote_end_date,
            test_run=False)
        self.assertIn(
            "Successfully created 1 courses/evaluations, 2 students and 1 contributors",
            "".join(success_messages))
        self.assertEqual(errors, [])
        self.assertEqual(warnings, expected_warnings)

        self.assertEqual(Course.objects.all().count(), 1)
        self.assertEqual(Evaluation.objects.all().count(), 1)

        course = Course.objects.get(name_de="Bauen")
        self.assertSetEqual(
            set(course.degrees.all()),
            set(Degree.objects.filter(name_de__in=["Master", "Bachelor"])))
Beispiel #32
0
    def test_duplicate_course_error(self):
        excel_content = excel_data.create_memory_excel_file(excel_data.test_enrollment_data_filedata)

        semester = baker.make(Semester)
        baker.make(Course, name_de="Stehlen", name_en="Stehlen", semester=semester)
        baker.make(Course, name_de="Shine", name_en="Shine", semester=semester)

        __, __, errors = EnrollmentImporter.process(excel_content, semester, None, None, test_run=False)

        self.assertCountEqual(
            errors[ImporterError.COURSE],
            {
                "Course Stehlen does already exist in this semester.",
                "Course Shine does already exist in this semester.",
            },
        )
Beispiel #33
0
    def test_existing_course_is_not_recreated(self):
        existing_course, existing_course_evaluation = self.create_existing_course()

        old_course_count = Course.objects.count()
        old_dict = model_to_dict(existing_course)
        self.assertFalse(existing_course_evaluation.participants.exists())

        __, __, __ = EnrollmentImporter.process(
            self.default_excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )

        expected_course_count = old_course_count + 22
        self.assertEqual(Course.objects.count(), expected_course_count)
        existing_course.refresh_from_db()
        self.assertEqual(old_dict, model_to_dict(existing_course))
        self.assertIn(
            UserProfile.objects.get(email="*****@*****.**"),
            existing_course_evaluation.participants.all(),
        )
Beispiel #34
0
    def test_existing_course_different_grading(self):
        existing_course, existing_course_evaluation = self.create_existing_course()
        existing_course_evaluation.wait_for_grade_upload_before_publishing = False
        existing_course_evaluation.save()

        old_course_count = Course.objects.count()
        old_dict = model_to_dict(existing_course)

        __, __, errors = EnrollmentImporter.process(
            self.default_excel_content, self.semester, self.vote_start_datetime, self.vote_end_date, test_run=False
        )

        self.assertIn(
            "Course Shake (Schütteln) already exists in this semester, but the courses can not be merged for the following reasons:"
            + "<br /> - the evaluation of the existing course has a mismatching grading specification",
            errors[ImporterError.COURSE],
        )
        self.assertEqual(Course.objects.count(), old_course_count)
        existing_course.refresh_from_db()
        self.assertEqual(old_dict, model_to_dict(existing_course))