Пример #1
0
    def test_single_vote_systemstate(self):
        """Tests votes handling.

        Create SingleVote model and assert it with SingleVote returned by wrapper.
        """
        state1 = SystemState(year="2010/11")
        state1.save()
        state2 = SystemState(year="2018/19")
        state2.save()
        students = [StudentFactory(), StudentFactory()]
        proposals = [ProposalFactory(name="Pranie"), ProposalFactory(name="Zmywanie")]
        SingleVote.objects.bulk_create([
            SingleVote(state=state1, student=students[0], proposal=proposals[0], value=2),
            SingleVote(state=state1, student=students[1], proposal=proposals[0], value=0),
            SingleVote(state=state1, student=students[0], proposal=proposals[1], value=3),
            SingleVote(state=state1, student=students[1], proposal=proposals[1], value=1),
            SingleVote(state=state2, student=students[0], proposal=proposals[0], value=0),
            SingleVote(
                state=state2, student=students[1], proposal=proposals[0], value=0, correction=1),
            SingleVote(state=state2, student=students[0], proposal=proposals[1], value=3),
            SingleVote(
                state=state2, student=students[1], proposal=proposals[1], value=1, correction=2),
        ])

        self.assertEqual(len(list(self.wrapper.systemstates())), 2)
        res_state2 = self.wrapper.systemstate(state2.id)
        self.assertEqual(res_state2.state_name, str(state2))
        # zero-value votes are ignored
        self.assertEqual(len(list(self.wrapper.single_votes({"state": state1.id}))), 3)
        # one of votes have value = 0, but correction = 1
        self.assertEqual(len(list(self.wrapper.single_votes({"value": 0}))), 1)
Пример #2
0
    def setUp(self):
        self.thesis_owner = EmployeeFactory()

        Thesis.objects.create(title="thesis_vote_0",
                              advisor=self.thesis_owner,
                              kind=0,
                              status=ThesisStatus.BEING_EVALUATED)
        thesis_vote_1 = Thesis.objects.create(
            title="thesis_vote_1",
            advisor=self.thesis_owner,
            kind=0,
            status=ThesisStatus.BEING_EVALUATED)
        thesis_vote_1.students.add(StudentFactory())

        Thesis.objects.create(title="thesis_edit_0",
                              advisor=self.thesis_owner,
                              kind=0,
                              status=ThesisStatus.ACCEPTED)
        Thesis.objects.create(title="thesis_edit_1",
                              advisor=self.thesis_owner,
                              kind=0,
                              status=ThesisStatus.RETURNED_FOR_CORRECTIONS)
        test_edit_2 = Thesis.objects.create(title="thesis_edit_2",
                                            advisor=self.thesis_owner,
                                            kind=0,
                                            status=ThesisStatus.IN_PROGRESS)
        test_edit_2.students.add(StudentFactory())

        settings = ThesesSystemSettings.objects.get()
        settings.num_required_votes = 1
        settings.save()
Пример #3
0
    def setUp(self):
        state1 = SystemState(year="2010/11")
        state1.save()
        state2 = SystemState(year="2018/19")
        state2.save()
        students = [StudentFactory(), StudentFactory()]
        proposals = [
            ProposalFactory(name="Pranie"),
            ProposalFactory(name="Zmywanie")
        ]
        SingleVote.objects.bulk_create([
            SingleVote(state=state1,
                       student=students[0],
                       proposal=proposals[0],
                       value=2),
            SingleVote(state=state1,
                       student=students[1],
                       proposal=proposals[0],
                       value=0),
            SingleVote(state=state1,
                       student=students[0],
                       proposal=proposals[1],
                       value=3),
            SingleVote(state=state1,
                       student=students[1],
                       proposal=proposals[1],
                       value=1),
            SingleVote(state=state2,
                       student=students[0],
                       proposal=proposals[0],
                       value=0),
            SingleVote(state=state2,
                       student=students[1],
                       proposal=proposals[0],
                       value=0,
                       correction=1),
            SingleVote(state=state2,
                       student=students[0],
                       proposal=proposals[1],
                       value=3),
            SingleVote(state=state2,
                       student=students[1],
                       proposal=proposals[1],
                       value=1,
                       correction=2),
        ])
        self.state1 = state1
        self.state2 = state2
        self.students = students
        self.employee = EmployeeFactory()

        self.semester = SemesterFactory()
        self.course_instance = CourseInstanceFactory(offer=proposals[1],
                                                     semester=self.semester)

        self.staff_member = UserFactory(is_staff=True)
Пример #4
0
    def setUpTestData(cls):
        # Student 1 will be voting. Student 2 will be taking part in a
        # correction (his primary vote will already have been saved).
        cls.student1 = StudentFactory()
        cls.student2 = StudentFactory()
        cls.state = SystemState.objects.create(
            year="2011/12",
            semester_winter=SemesterFactory(year="2011/12", type=SemesterChoices.WINTER),
            semester_summer=SemesterFactory(year="2011/12", type=SemesterChoices.SUMMER),
            vote_beg=date(2011, 6, 1),
            vote_end=date(2011, 6, 14),
            winter_correction_beg=date(2011, 9, 7),
            winter_correction_end=date(2011, 9, 13),
            summer_correction_beg=date(2012, 1, 28),
            summer_correction_end=date(2012, 2, 1),
        )

        cls.proposals = [
            ProposalFactory(semester=SemesterChoices.WINTER, status=ProposalStatus.IN_VOTE),
            ProposalFactory(semester=SemesterChoices.WINTER, status=ProposalStatus.IN_VOTE),
            ProposalFactory(semester=SemesterChoices.WINTER, status=ProposalStatus.IN_VOTE),
            ProposalFactory(semester=SemesterChoices.WINTER, status=ProposalStatus.IN_VOTE),
            ProposalFactory(semester=SemesterChoices.SUMMER, status=ProposalStatus.IN_VOTE),
            ProposalFactory(semester=SemesterChoices.SUMMER, status=ProposalStatus.IN_OFFER),
            ProposalFactory(semester=SemesterChoices.UNASSIGNED, status=ProposalStatus.IN_VOTE),
        ]

        # One of the winter proposals is going to be free to vote for (point
        # limit will not apply to it).
        cls.proposals[2].course_type.free_in_vote = True
        cls.proposals[2].course_type.save()

        # We reduce the point limit to 10.
        SystemState.DEFAULT_MAX_POINTS = 10

        # We already save some votes for student2, so he will be ready for
        # correction.
        SingleVote.objects.bulk_create([
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[0], value=3),
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[1], value=0),
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[2], value=2),
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[3], value=2),
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[4], value=3),
            SingleVote(state=cls.state, student=cls.student2, proposal=cls.proposals[6], value=2),
        ])

        # Some of the courses will be opened in the winter semester.
        CourseInstanceFactory(semester=cls.state.semester_winter, offer=cls.proposals[0])
        CourseInstanceFactory(semester=cls.state.semester_winter, offer=cls.proposals[1])
        CourseInstanceFactory(semester=cls.state.semester_winter, offer=cls.proposals[6])
Пример #5
0
    def setUpTestData(cls) -> None:
        s = StudentFactory()
        s.matricula = str(randint(100000, 200000))
        cls.student_user = s.user

        Semester.objects.all().delete()
        cls.semester = Semester(
            visible=True,
            type=Semester.TYPE_WINTER,
            records_opening=datetime.now() - timedelta(days=15),
            records_closing=datetime.now() + timedelta(days=15),
            records_ects_limit_abolition=datetime.now() + timedelta(days=5),
            semester_beginning=datetime.now() + timedelta(days=20),
            semester_ending=datetime.now() + timedelta(days=100))
        cls.semester.full_clean()
        cls.semester.save()
Пример #6
0
    def test_get_followers_when_type_exam_or_test(self):
        students = StudentFactory.create_batch(random.randint(10, 20))
        group = enrollment_factories.GroupFactory()
        for student in students:
            Record.objects.create(student=student, group=group, status=RecordStatus.ENROLLED)
        users = [student.user for student in students]

        event = factories.EventFactory(type=random.choice([Event.TYPE_EXAM, Event.TYPE_TEST]),
                                       interested=users, course=group.course)
Пример #7
0
    def test_student(self):
        """Tests student handling.

        Create Student model and assert it with Student returned by wrapper.
        """

        student1, student2 = StudentFactory(), StudentFactory()
        student1.save()
        student2.save()
        result = list(self.wrapper.students())
        self.assertEqual(len(result), 2)
        res_student = result[0]

        self.assertEqual(res_student.id, student1.id)
        self.assertEqual(res_student.matricula, student1.matricula)
        self.assertEqual(res_student.ects, student1.ects)
        self.assertEqual(res_student.is_active, student1.is_active)
        self.assertEqual(res_student.user.id, student1.user.id)
        self.assertEqual(res_student.user.username, student1.user.username)
        self.assertEqual(res_student.user.first_name, student1.user.first_name)
        self.assertEqual(res_student.user.last_name, student1.user.last_name)
        self.assertEqual(res_student.usos_id, student1.usos_id)
Пример #8
0
    def setUpTestData(cls) -> None:

        cls.MSG_HEADER = 'Wyślij wiadomość do studentów'
        regular_user = StudentFactory()
        cls.regular_user = regular_user.user

        permission = Permission.objects.get(codename='mailto_all_students')
        dean_user = EmployeeFactory()
        dean_user.user.user_permissions.add(permission)
        cls.dean_user = dean_user.user

        from apps.enrollment.courses.tests.factories import SemesterFactory
        summer_semester = SemesterFactory(type=Semester.TYPE_SUMMER)
        summer_semester.full_clean()
Пример #9
0
    def create_users(cls):
        NUM_STUDENTS = 15
        NUM_EMPLOYEES = cls.NUM_BOARD_MEMBERS * 2
        StudentFactory.create_batch(NUM_STUDENTS)
        EmployeeFactory.create_batch(NUM_EMPLOYEES)
        cls.students = list(Student.objects.all())
        cls.employees = list(Employee.objects.all())
        cls.board_group = Group.objects.get(name=THESIS_BOARD_GROUP_NAME)

        cls.staff_user = Employee.objects.all()[0]
        cls.staff_user.user.is_staff = True
        cls.staff_user.user.save()

        cls.board_members = []
        for i in range(cls.NUM_BOARD_MEMBERS):
            member = Employee.objects.all()[i]
            cls.board_members.append(member)
            cls.board_group.user_set.add(member.user)

        cls.rejecter = random.choice(cls.board_members)
        settings = ThesesSystemSettings.objects.get()
        settings.master_rejecter = cls.rejecter
        settings.save()
Пример #10
0
    def setUpClass(cls):
        super().setUpClass()
        cls.group = GroupFactory(limit=2)

        cls.bolek = StudentFactory()
        cls.lolek = StudentFactory()
        cls.tola = StudentFactory()
        cls.reksio = StudentFactory()
        cls.uszatek = StudentFactory()

        T0Times.populate_t0(cls.group.course.semester)

        # Tola and Uszatek are going to belong to the ISIM group.
        cls.isim_role = AuthGroup.objects.create(name='isim')
        cls.tola.user.groups.add(cls.isim_role)
        cls.uszatek.user.groups.add(cls.isim_role)

        GuaranteedSpots.objects.create(group=cls.group,
                                       role=cls.isim_role,
                                       limit=1)

        # For convenience we will store the records opening time in a separate
        # variable. Everyone will be entitled to enroll at this time.
        cls.opening_time = cls.group.course.semester.records_opening
Пример #11
0
    def test_save_student(self):
        """Tests save feature.

        Create Student, get it by wrapper, change it and save it.
        """

        student = StudentFactory()
        [res_student] = list(self.wrapper.students())
        self.assertEqual(res_student.id, student.id)
        res_student.usos_id = 666
        self.wrapper.save(res_student)

        [changed_student] = list(self.wrapper.students())

        self.assertEqual(changed_student.is_active, student.is_active)
        self.assertEqual(changed_student.usos_id, 666)
Пример #12
0
    def test_edit(self):
        thesis_edit_0 = Thesis.objects.get(title="thesis_edit_0")
        thesis_edit_1 = Thesis.objects.get(title="thesis_edit_1")
        thesis_edit_2 = Thesis.objects.get(title="thesis_edit_2")

        form_data_0 = {
            'title': thesis_edit_0.title,
            'advisor': thesis_edit_0.advisor_id,
            'kind': 0,
            'students': [StudentFactory()]
        }
        form_data_1 = {
            'title': thesis_edit_1.title,
            'advisor': thesis_edit_1.advisor_id,
            'kind': 0
        }
        form_data_2 = {
            'title': thesis_edit_2.title,
            'advisor': thesis_edit_2.advisor_id,
            'kind': 0
        }

        form_0 = EditThesisForm(instance=thesis_edit_0,
                                user=self.thesis_owner.user,
                                data=form_data_0)
        form_1 = EditThesisForm(instance=thesis_edit_1,
                                user=self.thesis_owner.user,
                                data=form_data_1)
        form_2 = EditThesisForm(instance=thesis_edit_2,
                                user=self.thesis_owner.user,
                                data=form_data_2)

        form_0.save(commit=True)
        form_1.save(commit=True)
        form_2.save(commit=True)

        self.assertEqual(thesis_edit_0.status, ThesisStatus.IN_PROGRESS.value)
        self.assertEqual(thesis_edit_1.status,
                         ThesisStatus.BEING_EVALUATED.value)
        self.assertEqual(thesis_edit_2.status, ThesisStatus.ACCEPTED.value)
Пример #13
0
    def test_change_program(self):
        """Test changing and removing student's program."""
        p1 = Program.objects.create(name="Informatyka, dzienne I stopnia inżynierskie")
        p2 = Program.objects.create(name="Informatyka, dzienne II stopnia magisterskie")
        student = StudentFactory(program=p1)

        s = self.wrapper.student(id=student.id)
        self.assertEqual(s.program.id, p1.id)

        s.program = api_models.Program(p2.id, p2.name)
        self.wrapper.save(s)
        student.refresh_from_db()
        self.assertEqual(student.program_id, p2.id)

        s = self.wrapper.student(id=student.id)
        s.program = None
        self.wrapper.save(s)
        student.refresh_from_db()
        self.assertIsNone(student.program)
Пример #14
0
    def test_clean__student_cant_add_accepted_event(self):
        student = StudentFactory().user

        event = factories.EventFactory.build(author=student)
        self.assertRaises(ValidationError, event.full_clean)
Пример #15
0
def make_student_with_name(name: str) -> Student:
    return StudentFactory(user__first_name=name, user__last_name="")
Пример #16
0
 def test_pagination(self):
     """Tests pagination handling."""
     StudentFactory.create_batch(210)
     result = list(self.wrapper.students())
     self.assertEqual(len(result), 210)
Пример #17
0
    def test_clean__student_cant_add_test(self):
        student = StudentFactory().user

        event = factories.EventFactory.build(author=student, type=Event.TYPE_TEST)
        self.assertRaises(ValidationError, event.full_clean)