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)
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))
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))
def test_deleted_activities(self): EventFactory.create(initiative=self.initiative, status='deleted') response = self.client.get(self.url, user=self.owner) data = response.json()['data'] self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(data['relationships']['activities']['data']), 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))
def test_export(self): from_date = now() - timedelta(weeks=2) to_date = now() + timedelta(weeks=1) data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'} tenant = connection.tenant initiatives = InitiativeFactory.create_batch(4) for initiative in initiatives: EventFactory.create_batch(3, initiative=initiative) AssignmentFactory.create_batch(2, initiative=initiative) FundingFactory.create_batch(1, initiative=initiative) result = plain_export(Exporter, tenant=tenant, **data) book = xlrd.open_workbook(result) self.assertEqual(book.sheet_by_name('Users').ncols, 11) self.assertEqual(book.sheet_by_name('Users').nrows, 41) self.assertEqual(book.sheet_by_name('Initiatives').nrows, 5) self.assertEqual(book.sheet_by_name('Funding activities').nrows, 5) self.assertEqual(book.sheet_by_name('Events').nrows, 13) self.assertEqual( book.sheet_by_name('Events').cell(0, 13).value, 'Start') self.assertEqual( book.sheet_by_name('Events').cell(0, 14).value, 'Time needed') self.assertEqual(book.sheet_by_name('Tasks').nrows, 9) self.assertEqual( book.sheet_by_name('Tasks').cell(0, 16).value, 'Preparation time') self.assertEqual( book.sheet_by_name('Tasks').cell(0, 17).value, 'Start time') self.assertEqual( book.sheet_by_name('Tasks').cell(0, 19).value, 'End date')
def test_activities_from_homepage(self): EventFactory.create_batch(10, status='open', highlight=True) ActivitiesContent.objects.create_for_placeholder(self.placeholder, highlighted=True) response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertEqual(response.data['blocks'][0]['type'], 'activities') self.assertEqual(len(response.data['blocks'][0]['activities']), 4)
def test_details_offline(self): event = EventFactory( is_online=False ) self.assertEqual( event.details, "{}\n{}".format( event.description, event.get_absolute_url(), ) )
def setUp(self): self.initiative = InitiativeFactory.create() self.initiative.states.submit() self.initiative.states.approve(save=True) self.event = EventFactory.create(initiative=self.initiative, capacity=10, duration=1) self.passed_event = EventFactory.create(initiative=self.initiative, start=timezone.now() - timedelta(days=1), duration=1)
def test_details_no_url(self): event = EventFactory( is_online=True, online_meeting_url='' ) self.assertEqual( event.details, "{}\n{}".format( event.description, event.get_absolute_url(), ) )
def test_details(self): event = EventFactory( is_online=True ) self.assertEqual( event.details, "{}\n{}\nJoin: {}".format( event.description, event.get_absolute_url(), event.online_meeting_url ) )
def test_filter_owner(self): EventFactory.create(owner=self.owner, status='open') EventFactory.create(status='open') response = self.client.get( self.url + '?filter[owner.id]={}'.format(self.owner.pk), user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 1) self.assertEqual( data['data'][0]['relationships']['owner']['data']['id'], str(self.owner.pk))
def test_limits(self): initiative = InitiativeFactory.create() EventFactory.create_batch( 7, status='open', initiative=initiative, ) response = self.client.get(self.url + '?page[size]=150', user=self.owner) self.assertEqual(len(response.json()['data']), 7) response = self.client.get(self.url + '?page[size]=3', user=self.owner) self.assertEqual(len(response.json()['data']), 3)
def test_search_segment_name(self): first = EventFactory.create(status='open', ) first.segments.add(SegmentFactory(name='Online Marketing')) EventFactory.create(status='open') response = self.client.get(self.url + '?filter[search]=marketing', user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 1) self.assertEqual(data['data'][0]['id'], str(first.pk))
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')
def test_sort_title(self): second = EventFactory.create(title='B: something else', status='open') first = EventFactory.create(title='A: something', status='open') third = EventFactory.create(title='C: More', status='open') response = self.client.get(self.url + '?sort=alphabetical', user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 3) self.assertEqual(data['data'][0]['id'], str(first.pk)) self.assertEqual(data['data'][1]['id'], str(second.pk)) self.assertEqual(data['data'][2]['id'], str(third.pk))
def test_initiative_location(self): location = LocationFactory.create() initiative = InitiativeFactory.create(status='open', location=location) activity = EventFactory.create(status='open', initiative=initiative) EventFactory.create(status='open') response = self.client.get( self.url + '?filter[initiative_location.id]={}'.format(location.pk), user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 1) self.assertEqual(data['data'][0]['id'], str(activity.pk))
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)
def test_search_initiative_title(self): first = EventFactory.create( initiative=InitiativeFactory.create(title='Test title'), status='open') second = EventFactory.create(title='Test title', status='open') EventFactory.create(status='open') response = self.client.get(self.url + '?filter[search]=test title', 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))
def test_search(self): first = EventFactory.create(title='Lorem ipsum dolor sit amet', description="Lorem ipsum", status='open') second = EventFactory.create(title='Lorem ipsum dolor sit amet', status='open') response = self.client.get(self.url + '?filter[search]=lorem ipsum', user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 2) self.assertEqual(data['data'][0]['id'], str(first.pk)) self.assertEqual(data['data'][1]['id'], str(second.pk))
def test_get_activities(self): event = EventFactory.create(initiative=self.initiative, image=ImageFactory.create()) response = self.client.get(self.url, user=self.owner) data = response.json()['data'] self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(data['relationships']['activities']['data']), 1) self.assertEqual(data['relationships']['activities']['data'][0]['id'], str(event.pk)) self.assertEqual( data['relationships']['activities']['data'][0]['type'], 'activities/events') activity_data = get_include(response, 'activities/events') self.assertEqual(activity_data['attributes']['title'], event.title) self.assertEqual(activity_data['type'], 'activities/events') activity_location = activity_data['relationships']['location']['data'] self.assertTrue(activity_location in ({ 'type': included['type'], 'id': included['id'] } for included in response.json()['included'])) activity_image = activity_data['relationships']['image']['data'] self.assertTrue(activity_image in ({ 'type': included['type'], 'id': included['id'] } for included in response.json()['included']))
def test_sort_activity_date(self): first = EventFactory.create(status='open', start=now() + timedelta(days=10)) second = EventFactory.create(status='open', start=now() + timedelta(days=9)) third = EventFactory.create(status='open', start=now() + timedelta(days=11)) response = self.client.get(self.url + '?sort=date', 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(first.pk)) self.assertEqual(data['data'][2]['id'], str(second.pk))
def test_delete_segment(self): activity = EventFactory.create(owner=self.user) self.team.delete() self.assertTrue(self.unit in activity.segments.all()) self.assertFalse(self.team in activity.segments.all())
def test_search_formatted_address(self): location = GeolocationFactory.create( formatted_address='Roggeveenstraat') first = EventFactory.create(location=location, status='open') second = EventFactory.create(title='Roggeveenstraat', status='open') EventFactory.create(status='open') response = self.client.get(self.url + '?filter[search]=Roggeveenstraat', 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))
def test_filter_segment_mismatch(self): first = EventFactory.create(status='open', ) first_segment = SegmentFactory.create() first.segments.add(first_segment) second_segment = SegmentFactory.create() first.segments.add(second_segment) EventFactory.create(status='open') response = self.client.get(self.url + '?filter[segment.{}]={}'.format( first_segment.type.slug, second_segment.pk), user=self.owner) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 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)
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)
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, ))
def setUp(self): super(ImpactGoalListAPITestCase, self).setUp() self.client = JSONAPITestClient() self.activity = EventFactory.create() self.type = ImpactTypeFactory.create() self.url = reverse('impact-goal-list') self.data = { 'data': { 'type': 'activities/impact-goals', 'attributes': { 'target': 1.5 }, 'relationships': { 'activity': { 'data': { 'type': 'activities/events', 'id': self.activity.pk }, }, 'type': { 'data': { 'type': 'activities/impact-types', 'id': self.type.pk }, } } } }
def setUp(self): super(WallpostReactionApiIntegrationTest, self).setUp() self.manager = BlueBottleUserFactory.create() self.manager_token = "JWT {0}".format( self.manager.get_jwt_token()) self.event = EventFactory.create(owner=self.manager) self.some_wallpost = TextWallpostFactory.create(content_object=self.event) self.another_wallpost = TextWallpostFactory.create() self.some_user = BlueBottleUserFactory.create( password='******', first_name='someName', last_name='someLast') self.some_token = "JWT {0}".format(self.some_user.get_jwt_token()) self.another_user = BlueBottleUserFactory.create( password='******', first_name='anotherName', last_name='anotherLast') self.another_token = "JWT {0}".format( self.another_user.get_jwt_token()) self.wallpost_reaction_url = reverse('wallpost_reaction_list') self.wallpost_url = reverse('wallpost_list') self.text_wallpost_url = reverse('text_wallpost_list') response = self.client.post( self.wallpost_reaction_url, { 'text': 'Dit is een test', 'wallpost': self.some_wallpost.id }, token=self.some_token ) self.reaction_detail_url = reverse('wallpost_reaction_detail', kwargs={'pk': response.data['id']})