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 #2
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])
Beispiel #3
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 #4
0
    def test_single_record(self):
        """Tests wrapper method that returns single objects instead of iterator.

        Create Semester model and assert it with Semester returned by wrapper
        """

        semester = SemesterFactory()
        res_semester = self.wrapper.semester(semester.id)

        self.assertEqual(res_semester.id, semester.id)
        self.assertEqual(res_semester.display_name, semester.get_name())
        self.assertEqual(res_semester.year, semester.year)
        self.assertEqual(res_semester.type, semester.type)
        self.assertEqual(res_semester.usos_kod, semester.usos_kod)
Beispiel #5
0
    def test_semester(self):
        """Tests semester handling.

        Create Semester model and assert it with Semester returned by wrapper
        """
        semester = SemesterFactory()
        result = list(self.wrapper.semesters())
        self.assertEqual(len(result), 1)
        res_semester = result[0]
        self.assertEqual(res_semester.id, semester.id)
        self.assertEqual(res_semester.display_name, semester.get_name())
        self.assertEqual(res_semester.year, semester.year)
        self.assertEqual(res_semester.type, semester.type)
        self.assertEqual(res_semester.usos_kod, semester.usos_kod)
Beispiel #6
0
    def test_current_semester_None(self):
        """Tests current semester handling.

        Create Semester model that is no current
        and check if result from wrapper is None.
        """
        SemesterFactory()
        res_semester = self.wrapper.current_semester()

        self.assertEqual(res_semester, None)
Beispiel #7
0
    def test_current_semester(self):
        """Tests current semester handling.

        Create Semester modelwith current date
        and assert it with result from wrapper
        """
        semester = SemesterFactory(semester_beginning=datetime.now().date(),
                                   semester_ending=datetime.now().date())
        res_semester = self.wrapper.current_semester()

        self.assertEqual(res_semester.id, semester.id)
Beispiel #8
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()
    def setUpTestData(cls):
        # Our semester is only going to take place in May 2019.
        cls.semester = SemesterFactory(lectures_beginning=date(2019, 5, 1),
                                       lectures_ending=date(2019, 5, 31))
        # We change one Thursday to Friday and one Friday to Thursday.
        ChangedDay.objects.create(day=date(2019, 5, 16), weekday=common.FRIDAY)
        ChangedDay.objects.create(day=date(2019, 5, 17),
                                  weekday=common.THURSDAY)
        # One Thursday is going to be free.
        Freeday.objects.create(day=date(2019, 5, 9))

        # There is going to be one course only.
        course = CourseInstanceFactory(semester=cls.semester)
        cls.group = GroupFactory(course=course)

        cls.classrooms = [ClassroomFactory(), ClassroomFactory()]
Beispiel #10
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")