Exemplo n.º 1
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))
Exemplo n.º 2
0
    def test_sort_activity_date(self):
        first = InitiativeFactory.create(status='approved')
        FundingFactory.create(initiative=first,
                              status='open',
                              deadline=now() + datetime.timedelta(days=8))
        FundingFactory.create(initiative=first,
                              status='submitted',
                              deadline=now() + datetime.timedelta(days=7))

        second = InitiativeFactory.create(status='approved')
        EventFactory.create(initiative=second,
                            status='open',
                            start=now() + datetime.timedelta(days=7))
        third = InitiativeFactory.create(status='approved')
        EventFactory.create(initiative=third,
                            status='open',
                            start=now() + datetime.timedelta(days=7))
        AssignmentFactory.create(initiative=third,
                                 status='open',
                                 date=now() + datetime.timedelta(days=9))

        response = self.client.get(self.url + '?sort=activity_date',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 3)
        self.assertEqual(data['data'][0]['id'], str(third.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
        self.assertEqual(data['data'][2]['id'], str(second.pk))
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
0
    def test_images(self):
        EventFactory.create(owner=self.owner,
                            review_status='approved',
                            image=ImageFactory.create())
        AssignmentFactory.create(review_status='approved',
                                 image=ImageFactory.create())
        FundingFactory.create(review_status='approved',
                              image=ImageFactory.create())

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

        for activity in response.json()['data']:
            self.assertEqual(
                activity['relationships']['image']['data']['type'], 'images')
Exemplo n.º 6
0
 def setUp(self):
     super(TestAssignmentAdmin, self).setUp()
     self.site = AdminSite()
     self.assignment_admin = AssignmentAdmin(Assignment, self.site)
     self.assignment = AssignmentFactory.create(status='created', end_date_type='on_date', preparation=5,)
     self.assignment_url = reverse('admin:assignments_assignment_change', args=(self.assignment.id,))
     self.assignment.save()
Exemplo n.º 7
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)
Exemplo n.º 8
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)
        )
Exemplo n.º 9
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')
Exemplo n.º 10
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')
Exemplo n.º 11
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')
Exemplo n.º 12
0
 def test_task_textwallpost_admin(self):
     task = AssignmentFactory.create()
     self.wallpost = MediaWallpostFactory.create(content_object=task)
     url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, ))
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200, response.content)
     self.assertContains(response, task.title)
Exemplo n.º 13
0
    def test_export_impact(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        users = BlueBottleUserFactory.create_batch(5)

        co2 = ImpactType.objects.get(slug='co2')
        co2.active = True
        co2.save()
        water = ImpactType.objects.get(slug='water')
        water.active = True
        water.save()

        initiative = InitiativeFactory.create(owner=users[0])

        assignment = AssignmentFactory.create(owner=users[1],
                                              initiative=initiative)
        assignment.goals.create(type=co2, realized=300)
        assignment.goals.create(type=water, realized=750)

        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('Tasks').cell(0, 23).value,
            u'Reduce CO\u2082 emissions')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 23).value, 300)
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 24).value, u'Save water')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 24).value, 750)
Exemplo n.º 14
0
 def setUp(self):
     super(AssignmentStatisticsTest, self).setUp()
     self.assignment = AssignmentFactory.create(
         owner=self.some_user,
         initiative=self.initiative,
         registration_deadline=(timezone.now() +
                                datetime.timedelta(hours=24)).date(),
         date=(timezone.now() + datetime.timedelta(hours=48)),
         duration=0.1)
     self.assignment.states.submit(save=True)
Exemplo n.º 15
0
    def setUp(self):
        super(UsedCountryListTestCase, self).setUp()

        belgium = Country.objects.get(translations__name="Belgium")
        location_be = GeolocationFactory.create(country=belgium)

        bulgaria = Country.objects.get(translations__name="Bulgaria")
        location_bg = GeolocationFactory.create(country=bulgaria)

        germany = Country.objects.get(translations__name="Germany")
        location_de = GeolocationFactory.create(country=germany)

        turkey = Country.objects.get(translations__name="Turkey")
        location_tr = LocationFactory.create(country=turkey)
        LocationFactory.create(country=Country.objects.get(translations__name='France'))

        EventFactory.create(
            status='open',
            location=location_be
        )
        EventFactory.create(
            status='full',
            location=location_bg
        )

        AssignmentFactory.create(
            status='draft',
            location=location_de
        )

        EventFactory.create(
            status='submitted',
            location=location_de
        )
        initiative = InitiativeFactory.create(
            status='approved',
            location=location_tr
        )
        FundingFactory.create(
            initiative=initiative,
            status='open'
        )
Exemplo n.º 16
0
    def setUp(self):
        super(AssignmentStateMachineTestCase, 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)
        mail.outbox = []
Exemplo n.º 17
0
    def test_incomplete(self):
        self.assignment = AssignmentFactory.create(owner=self.initiative.owner,
                                                   title='',
                                                   initiative=self.initiative)

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

        organizer = self.assignment.contributions.get()
        self.assertTrue(isinstance(organizer, Organizer))
        self.assertEqual(organizer.status, OrganizerStateMachine.new.value)
        self.assertRaises(TransitionNotPossible, self.assignment.states.submit)
Exemplo n.º 18
0
    def test_activity_date_filter(self):
        next_month = now() + dateutil.relativedelta.relativedelta(months=1)
        after = now() + dateutil.relativedelta.relativedelta(months=2)

        event = EventFactory.create(status='open', start=next_month)
        EventFactory.create(status='open', start=after)

        on_date_assignment = AssignmentFactory.create(status='open',
                                                      date=next_month,
                                                      end_date_type='on_date')
        AssignmentFactory.create(status='open',
                                 date=after,
                                 end_date_type='on_date')
        deadline_assignment = AssignmentFactory.create(
            status='open', date=next_month, end_date_type='deadline')

        # Feature is not dealing with time. Disabling timezone check for test
        funding = FundingFactory.create(status='open', deadline=next_month)
        FundingFactory.create(status='open', deadline=after)

        response = self.client.get(self.url + '?filter[date]={}-{}-{}'.format(
            after.year, after.month, after.day),
                                   user=self.owner)

        data = json.loads(response.content)
        self.assertEqual(data['meta']['pagination']['count'], 3)

        response = self.client.get(self.url + '?filter[date]={}-{}-{}'.format(
            next_month.year, next_month.month, next_month.day),
                                   user=self.owner)

        data = json.loads(response.content)
        self.assertEqual(data['meta']['pagination']['count'], 4)

        found = [item['id'] for item in data['data']]

        self.assertTrue(str(event.pk) in found)
        self.assertTrue(str(on_date_assignment.pk) in found)
        self.assertTrue(str(deadline_assignment.pk) in found)
        self.assertTrue(str(funding.pk) in found)
Exemplo n.º 19
0
    def test_submit_initiative_not_submitted(self):
        self.assignment = AssignmentFactory.create(
            owner=self.initiative.owner, initiative=InitiativeFactory.create())

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

        self.assertRaises(TransitionNotPossible, self.assignment.states.submit)
        self.assignment.initiative.states.submit(save=True)
        self.assignment.refresh_from_db()

        self.assertEqual(self.assignment.status,
                         AssignmentStateMachine.submitted.value)
Exemplo n.º 20
0
    def test_approve(self):
        self.assignment = AssignmentFactory.create(end_date_type='on_date',
                                                   owner=self.initiative.owner,
                                                   initiative=self.initiative,
                                                   capacity=3)
        self.assignment.states.submit(save=True)

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

        organizer = self.assignment.contributions.get()
        self.assertTrue(isinstance(organizer, Organizer))
        self.assertEqual(organizer.status,
                         OrganizerStateMachine.succeeded.value)
Exemplo n.º 21
0
    def test_sort_matching_combined(self):
        theme = ProjectThemeFactory.create()
        self.owner.favourite_themes.add(theme)

        skill = SkillFactory.create()
        self.owner.skills.add(skill)

        self.owner.location = LocationFactory.create(position='10.0, 20.0')
        self.owner.save()

        initiative = InitiativeFactory.create(theme=theme)

        first = EventFactory.create(status='open',
                                    initiative=initiative,
                                    is_online=False)
        second = AssignmentFactory.create(
            status='open',
            location=GeolocationFactory.create(position=Point(21.0, 9.0)),
            initiative=initiative,
            is_online=False)
        third = AssignmentFactory.create(
            status='open',
            location=GeolocationFactory.create(position=Point(21.0, 9.0)),
            initiative=initiative,
            expertise=skill,
            is_online=False)

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

        data = json.loads(response.content)

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

        self.assertEqual(data['data'][0]['id'], str(third.pk))
        self.assertEqual(data['data'][1]['id'], str(second.pk))
        self.assertEqual(data['data'][2]['id'], str(first.pk))
Exemplo n.º 22
0
    def setUp(self):
        super(WallpostPermissionsTest, self).setUp()

        self.owner = BlueBottleUserFactory.create(password='******', first_name='someName', last_name='someLast')
        self.owner_token = "JWT {0}".format(self.owner.get_jwt_token())

        self.initiative = InitiativeFactory.create(owner=self.owner)
        self.event = EventFactory.create(owner=self.owner)
        self.assignment = AssignmentFactory.create(owner=self.owner)

        self.other_user = BlueBottleUserFactory.create()
        self.other_token = "JWT {0}".format(
            self.other_user.get_jwt_token())

        self.media_wallpost_url = reverse('media_wallpost_list')
        self.text_wallpost_url = reverse('text_wallpost_list')
        self.wallpost_url = reverse('wallpost_list')
Exemplo n.º 23
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))
Exemplo n.º 24
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
Exemplo n.º 25
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)
Exemplo n.º 26
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 = []
Exemplo n.º 27
0
    def setUp(self):
        super(AssignmentDetailAPITestCase, self).setUp()
        self.settings = InitiativePlatformSettingsFactory.create(
            activity_types=['assignment'])

        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory(owner=self.user)
        self.assignment = AssignmentFactory.create(initiative=self.initiative)

        self.client = JSONAPITestClient()
        self.url = reverse('assignment-detail', args=(self.assignment.id, ))

        self.data = {
            'data': {
                'type': 'activities/assignments',
                'id': self.assignment.id,
                'attributes': {
                    'title':
                    'Design Sprint',
                    'start':
                    str(timezone.now() + timedelta(days=21)),
                    'duration':
                    4,
                    'registration_deadline':
                    str((timezone.now() + timedelta(days=14)).date()),
                    'capacity':
                    10,
                    'address':
                    'Zuid-Boulevard Katwijk aan Zee',
                    'description':
                    'We will clean up the beach south of Katwijk'
                },
                'relationships': {
                    'initiative': {
                        'data': {
                            'type': 'initiatives',
                            'id': self.initiative.id
                        },
                    },
                }
            }
        }
Exemplo n.º 28
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')
Exemplo n.º 29
0
    def test_assignment_check_start_date_no_applicants(self):
        user = BlueBottleUserFactory.create(first_name='Nono')

        deadline = now() - timedelta(days=1)
        date = now() - timedelta(hours=2)

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

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

        self.assertEqual(assignment.status, 'cancelled')
Exemplo n.º 30
0
    def setUp(self):
        super(ApplicantAPITestCase, self).setUp()
        self.settings = InitiativePlatformSettingsFactory.create(
            activity_types=['assignment'])

        self.client = JSONAPITestClient()
        self.url = reverse('applicant-list')
        self.owner = BlueBottleUserFactory()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create(owner=self.owner,
                                                   activity_manager=self.owner)

        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.assignment = AssignmentFactory.create(initiative=self.initiative,
                                                   duration=4,
                                                   owner=self.owner,
                                                   title="Make coffee")
        self.assignment.states.submit(save=True)
        self.apply_data = {
            'data': {
                'type': 'contributions/applicants',
                'attributes': {
                    'motivation': 'Pick me! Pick me!',
                },
                'relationships': {
                    'activity': {
                        'data': {
                            'type': 'activities/assignments',
                            'id': self.assignment.id
                        },
                    },
                }
            }
        }
        self.private_document_url = reverse('private-document-list')
        self.php_document_path = './bluebottle/files/tests/files/index.php'
        self.png_document_path = './bluebottle/files/tests/files/test-image.png'
        mail.outbox = []