Beispiel #1
0
    def test_after_clean_new_test_is_public(self):
        test = factories.EventFactory(type=Event.TYPE_TEST)

        employee = EmployeeFactory(user=test.author)
        employee.full_clean()
        test.full_clean()
        self.assertTrue(test.visible)
Beispiel #2
0
    def test_new_exam_after_clean_is_public(self):
        exam = factories.EventFactory(type=Event.TYPE_EXAM)

        employee = EmployeeFactory(user=exam.author)
        employee.full_clean()
        exam.full_clean()
        self.assertTrue(exam.visible)
    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)
Beispiel #4
0
    def test_vote(self):
        thesis_vote_0 = Thesis.objects.get(title="thesis_vote_0")
        thesis_vote_1 = Thesis.objects.get(title="thesis_vote_1")

        vote_0 = Vote.objects.create(owner=EmployeeFactory(),
                                     vote=ThesisVote.ACCEPTED,
                                     thesis=thesis_vote_0)
        vote_1 = Vote.objects.create(owner=EmployeeFactory(),
                                     vote=ThesisVote.ACCEPTED,
                                     thesis=thesis_vote_1)

        change_status(thesis_vote_0, vote_0.vote)
        change_status(thesis_vote_1, vote_1.vote)

        self.assertEqual(thesis_vote_0.status, ThesisStatus.ACCEPTED)
        self.assertEqual(thesis_vote_1.status, ThesisStatus.IN_PROGRESS)
Beispiel #5
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()
    def setUpTestData(cls):
        cls.employee = EmployeeFactory()

        # We need to have one course type in database.
        cls.course_type = CourseType.objects.create(
            name="I2.Z - zastosowania inf.",
            short_name="I2.Z",
            default_ects=6,
        )
Beispiel #7
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()
Beispiel #8
0
    def test_employee(self):
        """Tests employee handling.

        Create employee model and assert it with employee returned by wrapper.
        """
        employee = EmployeeFactory()
        [res_employee] = list(self.wrapper.employees())

        self.assertEqual(employee.id, res_employee.id)
        self.assertEqual(employee.consultations, res_employee.consultations)
        self.assertEqual(employee.homepage, res_employee.homepage)
        self.assertEqual(employee.room, res_employee.room)
        self.assertEqual(employee.title, res_employee.title)
        self.assertEqual(employee.usos_id, res_employee.usos_id)
Beispiel #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()
Beispiel #10
0
    def setUpTestData(cls):
        cls.employee = EmployeeFactory()

        # We need to have one course type in database.
        cls.course_type = CourseType.objects.create(
            name="I2.Z - zastosowania inf.",
            short_name="I2.Z",
            default_ects=6,
        )

        # This form data will be used across tests.
        cls.form_data = {
            'name':
            "Szydełkowanie",
            'language':
            'pl',
            'semester':
            'u',
            'course_type':
            cls.course_type.pk,
            'has_exam':
            True,
            'recommended_for_first_year':
            True,
            'hours_lecture':
            30,
            'hours_exercise':
            30,
            'hours_lab':
            0,
            'hours_exercise_lab':
            0,
            'hours_seminar':
            0,
            'hours_recap':
            15,
            'objectives':
            ("Celami przedmiotu jest zapoznanie studentów z technikami "
             "szydełkowania oraz nauczenie ich cierpliwości niezbędnej "
             "do wykonywania tej czynności."),
            'contents':
            ("1. Różnice między szydełkowaniem i robieniem na drutach.\n"
             "2. Podstawowe wzory szydełkowe."),
            'literature':
            "* Wildman, Emily. _Step-By-Step Crochet_, 1972\n",
            'status':
            ProposalStatus.PROPOSAL,
        }
        cls.semester = SemesterFactory()
Beispiel #11
0
    def setUp(self):
        employee = EmployeeFactory()
        teacher = employee.user
        teacher.full_clean()
        teacher.save()
        employee.save()

        self.event = factories.EventFactory(author=teacher)
        self.event.full_clean()

        room110 = enrollment_factories.ClassroomFactory(number='110')
        room110.full_clean()

        term_1 = factories.TermFixedDayFactory(event=self.event, room=room110)
        term_1.full_clean()

        term_2 = factories.TermFixedDayFactory(event=self.event, start=time(16), end=time(17),
                                               room=room110)
        term_2.full_clean()

        u = factories.UserFactory()
        u.full_clean()

        self.users = [u, teacher]
Beispiel #12
0
    def test_teacher_changed(self):
        teacher = EmployeeFactory()
        group = GroupFactory()
        mail.outbox = []

        teacher_changed.send(sender=Group, instance=group)

        ctx = {
            'content':
            render_description(
                NotificationType.ASSIGNED_TO_NEW_GROUP_AS_A_TEACHER,
                {"course_name": group.course.name}),
            'greeting':
            f'Dzień dobry, {teacher.user.first_name}',
        }
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].body,
            strip_tags(render_to_string('notifications/email_base.html', ctx)))
Beispiel #13
0
class VoteSystemTests(TestCase):
    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)

    def test_authorisation(self):
        """Tests API permissions.

        Checks that an unauthorised caller or a student is not able to perform
        API calls.
        """
        client = APIClient()
        response = client.get('/api/v1/systemstate/')
        self.assertEqual(response.status_code, 401)

        client.force_authenticate(user=self.students[0].user)
        response = client.get('/api/v1/systemstate/')
        self.assertEqual(response.status_code, 403)

    def test_system_states_endpoint(self):
        """Tests system state api.

        Queries the api with two SystemState instances using HTTP client.
        Check if content is JSON and contains expected data.
        There were no states in db, so we get only states created in setUp
        """
        client = APIClient()
        client.force_authenticate(user=self.staff_member)
        response = client.get('/api/v1/systemstate/')
        self.assertEqual(response.status_code, 200)
        resp_json = json.loads(json.dumps(response.data))
        self.assertEqual(len(resp_json), 2)
        self.assertEqual(
            resp_json[0], {
                "id": self.state1.pk,
                "state_name": "Ustawienia systemu na rok akademicki 2010/11"
            })
        self.assertEqual(
            resp_json[1], {
                "id": self.state2.pk,
                "state_name": "Ustawienia systemu na rok akademicki 2018/19"
            })

    def test_votes_endpoint(self):
        """Tests votes endpoint.

        Checks, that only votes with value in a requested System State are
        returned and their values are computed correctly.
        """
        client = APIClient()
        client.force_authenticate(user=self.staff_member)
        response = client.get('/api/v1/votes/', {'state': self.state2.pk},
                              format='json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['results']), 3)
        self.assertCountEqual(response.data['results'],
                              [{
                                  'student': self.students[1].pk,
                                  'course_name': "Pranie",
                                  'vote_points': 1
                              }, {
                                  'student': self.students[0].pk,
                                  'course_name': "Zmywanie",
                                  'vote_points': 3
                              }, {
                                  'student': self.students[1].pk,
                                  'course_name': "Zmywanie",
                                  'vote_points': 2
                              }])

    def test_can_set_semester_usos_kod(self):
        """Tests semester endpoint.

        Checks that the user is able to set/modify the `usos_kod` field of a
        semester.
        """
        client = APIClient()
        client.force_authenticate(user=self.staff_member)
        semester_list_response = client.get('/api/v1/semesters/')
        self.assertEqual(semester_list_response.data,
                         [{
                             'id': self.semester.pk,
                             'display_name': self.semester.get_name(),
                             'usos_kod': None,
                         }])

        semester_change_response = client.patch(
            f'/api/v1/semesters/{self.semester.pk}/',
            {'usos_kod': 'Nowy Kod USOS'})
        self.assertEqual(semester_change_response.status_code, 200)
        self.assertDictEqual(
            semester_change_response.data, {
                'id': self.semester.pk,
                'display_name': self.semester.get_name(),
                'usos_kod': 'Nowy Kod USOS',
            })
        self.semester.refresh_from_db()
        self.assertEqual(self.semester.usos_kod, 'Nowy Kod USOS')

    def test_can_set_course_usos_kod(self):
        """Tests course endpoint.

        Checks that the user is able to set/modify the `usos_kod` field of a
        CourseInstance object.
        """
        client = APIClient()
        client.force_authenticate(user=self.staff_member)

        response = client.get(f'/api/v1/courses/?semester={self.semester.pk}')
        self.assertEqual(response.data['count'], 1)
        course_dict = response.data['results'][0]
        self.assertEqual(course_dict['name'], self.course_instance.name)
        self.assertEqual(course_dict['usos_kod'], '')

        response = client.patch(f'/api/v1/courses/{self.course_instance.id}/',
                                {
                                    'usos_kod': '12-SM-ZMYWANIE',
                                })
        self.assertEqual(response.status_code, 200)
        self.course_instance.refresh_from_db()
        self.assertEqual(self.course_instance.usos_kod, '12-SM-ZMYWANIE')

    def test_set_employee_consultations_permissions(self):
        """Tests employee endpoint permissions.

        Checks that the user is able to modify the `usos_id` field but is not
        able to set/modify the `consultations` field of an employee.

        The REST API does not explicitly forbid these requests. It just does not
        change the field if it should not be changed.
        """
        client = APIClient()
        client.force_authenticate(user=self.staff_member)

        response = client.patch(f'/api/v1/employees/{self.employee.pk}/',
                                {'usos_id': 17})
        self.assertEqual(response.status_code, 200)
        self.employee.refresh_from_db()

        response = client.patch(f'/api/v1/employees/{self.employee.pk}/',
                                {'consultations': "Wtorek godz. 17"})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['consultations'], None)
        self.employee.refresh_from_db()
        self.assertNotEqual(self.employee.consultations, "Wtorek godz. 17")
Beispiel #14
0
def make_employee_with_name(name: str) -> Employee:
    return EmployeeFactory(user__first_name=name, user__last_name="")
Beispiel #15
0
    def test_clean__employee_can_add_accepted_event(self):
        employee = EmployeeFactory().user

        event = factories.EventFactory.build(author=employee)
        event.full_clean()
Beispiel #16
0
    def test_clean__employee_can_add_test(self):
        employee = EmployeeFactory().user

        event = factories.EventFactory.build(author=employee, type=Event.TYPE_TEST)
        event.full_clean()