コード例 #1
0
    def test_assignment_reminder_task_on_date(self):
        user = BlueBottleUserFactory.create(first_name='Nono')
        end = now() + timedelta(days=4)
        assignment = AssignmentFactory.create(
            owner=user,
            status='open',
            end_date_type='on_date',
            initiative=self.initiative,
            date=end
        )

        ApplicantFactory.create_batch(2, activity=assignment, status='new')
        ApplicantFactory.create(activity=assignment, status='accepted')
        withdrawn = ApplicantFactory.create(activity=assignment, status='new')
        withdrawn.states.withdraw(save=True)

        mail.outbox = []
        tenant = connection.tenant
        assignment_tasks()

        with LocalTenant(tenant, clear_tenant=True):
            assignment.refresh_from_db()

        recipients = [message.to[0] for message in mail.outbox]

        for applicant in assignment.contributions.instance_of(Applicant).all():
            if applicant.status in ['new', 'accepted']:
                self.assertTrue(applicant.user.email in recipients)
            else:
                self.assertFalse(applicant.user.email in recipients)
        self.assertEqual(
            mail.outbox[0].subject,
            '"{}" will take place in 5 days!'.format(assignment.title)
        )
コード例 #2
0
    def test_get_stats(self):
        event = EventFactory.create(initiative=self.initiative,
                                    status='succeeded')
        ParticipantFactory.create_batch(3,
                                        activity=event,
                                        status='succeeded',
                                        time_spent=3)

        assignment = AssignmentFactory.create(initiative=self.initiative,
                                              status='succeeded',
                                              duration=3)
        ApplicantFactory.create_batch(3,
                                      activity=assignment,
                                      status='succeeded',
                                      time_spent=3)

        funding = FundingFactory.create(initiative=self.initiative,
                                        status='succeeded')
        DonationFactory.create_batch(3,
                                     activity=funding,
                                     status='succeeded',
                                     amount=Money(10, 'EUR'))
        DonationFactory.create_batch(3,
                                     activity=funding,
                                     status='succeeded',
                                     amount=Money(10, 'USD'))

        response = self.client.get(self.url, user=self.owner)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        stats = response.json()['data']['meta']['stats']
        self.assertEqual(stats['hours'], 18)
        self.assertEqual(stats['activities'], 3)
        self.assertEqual(stats['contributions'], 12)
        self.assertEqual(stats['amount'], 75.0)
コード例 #3
0
    def test_assignment_check_end_date_future(self):
        user = BlueBottleUserFactory.create(first_name='Nono')

        deadline = now() - timedelta(days=4)
        date = now() + timedelta(days=2)

        assignment = AssignmentFactory.create(
            owner=user,
            status='open',
            capacity=3,
            registration_deadline=deadline.date(),
            initiative=self.initiative,
            date=date,
        )

        applicants = ApplicantFactory.create_batch(3, activity=assignment)
        for applicant in applicants:
            applicant.states.accept(save=True)

        ApplicantFactory.create_batch(3, activity=assignment)

        tenant = connection.tenant

        future = timezone.now() + timedelta(days=3)
        with mock.patch.object(timezone, 'now', return_value=future):
            assignment_tasks()

        with LocalTenant(tenant, clear_tenant=True):
            assignment.refresh_from_db()

        self.assertEqual(assignment.status, 'succeeded')
        for applicant in assignment.applicants:
            self.assertEqual(applicant.status, 'succeeded')
コード例 #4
0
    def test_sort_matching_skill(self):
        skill = SkillFactory.create()
        self.owner.skills.add(skill)
        self.owner.save()

        first = AssignmentFactory.create(status='full')
        ApplicantFactory.create_batch(3, activity=first, status='accepted')

        second = AssignmentFactory.create(status='full', expertise=skill)
        ApplicantFactory.create_batch(3, activity=second, status='accepted')

        third = AssignmentFactory.create(status='open')
        fourth = AssignmentFactory.create(status='open', expertise=skill)

        response = self.client.get(self.url + '?sort=popularity',
                                   user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 4)

        self.assertEqual(data['data'][0]['id'], str(fourth.pk))
        self.assertEqual(data['data'][1]['id'], str(third.pk))
        self.assertEqual(data['data'][2]['id'], str(second.pk))
        self.assertEqual(data['data'][3]['id'], str(first.pk))
コード例 #5
0
    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)
コード例 #6
0
    def test_sort_matching_office_location(self):
        self.owner.location = LocationFactory.create(position='10.0, 20.0')
        self.owner.save()

        first = AssignmentFactory.create(status='full')
        ApplicantFactory.create_batch(3, activity=first, status='accepted')

        second = AssignmentFactory.create(
            status='full',
            is_online=False,
            location=GeolocationFactory.create(position=Point(20.0, 10.0)))
        ApplicantFactory.create_batch(3, activity=second, status='accepted')

        third = AssignmentFactory.create(status='open')
        fourth = AssignmentFactory.create(
            status='open',
            is_online=False,
            location=GeolocationFactory.create(position=Point(21.0, 9.0)))
        fifth = AssignmentFactory.create(
            status='open',
            is_online=False,
            location=GeolocationFactory.create(position=Point(20.0, 10.0)))

        response = self.client.get(self.url + '?sort=popularity',
                                   user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 5)

        self.assertEqual(data['data'][0]['id'], str(fifth.pk))
        self.assertEqual(data['data'][1]['id'], str(fourth.pk))
        self.assertEqual(data['data'][2]['id'], str(third.pk))
        self.assertEqual(data['data'][3]['id'], str(second.pk))
        self.assertEqual(data['data'][4]['id'], str(first.pk))
コード例 #7
0
    def test_filter_country(self):
        country1 = CountryFactory.create()
        country2 = CountryFactory.create()

        initiative1 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative2 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))
        initiative3 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative4 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))

        first = AssignmentFactory.create(status='full', initiative=initiative1)
        ApplicantFactory.create_batch(3, activity=first, status='accepted')

        second = AssignmentFactory.create(status='open',
                                          initiative=initiative3)

        third = AssignmentFactory.create(status='full', initiative=initiative2)
        ApplicantFactory.create_batch(3, activity=third, status='accepted')

        AssignmentFactory.create(status='open', initiative=initiative4)

        response = self.client.get(
            self.url +
            '?sort=popularity&filter[country]={}'.format(country1.id),
            user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)

        self.assertEqual(data['data'][0]['id'], str(second.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
コード例 #8
0
 def test_delete_assignment_admin(self):
     self.client.force_login(self.superuser)
     ApplicantFactory.create_batch(3, activity=self.assignment)
     url = reverse('admin:assignments_assignment_delete', args=(self.assignment.id,))
     response = self.client.post(url, {'post': 'yes'})
     self.assertEqual(response.status_code, status.HTTP_302_FOUND)
     self.assertEqual(Assignment.objects.count(), 0)
     self.assertEqual(Applicant.objects.count(), 0)
コード例 #9
0
    def setUp(self):
        super(ContributionListAPITestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory.create()

        ParticipantFactory.create_batch(2, user=self.user)
        ApplicantFactory.create_batch(2, user=self.user)
        DonationFactory.create_batch(2, user=self.user, status='succeeded')
        DonationFactory.create_batch(2, user=self.user, status='new')

        ParticipantFactory.create()
        ApplicantFactory.create()
        DonationFactory.create()

        self.url = reverse('contribution-list')
コード例 #10
0
    def test_assignment_check_registration_deadline(self):
        user = BlueBottleUserFactory.create(first_name='Nono')

        deadline = now() - timedelta(days=1)
        end = now() + timedelta(days=4)

        assignment = AssignmentFactory.create(
            owner=user,
            status='open',
            capacity=3,
            end_date_type='on_date',
            registration_deadline=deadline.date(),
            initiative=self.initiative,
            duration=4,
            date=end,
        )
        applicants = ApplicantFactory.create_batch(3, activity=assignment, status='new')
        for applicant in applicants:
            applicant.states.accept(save=True)

        tenant = connection.tenant
        assignment_tasks()

        with LocalTenant(tenant, clear_tenant=True):
            assignment.refresh_from_db()

        self.assertEqual(assignment.status, 'full')
コード例 #11
0
    def test_succeed(self):
        self.assignment.states.submit(save=True)
        applicants = ApplicantFactory.create_batch(self.assignment.capacity,
                                                   activity=self.assignment)

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.open.value)

        for applicant in applicants:
            applicant.states.accept(save=True)

        self.assignment.date = now() - timedelta(days=1)
        self.assignment.registration_date = now() - timedelta(days=1)
        self.assignment.save()

        for applicant in applicants:
            applicant.refresh_from_db()
            self.assertEqual(applicant.time_spent, self.assignment.duration)

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.succeeded.value)
        self.assertEqual(
            mail.outbox[-1].subject,
            u'Your task "{}" has been successfully completed! 🎉'.format(
                self.assignment.title))
        self.assertTrue('You did it!' in mail.outbox[-1].body)
コード例 #12
0
    def test_assignment_check_start_date(self):
        user = BlueBottleUserFactory.create(first_name='Nono')

        registration_deadline = now() - timedelta(days=1)
        date = now() + timedelta(hours=6)

        assignment = AssignmentFactory.create(
            owner=user,
            status='open',
            capacity=3,
            registration_deadline=registration_deadline.date(),
            initiative=self.initiative,
            end_date_type='on_date',
            duration=10,
            date=date
        )
        applicants = ApplicantFactory.create_batch(3, activity=assignment, status='new')
        for applicant in applicants:
            applicant.states.accept(save=True)

        tenant = connection.tenant
        with mock.patch.object(timezone, 'now', return_value=(timezone.now() + timedelta(hours=7))):
            assignment_tasks()

        with LocalTenant(tenant, clear_tenant=True):
            assignment.refresh_from_db()

        self.assertEqual(assignment.status, 'running')
コード例 #13
0
    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)
コード例 #14
0
    def test_member_export(self):
        member = BlueBottleUserFactory.create(username='******')
        CustomMemberFieldSettings.objects.create(name='Extra Info')
        field = CustomMemberFieldSettings.objects.create(name='How are you')
        CustomMemberField.objects.create(member=member,
                                         value='Fine',
                                         field=field)

        ParticipantFactory.create(time_spent=5,
                                  user=member,
                                  status='succeeded')
        ParticipantFactory.create(time_spent=12,
                                  user=member,
                                  status='succeeded')
        ApplicantFactory.create_batch(3,
                                      time_spent=10,
                                      user=member,
                                      status='succeeded')
        DonationFactory.create_batch(7,
                                     amount=Money(5, 'EUR'),
                                     user=member,
                                     status='succeeded')

        export_action = self.member_admin.actions[0]
        response = export_action(self.member_admin, self.request,
                                 self.member_admin.get_queryset(self.request))

        data = response.content.decode('utf-8').split("\r\n")
        headers = data[0].split(",")
        user_data = []
        for row in data:
            if row.startswith('malle-eppie'):
                user_data = row.split(',')

        # Test basic info and extra field are in the csv export
        self.assertEqual(headers, [
            'username', 'email', 'remote_id', 'first_name', 'last name',
            'date joined', 'is initiator', 'is supporter', 'is volunteer',
            'amount donated', 'time spent', 'subscribed to matching projects',
            'Extra Info', 'How are you'
        ])
        self.assertEqual(user_data[0], 'malle-eppie')
        self.assertEqual(user_data[7], 'True')
        self.assertEqual(user_data[8], 'True')
        self.assertEqual(user_data[9], u'35.00 €')
        self.assertEqual(user_data[10], '47.0')
        self.assertEqual(user_data[13], 'Fine')
コード例 #15
0
    def test_export_user_segments(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        users = BlueBottleUserFactory.create_batch(5)
        segment_type = SegmentTypeFactory.create(name='Department')
        engineering = SegmentFactory.create(type=segment_type,
                                            name='Engineering')
        rubbish = SegmentFactory.create(type=segment_type, name='Rubbish')
        users[0].segments.add(engineering)
        initiative = InitiativeFactory.create(owner=users[0])
        assignment = AssignmentFactory.create(owner=users[1],
                                              initiative=initiative)
        assignment.segments.add(engineering)
        assignment.segments.add(rubbish)
        ApplicantFactory.create(activity=assignment, user=users[2])

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(book.sheet_by_name('Users').ncols, 12)
        self.assertEqual(
            book.sheet_by_name('Users').cell(0, 11).value, 'Department')

        t = 0
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(t, 5).value == users[0].email:
                self.assertEqual(
                    book.sheet_by_name('Users').cell(t, 11).value,
                    'Engineering')
            t += 1

        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 23).value, 'Department')

        t = 0
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(t, 5).value == users[0].email:
                self.assertTrue(
                    book.sheet_by_name('Tasks').cell(t, 23).value in
                    ['Engineering, Rubbish', 'Rubbish, Engineering'])
            t += 1
コード例 #16
0
    def test_retrieve_applicant(self):
        applicant = ApplicantFactory.create(activity=self.assignment)
        response = self.client.get(self.url, user=applicant.user)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['status'], 'draft')

        self.assertEqual(
            self.assignment.online_meeting_url,
            response.json()['data']['attributes']['online-meeting-url'])
コード例 #17
0
    def test_assignment_reminder_task_twice(self):
        user = BlueBottleUserFactory.create(first_name='Nono')
        end = now() + timedelta(days=4)
        assignment = AssignmentFactory.create(
            owner=user,
            status='open',
            initiative=self.initiative,
            date=end,
        )

        ApplicantFactory.create_batch(3, activity=assignment, status='new')
        withdrawn = ApplicantFactory.create(activity=assignment, status='new')
        withdrawn.states.withdraw(save=True)

        assignment_tasks()
        mail.outbox = []
        assignment_tasks()

        self.assertEqual(len(mail.outbox), 0)
コード例 #18
0
    def test_fill(self):
        self.assignment.states.submit(save=True)
        applicants = ApplicantFactory.create_batch(self.assignment.capacity,
                                                   activity=self.assignment)
        for applicant in applicants:
            applicant.states.accept(save=True)

        self.assignment.refresh_from_db()

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.full.value)
コード例 #19
0
    def test_unfill_change_capacity(self):
        self.assignment.states.submit(save=True)
        applicants = ApplicantFactory.create_batch(self.assignment.capacity,
                                                   activity=self.assignment)
        for applicant in applicants:
            applicant.states.accept(save=True)

        self.assignment.capacity += 1
        self.assignment.save()

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.open.value)
コード例 #20
0
    def test_export_custom_user_fields(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)

        colour = CustomMemberFieldSettings.objects.create(
            name='colour', description='Favourite colour')

        BlueBottleUserFactory.create_batch(2)
        user = BlueBottleUserFactory.create(email='*****@*****.**')
        BlueBottleUserFactory.create_batch(2)

        CustomMemberField.objects.create(member=user,
                                         field=colour,
                                         value='Parblue Yellow')
        initiative = InitiativeFactory.create(owner=user)
        assignment = AssignmentFactory.create(owner=user,
                                              initiative=initiative)
        ApplicantFactory.create(activity=assignment, user=user)

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(book.sheet_by_name('Users').ncols, 12)
        t = 1
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(
                    t, 5).value == '*****@*****.**':
                self.assertEqual(
                    book.sheet_by_name('Users').cell(t, 11).value,
                    'Parblue Yellow')
            t += 1

        self.assertEqual(
            book.sheet_by_name('Task contributions').cell(0, 13).value,
            'Favourite colour')
        self.assertEqual(
            book.sheet_by_name('Task contributions').cell(1, 13).value,
            'Parblue Yellow')
コード例 #21
0
    def setUp(self):
        super(ApplicantStateMachineTestCase, self).setUp()
        self.settings = InitiativePlatformSettingsFactory.create(
            activity_types=['assignment'])
        self.initiative = InitiativeFactory()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.assignment = AssignmentFactory.create(owner=self.initiative.owner,
                                                   initiative=self.initiative)
        self.assignment.states.submit(save=True)
        mail.outbox = []
        self.applicant = ApplicantFactory.create(activity=self.assignment)
コード例 #22
0
    def test_participant_rejected(self):
        contribution = ApplicantFactory.create(activity=self.assignment,
                                               user=self.other_user)
        contribution.states.reject(save=True)
        self.assignment.states.start(save=True)
        self.assignment.states.succeed(save=True)

        self.assertEqual(self.stats.activities_online, 0)
        self.assertEqual(self.stats.activities_succeeded, 1)
        self.assertEqual(self.stats.assignments_succeeded, 1)
        self.assertEqual(self.stats.time_spent, 0)
        self.assertEqual(self.stats.assignment_members, 0)
        self.assertEqual(self.stats.people_involved, 1)
コード例 #23
0
    def test_empty_title_assignment_admin(self):
        self.client.force_login(self.superuser)
        self.applicants = ApplicantFactory.create_batch(3, activity=self.assignment, time_spent=6,)
        self.assertEqual(Applicant.objects.count(), 3)
        url = reverse('admin:assignments_assignment_change', args=(self.assignment.id,))

        data = {
            'title': '',
            'slug': self.assignment.slug,
            'owner': self.assignment.owner_id,
            'initiative': self.assignment.initiative_id,
            'description': self.assignment.description,
            'capacity': self.assignment.capacity,
            'date_0': str(self.assignment.date.date()),
            'date_1': str(self.assignment.date.time()),
            'end_date_type': self.assignment.end_date_type,
            'registration_deadline': str(self.assignment.registration_deadline),
            'duration': self.assignment.duration,
            'preparation': self.assignment.preparation,
            'expertise': self.assignment.expertise_id,
            'is_online': self.assignment.is_online,
            'location': self.assignment.location_id,

            '_continue': 'Save and continue editing',
            'confirm': 'Yes',

            'notifications-message-content_type-object_id-TOTAL_FORMS': '0',
            'notifications-message-content_type-object_id-INITIAL_FORMS': '0',
            'wallposts-wallpost-content_type-object_id-TOTAL_FORMS': '0',
            'wallposts-wallpost-content_type-object_id-INITIAL_FORMS': '0',

            'contributions-TOTAL_FORMS': '3',
            'contributions-INITIAL_FORMS': '3',
            'contributions-0-contribution_ptr': self.applicants[0].contribution_ptr_id,
            'contributions-0-activity': self.assignment.id,
            'contributions-0-user': self.applicants[0].user_id,
            'contributions-0-time_spent': self.applicants[0].time_spent,
            'contributions-0-DELETE': 'on',
            'contributions-1-contribution_ptr': self.applicants[1].contribution_ptr_id,
            'contributions-1-activity': self.assignment.id,
            'contributions-1-user': self.applicants[1].user_id,
            'contributions-1-time_spent': self.applicants[1].time_spent,
            'contributions-2-contribution_ptr': self.applicants[2].contribution_ptr_id,
            'contributions-2-activity': self.assignment.id,
            'contributions-2-user': self.applicants[2].user_id,
            'contributions-2-time_spent': self.applicants[2].time_spent,
            'contributions-2-DELETE': 'on',
        }

        response = self.client.post(url, data)
        self.assertContains(response, '<ul class="errorlist"><li>This field is required.</li></ul>')
コード例 #24
0
 def test_applicant(self):
     contribution = ApplicantFactory.create(activity=self.assignment,
                                            user=self.other_user)
     contribution.states.accept(save=True)
     self.assignment.states.start(save=True)
     self.assignment.states.succeed(save=True)
     contribution.refresh_from_db()
     contribution.time_spent = 32
     contribution.save()
     self.assertEqual(self.stats.activities_online, 0)
     self.assertEqual(self.stats.activities_succeeded, 1)
     self.assertEqual(self.stats.assignments_succeeded, 1)
     self.assertEqual(self.stats.time_spent, 32)
     self.assertEqual(self.stats.assignment_members, 1)
     self.assertEqual(self.stats.people_involved, 2)
コード例 #25
0
    def test_check_status_applicant_removed(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            date=now() + timedelta(days=4),
            capacity=3,
        )
        applicants = ApplicantFactory.create_batch(3, activity=assignment)
        for applicant in applicants:
            applicant.states.accept(save=True)

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

        applicants[0].delete()

        self.assertEqual(assignment.status, 'open')
コード例 #26
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')
コード例 #27
0
    def test_succeed_then_reschedule(self):
        self.assignment.states.submit(save=True)
        applicants = ApplicantFactory.create_batch(self.assignment.capacity,
                                                   activity=self.assignment)
        for applicant in applicants:
            applicant.states.accept(save=True)

        self.assignment.date = now() - timedelta(days=1)
        self.assignment.save()

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

        self.assignment.refresh_from_db()

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.open.value)
コード例 #28
0
 def test_change_deadline(self):
     tomorrow = now() + timedelta(days=1)
     next_week = now() + timedelta(days=7)
     assignment = AssignmentFactory.create(capacity=5,
                                           end_date_type='deadline',
                                           date=tomorrow)
     self.assignment.save()
     applicants = ApplicantFactory.create_batch(3, activity=assignment)
     for applicant in applicants:
         applicant.states.accept(save=True)
     mail.outbox = []
     assignment.date = next_week
     assignment.save()
     self.assertEqual(len(mail.outbox), 3)
     self.assertEqual(
         mail.outbox[0].subject,
         'The deadline for your task "{}" has been changed.'.format(
             assignment.title))
コード例 #29
0
    def setUp(self):
        super(ApplicantTransitionAPITestCase, self).setUp()
        self.settings = InitiativePlatformSettingsFactory.create(
            activity_types=['assignment'])

        self.client = JSONAPITestClient()
        self.transition_url = reverse('applicant-transition-list')
        self.user = BlueBottleUserFactory()
        self.someone_else = BlueBottleUserFactory()
        self.manager = BlueBottleUserFactory(first_name="Boss")
        self.owner = BlueBottleUserFactory(first_name="Owner")
        self.initiative = InitiativeFactory.create(
            activity_manager=self.manager)

        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.assignment = AssignmentFactory.create(owner=self.owner,
                                                   initiative=self.initiative)
        self.assignment.states.submit(save=True)

        document = PrivateDocumentFactory.create()
        self.applicant = ApplicantFactory.create(activity=self.assignment,
                                                 document=document,
                                                 user=self.user)
        self.participant_url = reverse('applicant-detail',
                                       args=(self.applicant.id, ))
        self.transition_data = {
            'data': {
                'type': 'contributions/applicant-transitions',
                'attributes': {
                    'transition': 'accept',
                },
                'relationships': {
                    'resource': {
                        'data': {
                            'type': 'contributions/applicants',
                            'id': self.applicant.pk
                        }
                    }
                }
            }
        }
        mail.outbox = []
コード例 #30
0
    def test_applicant_status_change_on_time_spent(self):
        assignment = AssignmentFactory(
            title='Test Title',
            status='open',
            date=now() + timedelta(days=4),
        )

        applicant = ApplicantFactory.create(activity=assignment)
        applicant.states.accept(save=True)
        assignment.states.start(save=True)
        assignment.states.succeed(save=True)
        applicant.refresh_from_db()

        self.assertEqual(assignment.status, 'succeeded')
        self.assertEqual(applicant.status, 'succeeded')
        applicant.time_spent = 0
        applicant.save()
        self.assertEqual(applicant.status, 'no_show')
        applicant.time_spent = 10
        applicant.save()
        self.assertEqual(applicant.status, 'succeeded')
        self.assertEqual(applicant.contribution_date, assignment.date)