예제 #1
0
 def test_clean(self):
     s2 = Group.objects.create(name="studentgroup2")
     f = CourseAdminForm(
         dict(title="foo",
              group=s2.id,
              faculty_group=self.faculty_group.id,
              add_user='******',
              ))
     f.save(commit=False)
     f.clean()
     f.clean_users_to_remove()
예제 #2
0
    def test_clean_no_group(self):
        f = CourseAdminForm(
            dict(title="foo",
                 faculty_group=self.faculty_group.id,
                 add_user='******')
        )

        with self.assertRaisesRegexp(
                ValueError,
                'The Course could not be created'):
            f.save(commit=False)

        with self.assertRaisesRegexp(
                forms.ValidationError,
                'You must select a group or enter a course string'):
            f.clean()
예제 #3
0
    def test_clean_remove(self):
        f = CourseAdminForm(instance=self.c)
        f.cleaned_data = dict(pk=self.c.id,
                              title="test course",
                              group=self.student_group.id,
                              faculty_group=self.faculty_group.id,
                              add_user='',
                              users_to_remove=[self.faculty, self.student]
                              )
        f.save(commit=False)
        f.clean()
        f.clean_users_to_remove()

        self.assertFalse(self.student_group in self.student.groups.all())

        self.assertFalse(self.student_group in self.faculty.groups.all())
        self.assertFalse(self.faculty_group in self.faculty.groups.all())
예제 #4
0
    def test_clean(self):
        s2 = Group.objects.create(name="studentgroup2")
        f = CourseAdminForm(
            dict(title="foo",
                 group=s2.id,
                 faculty_group=self.faculty_group.id,
                 add_user='******'
                 ))
        f.save(commit=False)
        f.clean()
        f.clean_users_to_remove()

        self.assertTrue(s2 in self.student.groups.all())
        self.assertFalse(self.faculty_group in self.student.groups.all())

        user = User.objects.filter(username='******').first()
        self.assertIsNotNone(user)
        self.assertTrue(s2 in user.groups.all())
        self.assertTrue(self.faculty_group in user.groups.all())