Exemplo n.º 1
0
    def test_only_verified_students_can_enroll(self):
        """
        Verify that only students can enroll for a 'student-only' marked course.
        """
        flush_tables()
        insert_dummy_data()

        course = Course.objects.get(subject=Subject.objects.get(name='Hacking for Beginners'))
        course.student_only = True
        course.active = True
        course.save()

        fac = Faculty.objects.create(name="Faculty of Computer Science")
        fac.save()

        u2 = UserInformation.create('samgroves', '*****@*****.**', 'L33T', 'Samantha', 'Groves')
        u2.user.is_active = True
        u2.user.save()
        u3 = UserInformation.create('sameen', '*****@*****.**', 'Sh00T', 'Sameen', 'Shaw', 's9283457', fac.pk)
        u3.user.is_active = True
        u3.user.save()

        with self.assertRaises(Course.IsNoStudent):
            course.enroll(u2)

        with self.assertRaises(Course.IsNoVerifiedStudent):
            course.enroll(u3)

        u3.studentinformation.verified = True
        u3.save()

        course.enroll(u3.user.userinformation)

        self.assertEqual(course.participants.count(), 1,
                         'More than one participant found, although only one was registered.')
Exemplo n.º 2
0
    def test_remove_enrolled_user(self):
        """
        Verify that deleting a user who is enrolled for a course removes the enrollment.
        """
        flush_tables()
        insert_dummy_data()
        u2 = UserInformation.create('samgroves', '*****@*****.**',
                                    'L33T', 'Samantha', 'Groves')
        u2.user.is_active = True
        u2.user.save()

        course = Course.objects.get(subject=Subject.objects.get(
            name='Hacking for Beginners'))
        course.active = True
        course.save()
        course.enroll(u2)

        self.assertEqual(
            course.participants.count(), 1,
            'There was more than one person enrolled to the course!')
        self.assertEqual(UserInformation.objects.count(), 2, 'Too much users!')

        User.objects.get(username='******').delete()

        self.assertEqual(UserInformation.objects.count(), 1,
                         "The user was not removed!")
        self.assertEqual(
            course.participants.count(), 0,
            'There was more than one person enrolled to the course!')
Exemplo n.º 3
0
    def test_only_verified_students_can_enroll(self):
        """
        Verify that only students can enroll for a 'student-only' marked course.
        """
        flush_tables()
        insert_dummy_data()

        course = Course.objects.get(subject=Subject.objects.get(
            name='Hacking for Beginners'))
        course.student_only = True
        course.active = True
        course.save()

        fac = Faculty.objects.create(name="Faculty of Computer Science")
        fac.save()

        u2 = UserInformation.create('samgroves', '*****@*****.**',
                                    'L33T', 'Samantha', 'Groves')
        u2.user.is_active = True
        u2.user.save()
        u3 = UserInformation.create('sameen', '*****@*****.**', 'Sh00T',
                                    'Sameen', 'Shaw', 's9283457', fac.pk)
        u3.user.is_active = True
        u3.user.save()

        with self.assertRaises(Course.IsNoStudent):
            course.enroll(u2)

        with self.assertRaises(Course.IsNoVerifiedStudent):
            course.enroll(u3)

        u3.studentinformation.verified = True
        u3.save()

        course.enroll(u3.user.userinformation)

        self.assertEqual(
            course.participants.count(), 1,
            'More than one participant found, although only one was registered.'
        )
Exemplo n.º 4
0
def insert_dummy_data():
    u1 = UserInformation.create('hfinch', '*****@*****.**', 'test', 'Harold', 'Finch')
    u1.user.is_active = True
    u1.user.save()

    s1 = Subject.objects.create(
        name='Hacking for Beginners',
        description='Nothing to see here.'
    )
    s1.save()

    c1 = Course.objects.create(
        subject=s1,
        max_participants=1,
    )
    c1.teacher.add(u1)
    c1.save()
Exemplo n.º 5
0
    def test_remove_enrolled_user(self):
        """
        Verify that deleting a user who is enrolled for a course removes the enrollment.
        """
        flush_tables()
        insert_dummy_data()
        u2 = UserInformation.create('samgroves', '*****@*****.**', 'L33T', 'Samantha', 'Groves')
        u2.user.is_active = True
        u2.user.save()

        course = Course.objects.get(subject=Subject.objects.get(name='Hacking for Beginners'))
        course.active = True
        course.save()
        course.enroll(u2)

        self.assertEqual(course.participants.count(), 1, 'There was more than one person enrolled to the course!')
        self.assertEqual(UserInformation.objects.count(), 2, 'Too much users!')

        User.objects.get(username='******').delete()

        self.assertEqual(UserInformation.objects.count(), 1, "The user was not removed!")
        self.assertEqual(course.participants.count(), 0, 'There was more than one person enrolled to the course!')