Beispiel #1
0
    def test_event_end_task(self):
        user = BlueBottleUserFactory.create(first_name='Nono')
        start = timezone.now() + timedelta(hours=5)
        event = EventFactory.create(
            owner=user,
            initiative=self.initiative,
            title='Finish them translations, Rolfertjan!',
            start=start,
            duration=1
        )
        event.states.submit(save=True)
        ParticipantFactory.create_batch(3, activity=event)

        tenant = connection.tenant

        mail.outbox = []

        future = timezone.now() + timedelta(hours=6)
        with mock.patch.object(timezone, 'now', return_value=future):
            event_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            event = Event.objects.get(pk=event.pk)
        self.assertEqual(event.status, EventStateMachine.succeeded.value)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, u'Your event "{}" took place! \U0001f389'.format(event.title))
        self.assertTrue("Hi Nono,", mail.outbox[0].body)
Beispiel #2
0
    def test_date_changed(self):
        event = EventFactory(
            title='Test Title',
            status='open',
            location=GeolocationFactory.create(position=Point(20.0, 10.0)),
            start=now() + timedelta(days=4),
        )

        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

        mail.outbox = []

        event.start = event.start + timedelta(days=1)
        event.save()

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

        self.assertTrue(
            event.local_timezone_name in mail.outbox[0].body
        )

        self.assertTrue(
            formats.time_format(event.local_start) in mail.outbox[0].body
        )

        for participant in event.contributions.instance_of(Participant):
            if participant.status == 'new':
                self.assertTrue(participant.user.email in recipients)
            else:
                self.assertFalse(participant.user.email in recipients)
Beispiel #3
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)
Beispiel #4
0
    def setUp(self):
        super(ImpactTypeListAPITestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.url = reverse('statistic-list')
        self.user = BlueBottleUserFactory()

        initiative = InitiativeFactory.create()
        event = EventFactory.create(
            initiative=initiative,
            owner=initiative.owner,
            start=timezone.now() - datetime.timedelta(hours=1),
            duration=0.1

        )

        initiative.states.submit(save=True)
        initiative.states.approve(save=True)

        event.refresh_from_db()

        ParticipantFactory.create_batch(5, activity=event)

        self.impact_type = ImpactTypeFactory.create()

        self.impact_goal = ImpactGoalFactory.create(
            type=self.impact_type,
            target=100,
            realized=50
        )

        self.manual = ManualStatisticFactory.create()
        self.impact = ImpactStatisticFactory(impact_type=self.impact_type)
        self.database = DatabaseStatisticFactory(query='people_involved')
    def test_change_capacity_no_transition(self):
        self.event.states.submit(save=True)
        ParticipantFactory.create_batch(self.event.capacity - 1,
                                        activity=self.event)

        self.event.capacity = self.event.capacity + 1
        self.event.save()
        self.assertEqual(self.event.status, EventStateMachine.open.value)
 def test_delete_event_admin(self):
     self.client.force_login(self.superuser)
     ParticipantFactory.create_batch(3, activity=self.event)
     url = reverse('admin:events_event_delete', args=(self.event.id, ))
     response = self.client.post(url, {'post': 'yes'})
     self.assertEqual(response.status_code, status.HTTP_302_FOUND)
     self.assertEqual(Event.objects.count(), 0)
     self.assertEqual(Participant.objects.count(), 0)
    def test_full(self):
        self.event.states.submit(save=True)
        ParticipantFactory.create_batch(self.event.capacity,
                                        activity=self.event)

        self.event.refresh_from_db()

        self.assertEqual(self.event.status, EventStateMachine.full.value)
        for participant in self.event.contributions.instance_of(Participant):
            self.assertEqual(participant.status,
                             ParticipantStateMachine.new.value)
Beispiel #8
0
 def test_event_scheduled_task_start(self):
     ParticipantFactory.create_batch(2, activity=self.event)
     self.assertEqual(self.event.status, 'full')
     tenant = connection.tenant
     with mock.patch.object(timezone,
                            'now',
                            return_value=(timezone.now() +
                                          timedelta(days=10, hours=12))):
         event_tasks()
     with LocalTenant(tenant, clear_tenant=True):
         self.event.refresh_from_db()
     event = Event.objects.get(pk=self.event.pk)
     self.assertEqual(event.status, 'running')
    def test_change_capacity_open(self):
        self.event.states.submit(save=True)
        ParticipantFactory.create_batch(self.event.capacity,
                                        activity=self.event)

        self.event.capacity = self.event.capacity + 1

        effects = list(self.event.current_effects)
        self.assertEqual(len(effects), 1)
        self.assertEqual(effects[0].name, 'reopen')

        self.event.save()
        self.assertEqual(self.event.status, EventStateMachine.open.value)
Beispiel #10
0
    def test_event_properties(self):

        start = now() - timedelta(hours=1)
        event = EventFactory.create(
            title='The greatest event',
            start=start,
            duration=3,
            capacity=10,
            initiative=InitiativeFactory.create(status='approved')
        )
        event.states.submit(save=True)

        ParticipantFactory.create_batch(3, activity=event, status='new')
        self.assertEqual(event.participants.count(), 3)
 def test_list_my_participation_by_event(self):
     # Filtering by user and activity user should only see
     # own participation for that event
     ParticipantFactory.create_batch(4, status='closed', user=self.user)
     ParticipantFactory.create(activity=self.event,
                               status='closed',
                               user=self.user)
     response = self.client.get(self.participant_url, {
         'filter[activity.id]': self.event.id,
         'filter[user.id]': self.user.id
     },
                                user=self.user)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data['results']), 1)
    def test_list_my_participation(self):
        response = self.client.get(self.participant_url,
                                   {'filter[user.id]': self.user.id},
                                   user=self.user)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 0)

        # Create 4 participant objects for this user for different events
        ParticipantFactory.create_batch(4, status='closed', user=self.user)
        response = self.client.get(self.participant_url,
                                   {'filter[user.id]': self.user.id},
                                   user=self.user)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 4)
Beispiel #13
0
 def test_event_scheduled_task_reminder(self):
     ParticipantFactory.create_batch(2, activity=self.event)
     tenant = connection.tenant
     mail.outbox = []
     with mock.patch.object(timezone,
                            'now',
                            return_value=(timezone.now() +
                                          timedelta(days=7))):
         event_tasks()
     with LocalTenant(tenant, clear_tenant=True):
         self.event.refresh_from_db()
     event = Event.objects.get(pk=self.event.pk)
     self.assertEqual(event.status, 'full')
     self.assertEqual(len(mail.outbox), 2)
Beispiel #14
0
    def test_date_not_changed(self):
        event = EventFactory(
            title='Test Title',
            status='open',
            start=now() + timedelta(days=4),
        )
        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

        mail.outbox = []

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

        self.assertEqual(len(mail.outbox), 0)
Beispiel #15
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')
Beispiel #16
0
    def test_full(self):
        start = now() + timedelta(hours=2)
        event = EventFactory.create(
            title='The greatest event',
            start=start,
            duration=1,
            capacity=10,
            initiative=InitiativeFactory.create(status='approved')
        )
        event.states.submit(save=True)

        ParticipantFactory.create_batch(event.capacity, activity=event)
        event.refresh_from_db()

        self.assertEqual(event.status, 'full')
    def test_delete_participant_event_admin(self):
        self.client.force_login(self.superuser)
        self.participants = ParticipantFactory.create_batch(
            3, activity=self.event)
        self.assertEqual(Participant.objects.count(), 3)
        url = reverse('admin:events_event_change', args=(self.event.id, ))

        data = {
            'title': 'New title',
            'slug': self.event.slug,
            'owner': self.event.owner_id,
            'initiative': self.event.initiative_id,
            'description': self.event.description,
            'capacity': self.event.capacity,
            'start_0': str(self.event.start.date()),
            'start_1': str(self.event.start.time()),
            'duration': self.event.duration,
            'status': self.event.status,
            'registration_deadline': str(self.event.registration_deadline),
            'is_online': self.event.is_online,
            'location': self.event.location_id,
            'location_hint': self.event.location_hint,
            '_continue': 'Save and continue editing',
            'confirm': 'Yes',
            'follow-follow-content_type-instance_id-INITIAL_FORMS': '0',
            'follow-follow-content_type-instance_id-TOTAL_FORMS': '0',
            'wallposts-wallpost-content_type-object_id-TOTAL_FORMS': '0',
            'wallposts-wallpost-content_type-object_id-INITIAL_FORMS': '0',
            'notifications-message-content_type-object_id-TOTAL_FORMS': '0',
            'notifications-message-content_type-object_id-INITIAL_FORMS': '0',
            'contributions-TOTAL_FORMS': '3',
            'contributions-INITIAL_FORMS': '3',
            'contributions-0-contribution_ptr':
            self.participants[0].contribution_ptr_id,
            'contributions-0-activity': self.event.id,
            'contributions-0-user': self.participants[0].user_id,
            'contributions-0-time_spent': self.participants[0].time_spent,
            'contributions-0-DELETE': 'on',
            'contributions-1-contribution_ptr':
            self.participants[1].contribution_ptr_id,
            'contributions-1-activity': self.event.id,
            'contributions-1-user': self.participants[1].user_id,
            'contributions-1-time_spent': self.participants[1].time_spent,
            'contributions-2-contribution_ptr':
            self.participants[2].contribution_ptr_id,
            'contributions-2-activity': self.event.id,
            'contributions-2-user': self.participants[2].user_id,
            'contributions-2-time_spent': self.participants[2].time_spent,
            'contributions-2-DELETE': 'on',
        }

        response = self.client.post(url, data)
        self.assertEqual(
            response.status_code, status.HTTP_302_FOUND,
            'Deleting participants failed. '
            'Did you change admin fields for EventAdmin? '
            'Please adjust the data in this test.')
        self.event.refresh_from_db()
        self.assertEqual(self.event.title, 'New title')
        self.assertEqual(Participant.objects.count(), 1)
Beispiel #18
0
    def test_database(self):
        initiative = InitiativeFactory.create()
        event = EventFactory.create(initiative=initiative,
                                    owner=initiative.owner,
                                    start=timezone.now() -
                                    datetime.timedelta(hours=1),
                                    duration=0.1)

        initiative.states.submit(save=True)
        initiative.states.approve(save=True)

        event.refresh_from_db()

        ParticipantFactory.create_batch(5, activity=event)

        stat = DatabaseStatisticFactory.create(name='Test',
                                               query='people_involved')

        self.assertEqual(stat.get_value(), 6)
Beispiel #19
0
    def test_date_changed_passed(self):
        event = EventFactory(
            title='Test Title',
            status='open',
            start=now() - timedelta(days=4),
        )

        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

        mail.outbox = []

        event.start = event.start + timedelta(days=1)
        event.save()

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

        for participant in event.contributions.instance_of(Participant):
            self.assertFalse(participant.user.email in recipients)
Beispiel #20
0
    def test_event_reminder_task_twice(self):
        user = BlueBottleUserFactory.create(first_name='Nono')
        start = timezone.now() + timedelta(days=4)
        event = EventFactory.create(
            owner=user,
            status='open',
            initiative=self.initiative,
            start=start,
            duration=1
        )

        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

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

        self.assertEqual(len(mail.outbox), 0)
Beispiel #21
0
    def test_event_reminder_task(self):
        user = BlueBottleUserFactory.create(first_name='Nono')
        start = timezone.now() + timedelta(days=4)
        event = EventFactory.create(
            owner=user,
            status='open',
            initiative=self.initiative,
            start=start,
            duration=1
        )

        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

        tenant = connection.tenant
        event_tasks()

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

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

        for participant in event.contributions.all():
            if participant.status == 'new':
                self.assertTrue(participant.user.email in recipients)
            else:
                self.assertFalse(participant.user.email in recipients)

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

        for participant in event.contributions.all():
            if participant.status == 'new':
                self.assertTrue(participant.user.email in recipients)
            else:
                self.assertFalse(participant.user.email in recipients)

        mail.outbox = []
    def test_reject_participants(self):
        self.event.states.submit(save=True)
        participants = ParticipantFactory.create_batch(self.event.capacity,
                                                       activity=self.event)
        self.assertEqual(self.event.status, EventStateMachine.full.value)

        participant = participants[0]
        participant.states.reject(user=self.event.owner)
        participant.save()

        self.assertEqual(participant.status,
                         ParticipantStateMachine.rejected.value)

        self.event.refresh_from_db()
        self.assertEqual(self.event.status, EventStateMachine.open.value)
    def test_withdraw_participants_succeeded(self):
        self.event.states.submit(save=True)
        participants = ParticipantFactory.create_batch(self.event.capacity,
                                                       activity=self.event)
        self.assertEqual(self.event.status, EventStateMachine.full.value)

        participant = participants[0]
        participant.states.withdraw(user=participant.user, save=True)

        self.assertEqual(participant.status,
                         ParticipantStateMachine.withdrawn.value)

        self.event.refresh_from_db()
        self.event.start = timezone.now() - timedelta(hours=2)
        self.event.save()

        self.assertEqual(self.event.status, EventStateMachine.succeeded.value)

        participant.states.reapply(save=True)

        self.assertEqual(participant.status,
                         ParticipantStateMachine.succeeded.value)
    def setUp(self):
        super(ParticipantListFilterCase, self).setUp()
        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory.create()

        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.event = EventFactory(title='Test Title',
                                  status='open',
                                  start=(now() - timedelta(hours=5)),
                                  owner=self.initiative.owner,
                                  initiative=self.initiative,
                                  duration=4)

        ParticipantFactory.create_batch(3, activity=self.event, status='new')
        ParticipantFactory.create_batch(2,
                                        activity=self.event,
                                        status='cancelled')
        ParticipantFactory.create_batch(3, status='new')

        self.participant_url = reverse('participant-list')
        self.event_url = reverse('event-detail', args=(self.event.pk, ))