Esempio n. 1
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)
Esempio n. 2
0
    def setUp(self):
        super(StatisticsDateTest, self).setUp()

        user = BlueBottleUserFactory.create()
        other_user = BlueBottleUserFactory.create()

        for diff in (10, 5, 1):
            initiative = InitiativeFactory.create(owner=user)
            past_date = timezone.now() - datetime.timedelta(days=diff)
            initiative.created = past_date
            initiative.save()
            initiative.states.submit()
            initiative.states.approve(save=True)

            event = EventFactory(
                start=past_date,
                initiative=initiative,
                duration=1,
                transition_date=past_date,
                status='succeeded',
                owner=BlueBottleUserFactory.create(),
            )

            ParticipantFactory.create(activity=event,
                                      status='succeeded',
                                      time_spent=1,
                                      user=other_user)
    def test_succeed_when_passed(self):
        self.passed_event.states.submit(save=True)
        ParticipantFactory.create(activity=self.passed_event)
        self.assertEqual(self.passed_event.status,
                         EventStateMachine.succeeded.value)

        for participant in self.passed_event.contributions.instance_of(
                Participant):
            self.assertEqual(participant.status,
                             ParticipantStateMachine.succeeded.value)
Esempio n. 4
0
    def test_participant(self):
        ParticipantFactory.create(activity=self.event, user=self.other_user)
        self.event.states.succeed(save=True)

        self.assertEqual(self.stats.activities_online, 0)
        self.assertEqual(self.stats.activities_succeeded, 1)
        self.assertEqual(self.stats.events_succeeded, 1)
        self.assertEqual(self.stats.time_spent, 0.1)
        self.assertEqual(self.stats.event_members, 1)
        self.assertEqual(self.stats.people_involved, 2)
    def test_not_succeed_change_start(self):
        self.event.states.submit(save=True)
        self.assertEqual(self.event.status, EventStateMachine.open.value)
        ParticipantFactory.create(activity=self.event)

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

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

        for participant in self.event.contributions.instance_of(Participant):
            self.assertEqual(participant.status,
                             ParticipantStateMachine.new.value)
Esempio n. 6
0
 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)
Esempio n. 7
0
    def test_sort_matching_popularity(self):
        first = EventFactory.create(status='open')
        second = EventFactory.create(status='open')
        ParticipantFactory.create(activity=second,
                                  created=now() - timedelta(days=7))

        third = EventFactory.create(status='open')
        ParticipantFactory.create(activity=third,
                                  created=now() - timedelta(days=5))

        fourth = EventFactory.create(status='open')
        ParticipantFactory.create(activity=fourth,
                                  created=now() - timedelta(days=7))
        ParticipantFactory.create(activity=fourth,
                                  created=now() - timedelta(days=5))

        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))
Esempio n. 8
0
    def test_sort_matching_theme(self):
        theme = ProjectThemeFactory.create()
        self.owner.favourite_themes.add(theme)
        self.owner.save()

        initiative = InitiativeFactory.create(theme=theme)

        first = EventFactory.create(status='open', capacity=1)
        ParticipantFactory.create(activity=first)
        second = EventFactory.create(status='open',
                                     initiative=initiative,
                                     capacity=1)
        ParticipantFactory.create(activity=second)
        third = EventFactory.create(status='open')
        ParticipantFactory.create(activity=third)
        fourth = EventFactory.create(status='open', initiative=initiative)
        ParticipantFactory.create(activity=fourth)

        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))
Esempio n. 9
0
    def test_no_capacity(self):
        start = now() + timedelta(hours=1)
        event = EventFactory.create(
            title='The greatest event',
            start=start,
            duration=3,
            initiative=InitiativeFactory.create(status='approved'),
            capacity=None
        )

        event.states.submit(save=True)

        ParticipantFactory.create(activity=event, status='new')
        self.assertEqual(event.status, 'open')
Esempio n. 10
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)
Esempio n. 11
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')
Esempio n. 12
0
    def setUp(self):
        super(ParticipantTransitionTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.url = reverse('event-list')
        self.participant_user = BlueBottleUserFactory()

        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.event = EventFactory.create(owner=self.initiative.owner,
                                         initiative=self.initiative)
        self.participant = ParticipantFactory.create(
            user=self.participant_user, activity=self.event)

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

        self.data = {
            'data': {
                'type': 'contributions/participant-transitions',
                'attributes': {
                    'transition': 'withdraw',
                },
                'relationships': {
                    'resource': {
                        'data': {
                            'type': 'contributions/participants',
                            'id': self.participant.pk
                        }
                    }
                }
            }
        }
Esempio n. 13
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')
Esempio n. 14
0
    def test_mark_absent_no_change(self):
        self.passed_event.states.submit(save=True)
        ParticipantFactory.create(activity=self.passed_event)
        participant = ParticipantFactory.create(activity=self.passed_event)

        self.assertEqual(self.passed_event.status,
                         EventStateMachine.succeeded.value)
        self.assertEqual(participant.status, EventStateMachine.succeeded.value)

        participant.states.mark_absent(user=self.passed_event.owner)
        participant.save()

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

        self.passed_event.refresh_from_db()
        self.assertEqual(self.passed_event.status,
                         EventStateMachine.succeeded.value)
Esempio n. 15
0
    def test_succeed_in_future(self):
        self.event.states.submit(save=True)
        ParticipantFactory.create(activity=self.event)

        future = self.event.start + timedelta(days=2)
        self.event.save()
        tenant = connection.tenant
        with mock.patch.object(timezone, 'now', return_value=future):
            event_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            self.event.refresh_from_db()

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

        self.event.refresh_from_db()
        for participant in self.event.contributions.instance_of(Participant):
            self.assertEqual(participant.status,
                             ParticipantStateMachine.succeeded.value)
            self.assertEqual(participant.time_spent, self.event.duration)
Esempio n. 16
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)
Esempio n. 17
0
    def test_get_participant(self):
        participant = ParticipantFactory.create(activity=self.event)

        response = self.client.get(self.url, user=participant.user)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['data']['attributes']['title'],
                         self.event.title)
        self.assertEqual(
            self.event.online_meeting_url,
            response.json()['data']['attributes']['online-meeting-url'])
Esempio n. 18
0
    def test_event_start_task(self):
        start = timezone.now() + timedelta(hours=1)
        event = EventFactory.create(
            initiative=self.initiative,
            start=start,
            duration=3
        )
        event.states.submit(save=True)

        ParticipantFactory.create(activity=event)

        self.assertEqual(event.status, 'open')
        tenant = connection.tenant
        future = timezone.now() + timedelta(hours=2)
        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, 'running')
Esempio n. 19
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)
Esempio n. 20
0
    def test_participant_withdrawn(self):
        contribution = ParticipantFactory.create(activity=self.event,
                                                 user=self.other_user)
        contribution.states.withdraw(save=True)
        self.event.states.start(save=True)
        self.event.states.succeed(save=True)

        self.assertEqual(self.stats.activities_online, 0)
        self.assertEqual(self.stats.activities_succeeded, 1)
        self.assertEqual(self.stats.events_succeeded, 1)
        self.assertEqual(self.stats.time_spent, 0)
        self.assertEqual(self.stats.event_members, 0)
        self.assertEqual(self.stats.people_involved, 1)
Esempio n. 21
0
    def setUp(self):
        super(ActivityAPIAnonymizationTestCase, self).setUp()
        self.member_settings = MemberPlatformSettings.load()

        self.client = JSONAPITestClient()
        self.owner = BlueBottleUserFactory.create()
        last_year = now() - timedelta(days=400)
        self.old_event = EventFactory.create(created=last_year, status='open')
        ParticipantFactory.create(activity=self.old_event, created=last_year)
        ParticipantFactory.create(activity=self.old_event)

        self.new_event = EventFactory.create(status='open')
        ParticipantFactory.create(activity=self.new_event, created=last_year)
        ParticipantFactory.create(activity=self.new_event)
        self.new_url = reverse('event-detail', args=(self.new_event.id, ))
        self.old_url = reverse('event-detail', args=(self.old_event.id, ))
Esempio n. 22
0
    def setUp(self):
        self.initiator = BlueBottleUserFactory.create()
        self.initiative = InitiativeFactory.create(owner=self.initiator)
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.event = EventFactory.create(initiative=self.initiative,
                                         owner=self.initiator,
                                         capacity=10,
                                         duration=1,
                                         start=now() + timedelta(hours=4))
        self.user = BlueBottleUserFactory.create()
        self.old_user = BlueBottleUserFactory.create()

        self.passed_event = EventFactory.create(initiative=self.initiative,
                                                start=timezone.now() -
                                                timedelta(days=1),
                                                status='succeeded',
                                                duration=1)
        mail.outbox = []
        self.participant = ParticipantFactory.create(user=self.user,
                                                     activity=self.event)
        self.passed_participant = ParticipantFactory.create(
            user=self.old_user, activity=self.passed_event)
Esempio n. 23
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 = []
Esempio n. 24
0
    def setUp(self):
        super(ParticipantDetailTestCase, 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',
                                  initiative=self.initiative,
                                  duration=4)
        self.participant = ParticipantFactory.create(activity=self.event)
        self.participant_url = reverse('participant-detail',
                                       args=(self.participant.pk, ))
Esempio n. 25
0
    def test_sort_matching_status(self):
        EventFactory.create(status='closed')
        second = EventFactory.create(status='succeeded')
        ParticipantFactory.create(activity=second)
        third = EventFactory.create(status='open', capacity=1)
        ParticipantFactory.create(activity=third)
        fourth = EventFactory.create(status='running')
        ParticipantFactory.create(activity=fourth)
        fifth = EventFactory.create(status='open')
        ParticipantFactory.create(activity=fifth)

        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(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))
Esempio n. 26
0
    def test_reject_participants_succeeded(self):
        self.event.states.submit(save=True)
        self.assertEqual(self.event.status, EventStateMachine.open.value)
        participant = ParticipantFactory.create(activity=self.event)
        participant.states.reject(user=self.event.owner, save=True)
        self.assertEqual(participant.status,
                         ParticipantStateMachine.rejected.value)

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

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

        participant.states.accept(save=True)

        self.assertEqual(participant.status,
                         ParticipantStateMachine.succeeded.value)
        self.event.refresh_from_db()
        self.assertEqual(self.event.status, EventStateMachine.succeeded.value)