def test_date_changed(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            date=now() + timedelta(days=4),
        )
        ApplicantFactory.create_batch(3, activity=assignment, status='new')
        ApplicantFactory.create_batch(3,
                                      activity=assignment,
                                      status='accepted')
        withdrawn = ApplicantFactory.create(activity=assignment, status='new')
        withdrawn.states.withdraw(save=True)

        mail.outbox = []

        assignment.date = assignment.date + timedelta(days=1)
        assignment.save()

        messages = dict(
            (message.to[0], message.body) for message in mail.outbox)

        for participant in assignment.contributions.instance_of(
                Applicant).all():
            if participant.status in ('new', 'accepted'):
                self.assertTrue(participant.user.email in messages)
                self.assertTrue(
                    formats.date_format(assignment.date) in messages[
                        participant.user.email])
            else:
                self.assertFalse(participant.user.email in messages)
    def test_end_date_type_changed(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            end_date_type='on_date',
            preparation=5,
            date=now() + timedelta(days=4),
        )

        assignment.end_date_type = 'deadline'
        assignment.save()

        self.assertEqual(assignment.end_date_type, 'deadline')
        self.assertIsNone(assignment.preparation)
    def test_date_not_changed(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            date=now() + timedelta(days=4),
        )
        ApplicantFactory.create_batch(3, activity=assignment, status='new')
        withdrawn = ApplicantFactory.create(activity=assignment, status='new')
        withdrawn.states.withdraw(save=True)

        mail.outbox = []

        assignment.title = 'New title'
        assignment.save()

        self.assertEqual(len(mail.outbox), 0)
    def test_check_status_capacity_changed(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            date=now() + timedelta(days=4),
            capacity=3,
        )
        for applicant in ApplicantFactory.create_batch(3, activity=assignment):
            applicant.states.accept(save=True)

        assignment.refresh_from_db()
        self.assertEqual(assignment.status, 'full')

        assignment.capacity = 10
        assignment.save()

        self.assertEqual(assignment.status, 'open')