예제 #1
0
 def test_send_accept_mail(self):
     assignment = mommy.make(
         'core.Assignment',
         long_name='Assignment 1',
         short_name='assignment1',
         parentnode__long_name='Spring2017',
         parentnode__short_name='s17',
         parentnode__parentnode__long_name=
         'DUCK1010 - Object Oriented Programming',
         parentnode__parentnode__short_name='Duck1010',
         students_can_create_groups=True,
     )
     testgroup = mommy.make('core.AssignmentGroup', parentnode=assignment)
     testgroup1 = mommy.make('core.AssignmentGroup', parentnode=assignment)
     sent_by = core_mommy.candidate(testgroup,
                                    shortname="*****@*****.**",
                                    fullname="April").relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1,
                                    shortname="*****@*****.**",
                                    fullname="Dewey").relatedstudent.user
     mommy.make('devilry_account.UserEmail',
                user=sent_to,
                email="*****@*****.**")
     mommy.make('devilry_account.UserEmail',
                user=sent_by,
                email="*****@*****.**")
     invite = GroupInvite(group=testgroup, sent_by=sent_by, sent_to=sent_to)
     invite.full_clean()
     invite.save()
     invite.send_invite_notification(self.__fake_request())
     invite.respond(True)
     self.assertEqual(len(mail.outbox), 2)
     self.assertEqual(mail.outbox[1].subject,
                      '[Devilry] Dewey accepted your project group invite')
예제 #2
0
 def test_send_accept_mail(self):
     assignment = mommy.make(
         'core.Assignment',
         long_name='Assignment 1',
         short_name='assignment1',
         parentnode__long_name='Spring2017',
         parentnode__short_name='s17',
         parentnode__parentnode__long_name='DUCK1010 - Object Oriented Programming',
         parentnode__parentnode__short_name='Duck1010',
         students_can_create_groups=True,
     )
     testgroup = mommy.make('core.AssignmentGroup', parentnode=assignment)
     testgroup1 = mommy.make('core.AssignmentGroup', parentnode=assignment)
     sent_by = core_mommy.candidate(testgroup, shortname="*****@*****.**", fullname="April").relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1, shortname="*****@*****.**", fullname="Dewey").relatedstudent.user
     mommy.make('devilry_account.UserEmail', user=sent_to, email="*****@*****.**")
     mommy.make('devilry_account.UserEmail', user=sent_by, email="*****@*****.**")
     invite = GroupInvite(
         group=testgroup,
         sent_by=sent_by,
         sent_to=sent_to
     )
     invite.full_clean()
     invite.save()
     invite.send_invite_notification(self.__fake_request())
     invite.respond(True)
     self.assertEqual(len(mail.outbox), 2)
     self.assertEqual(mail.outbox[1].subject, '[Devilry] Dewey accepted your project group invite')
예제 #3
0
 def test_send_invite_mail(self):
     assignment = mommy.make(
         'core.Assignment',
         long_name='Assignment 1',
         short_name='assignment1',
         parentnode__long_name='Spring2017',
         parentnode__short_name='s17',
         parentnode__parentnode__long_name='DUCK1010 - Object Oriented Programming',
         parentnode__parentnode__short_name='Duck1010',
         students_can_create_groups=True,
     )
     testgroup = mommy.make('core.AssignmentGroup', parentnode=assignment)
     testgroup1 = mommy.make('core.AssignmentGroup', parentnode=assignment)
     sent_by = core_mommy.candidate(testgroup, shortname="*****@*****.**", fullname="April").relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1, shortname="*****@*****.**", fullname="Dewey").relatedstudent.user
     mommy.make('devilry_account.UserEmail', user=sent_to, email="*****@*****.**")
     invite = GroupInvite(group=testgroup, sent_by=sent_by, sent_to=sent_to)
     invite.full_clean()
     invite.save()
     request = self.__fake_request()
     invite.send_invite_notification(request)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject, '[Devilry] Project group invite for Duck1010.s17.assignment1')
     url = request.build_absolute_uri(
         reverse('devilry_student_groupinvite_respond', kwargs={'invite_id': invite.id}))
     self.assertIn(url, mail.outbox[0].body)
 def clean(self):
     cleaned_data = super(CreateForm, self).clean()
     sent_to_userid = cleaned_data.get('sent_to')
     if sent_to_userid:
         sent_to = GroupInvite.send_invite_to_choices_queryset(self.group).get(id=sent_to_userid)
         invite = GroupInvite(group=self.group, sent_by=self.sent_by, sent_to=sent_to)
         invite.full_clean()
         self.cleaned_invite = invite
     return cleaned_data
 def test_invited_student_must_be_relatedstudent(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_assignment('assignment1',
             students_can_create_groups=True)\
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(
         group=group,
         sent_by=self.testuser1,
         sent_to=self.testuser2)
     with self.assertRaisesRegexp(ValidationError,
             r'^.*The invited student is not registered on this subject.*$'):
         invite.full_clean()
예제 #6
0
    def test_student_already_member_of_the_group(self):
        testgroup = mommy.make('core.AssignmentGroup')
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The student is already a member of the group.'):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
예제 #7
0
 def test_sanity(self):
     testgroup = mommy.make('core.AssignmentGroup',
                            parentnode__students_can_create_groups=True)
     testgroup1 = mommy.make('core.AssignmentGroup',
                             parentnode=testgroup.parentnode)
     sent_by = core_mommy.candidate(testgroup).relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
     invite = GroupInvite(group=testgroup, sent_by=sent_by, sent_to=sent_to)
     invite.full_clean()
     self.assertEqual(invite.sent_to, sent_to)
     self.assertEqual(invite.sent_by, sent_by)
     self.assertEqual(invite.group, testgroup)
     self.assertIsNotNone(invite.sent_datetime)
 def test_only_when_allowed_on_assignment(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_relatedstudents(self.testuser2)\
         .add_assignment('assignment1',
             students_can_create_groups=False)\
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(
         group=group,
         sent_by=self.testuser1,
         sent_to=self.testuser2)
     with self.assertRaisesRegexp(ValidationError,
             r'^.*This assignment does not allow students to form project groups on their own.*$'):
         invite.full_clean()
예제 #9
0
 def test_invited_student_must_be_relatedstudent(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active() \
         .add_assignment('assignment1',
                         students_can_create_groups=True) \
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(group=group,
                          sent_by=self.testuser1,
                          sent_to=self.testuser2)
     with self.assertRaisesRegexp(
             ValidationError,
             r'^.*The invited student is not registered on this subject.*$'
     ):
         invite.full_clean()
예제 #10
0
 def clean(self):
     cleaned_data = super(CreateForm, self).clean()
     sent_to_candidate_id = cleaned_data.get('sent_to')
     if sent_to_candidate_id:
         try:
             sent_to = GroupInvite.validate_candidate_id_sent_to(self.group, sent_to_candidate_id)
         except ValidationError as e:
             self.cleaned_invite = None
         else:
             invite = GroupInvite(group=self.group, sent_by=self.sent_by, sent_to=sent_to)
             invite.full_clean()
             self.cleaned_invite = invite
     return cleaned_data
 def test_students_can_not_create_groups_after(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_relatedstudents(self.testuser2)\
         .add_assignment('assignment1',
             students_can_not_create_groups_after=DateTimeBuilder.now().minus(days=1),
             students_can_create_groups=True)\
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(
         group=group,
         sent_by=self.testuser1,
         sent_to=self.testuser2)
     with self.assertRaisesRegexp(ValidationError,
             r'^.*Creating project groups without administrator approval is not allowed on this assignment anymore.*$'):
         invite.full_clean()
예제 #12
0
    def test_student_already_member_of_the_group(self):
        testgroup = mommy.make('core.AssignmentGroup')
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The student is already a member of the group.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #13
0
 def test_only_when_allowed_on_assignment(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active() \
         .add_relatedstudents(self.testuser2) \
         .add_assignment('assignment1',
                         students_can_create_groups=False) \
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(group=group,
                          sent_by=self.testuser1,
                          sent_to=self.testuser2)
     with self.assertRaisesRegexp(
             ValidationError,
             r'^.*This assignment does not allow students to form '
             r'project groups on their own.*$'):
         invite.full_clean()
예제 #14
0
    def test_student_sent_to_is_not_registerd_on_assignment(self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup')
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The invited student is not registered on this assignment.'):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
 def test_create_sanity(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_relatedstudents(self.testuser2)\
         .add_assignment('assignment1',
             students_can_create_groups=True)\
         .add_group(students=[self.testuser1]).group
     before = datetime.now()
     invite = GroupInvite(
         group=group,
         sent_by=self.testuser1,
         sent_to=self.testuser2)
     invite.full_clean()
     invite.save()
     after = datetime.now()
     self.assertTrue(invite.sent_datetime >= before and invite.sent_datetime <= after)
예제 #16
0
 def test_create_sanity(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active() \
         .add_relatedstudents(self.testuser2) \
         .add_assignment('assignment1',
                         students_can_create_groups=True) \
         .add_group(students=[self.testuser1]).group
     before = datetime.now()
     invite = GroupInvite(group=group,
                          sent_by=self.testuser1,
                          sent_to=self.testuser2)
     invite.full_clean()
     invite.save()
     after = datetime.now()
     self.assertTrue(invite.sent_datetime >= before
                     and invite.sent_datetime <= after)
예제 #17
0
    def test_student_sent_to_is_not_registerd_on_assignment(self):
        testgroup = mommy.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup')
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The invited student is not registered on this assignment.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #18
0
 def test_students_can_not_create_groups_after(self):
     group = PeriodBuilder.quickadd_ducku_duck1010_active() \
         .add_relatedstudents(self.testuser2) \
         .add_assignment('assignment1',
                         students_can_not_create_groups_after=DateTimeBuilder.now().minus(days=1),
                         students_can_create_groups=True) \
         .add_group(students=[self.testuser1]).group
     invite = GroupInvite(group=group,
                          sent_by=self.testuser1,
                          sent_to=self.testuser2)
     with self.assertRaisesRegexp(
             ValidationError,
             r'^.*Creating project groups without administrator approval is '
             r'not allowed on this assignment anymore.*$'):
         invite.full_clean()
예제 #19
0
 def test_sanity(self):
     testgroup = mommy.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
     testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
     sent_by = core_mommy.candidate(testgroup).relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
     invite = GroupInvite(
         group=testgroup,
         sent_by=sent_by,
         sent_to=sent_to
     )
     invite.full_clean()
     self.assertEqual(invite.sent_to, sent_to)
     self.assertEqual(invite.sent_by, sent_by)
     self.assertEqual(invite.group, testgroup)
     self.assertIsNotNone(invite.sent_datetime)
예제 #20
0
    def test_user_sending_is_not_part_of_the_group(self):
        testgroup = mommy.make('core.AssignmentGroup')
        testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        testgroup2 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup1).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup2).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The user sending an invite must be a Candiate on the group.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #21
0
    def test_assignment_does_not_allow_students_to_form_groups(self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=False)
        testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'This assignment does not allow students to form project groups on their own.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #22
0
    def test_student_already_invited_but_not_responded(self):
        testgroup = mommy.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
        mommy.make('core.GroupInvite', group=testgroup, sent_by=sent_by, sent_to=sent_to)

        with self.assertRaisesMessage(
                ValidationError,
                'The student is already invited to join the group, but they have not responded yet.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #23
0
    def test_user_sending_is_not_part_of_the_group(self):
        testgroup = mommy.make('core.AssignmentGroup')
        testgroup1 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        testgroup2 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup1).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup2).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'The user sending an invite must be a Candiate on the group.'):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
예제 #24
0
    def test_assignment_does_not_allow_students_to_form_groups(self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=False)
        testgroup1 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'This assignment does not allow students to form project groups on their own.'
        ):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
예제 #25
0
    def test_student_sent_to_is_already_in_a_group_with_more_than_one_student(self):
        testgroup = mommy.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
        core_mommy.candidate(testgroup1)

        with self.assertRaisesMessage(
                ValidationError,
                'The invited student is already in a project group with more than 1 students.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to,
                accepted=True
            )
            invite.full_clean()
예제 #26
0
    def test_student_sent_to_is_already_in_a_group_with_more_than_one_student(
            self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
        core_mommy.candidate(testgroup1)

        with self.assertRaisesMessage(
                ValidationError,
                'The invited student is already in a project group with more than 1 students.'
        ):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to,
                                 accepted=True)
            invite.full_clean()
예제 #27
0
    def test_create_groups_expired(self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=True,
                               parentnode__students_can_not_create_groups_after=timezone.now() - timedelta(days=1))
        testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'Creating project groups without administrator approval is not '
                'allowed on this assignment anymore. Please contact you course '
                'administrator if you think this is wrong.'):
            invite = GroupInvite(
                group=testgroup,
                sent_by=sent_by,
                sent_to=sent_to
            )
            invite.full_clean()
예제 #28
0
    def test_create_groups_expired(self):
        testgroup = mommy.make(
            'core.AssignmentGroup',
            parentnode__students_can_create_groups=True,
            parentnode__students_can_not_create_groups_after=timezone.now() -
            timedelta(days=1))
        testgroup1 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user

        with self.assertRaisesMessage(
                ValidationError,
                'Creating project groups without administrator approval is not '
                'allowed on this assignment anymore. Please contact you course '
                'administrator if you think this is wrong.'):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
예제 #29
0
    def test_student_already_invited_but_not_responded(self):
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__students_can_create_groups=True)
        testgroup1 = mommy.make('core.AssignmentGroup',
                                parentnode=testgroup.parentnode)
        sent_by = core_mommy.candidate(testgroup).relatedstudent.user
        sent_to = core_mommy.candidate(testgroup1).relatedstudent.user
        mommy.make('core.GroupInvite',
                   group=testgroup,
                   sent_by=sent_by,
                   sent_to=sent_to)

        with self.assertRaisesMessage(
                ValidationError,
                'The student is already invited to join the group, but they have not responded yet.'
        ):
            invite = GroupInvite(group=testgroup,
                                 sent_by=sent_by,
                                 sent_to=sent_to)
            invite.full_clean()
예제 #30
0
 def test_send_invite_mail(self):
     assignment = mommy.make(
         'core.Assignment',
         long_name='Assignment 1',
         short_name='assignment1',
         parentnode__long_name='Spring2017',
         parentnode__short_name='s17',
         parentnode__parentnode__long_name=
         'DUCK1010 - Object Oriented Programming',
         parentnode__parentnode__short_name='Duck1010',
         students_can_create_groups=True,
     )
     testgroup = mommy.make('core.AssignmentGroup', parentnode=assignment)
     testgroup1 = mommy.make('core.AssignmentGroup', parentnode=assignment)
     sent_by = core_mommy.candidate(testgroup,
                                    shortname="*****@*****.**",
                                    fullname="April").relatedstudent.user
     sent_to = core_mommy.candidate(testgroup1,
                                    shortname="*****@*****.**",
                                    fullname="Dewey").relatedstudent.user
     mommy.make('devilry_account.UserEmail',
                user=sent_to,
                email="*****@*****.**")
     invite = GroupInvite(group=testgroup, sent_by=sent_by, sent_to=sent_to)
     invite.full_clean()
     invite.save()
     request = self.__fake_request()
     invite.send_invite_notification(request)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(
         mail.outbox[0].subject,
         '[Devilry] Project group invite for Duck1010.s17.assignment1')
     url = request.build_absolute_uri(
         reverse('devilry_student_groupinvite_respond',
                 kwargs={'invite_id': invite.id}))
     self.assertIn(url, mail.outbox[0].body)