def test_create_rsvp(self): data = self.APPLICATION_DATA data['study_group'] = StudyGroup.objects.get(pk=1) application = Application(**data) application.save() sg = StudyGroup.objects.get(pk=1) meeting_date = timezone.now() sgm = Meeting(study_group=sg, meeting_time=meeting_date.time(), meeting_date=meeting_date.date()) sgm.save() sgm = Meeting(study_group=sg, meeting_time=meeting_date.time(), meeting_date=meeting_date.date() + datetime.timedelta(weeks=1)) sgm.save() # Test creating an RSVP self.assertEqual(Rsvp.objects.all().count(), 0) create_rsvp('*****@*****.**', sg.id, meeting_date, 'yes') self.assertEqual(Rsvp.objects.all().count(), 1) self.assertTrue(Rsvp.objects.all().first().attending) # Test updating an RSVP create_rsvp('*****@*****.**', sg.id, meeting_date, 'no') self.assertEqual(Rsvp.objects.all().count(), 1) self.assertFalse(Rsvp.objects.all().first().attending)
def test_rsvp_view(self): # Setup data for RSVP -> StudyGroup + Signup + Meeting in future c = Client() study_group = StudyGroup.objects.get(pk=1) meeting_time = timezone.now() + datetime.timedelta(days=2) study_group_meeting = Meeting(study_group=study_group, meeting_time=meeting_time.time(), meeting_date=meeting_time.date()) study_group_meeting.save() signup_data = self.APPLICATION_DATA.copy() resp = c.post('/en/signup/foo-bob-1/', signup_data) self.assertRedirects(resp, '/en/signup/1/success/') self.assertEqual(Application.objects.active().count(), 1) qs = gen_rsvp_querystring(signup_data['email'], study_group.pk, study_group_meeting.meeting_datetime(), 'yes') url = '/en/rsvp/?{0}'.format(qs) # Generate RSVP link # visit link self.assertEqual(0, Rsvp.objects.count()) resp = c.get(url) self.assertEqual(1, Rsvp.objects.count()) self.assertTrue(Rsvp.objects.first().attending) qs = gen_rsvp_querystring(signup_data['email'], study_group.pk, study_group_meeting.meeting_datetime(), 'no') url = '/en/rsvp/?{0}'.format(qs) self.assertEqual(1, Rsvp.objects.count()) resp = c.get(url) self.assertEqual(1, Rsvp.objects.count()) self.assertFalse(Rsvp.objects.first().attending) # Test RSVP with mobile number signup_data = self.APPLICATION_DATA.copy() signup_data['email'] = '*****@*****.**' signup_data['mobile'] = '+12812347890' resp = c.post('/en/signup/foo-bob-1/', signup_data) self.assertRedirects(resp, '/en/signup/1/success/') self.assertEqual(Application.objects.active().count(), 2) qs = gen_rsvp_querystring(signup_data['mobile'], study_group.pk, study_group_meeting.meeting_datetime(), 'yes') url = '/en/rsvp/?{0}'.format(qs) # Generate RSVP link # visit link c = Client() Rsvp.objects.all().delete() self.assertEqual(0, Rsvp.objects.count()) resp = c.get(url) self.assertEqual(1, Rsvp.objects.count()) self.assertTrue(Rsvp.objects.first().attending)
def test_receive_sms_rsvp(self): signup_data = self.APPLICATION_DATA.copy() signup_data['mobile'] = '+12812347890' c = Client() resp = c.post('/en/signup/foo-bob-1/', signup_data) self.assertRedirects(resp, '/en/signup/1/success/') self.assertEqual(Application.objects.active().count(), 1) mail.outbox = [] next_meeting = Meeting() next_meeting.study_group = StudyGroup.objects.get( pk=signup_data['study_group']) next_meeting.meeting_time = (timezone.now() + datetime.timedelta(days=1)).time() next_meeting.meeting_date = timezone.now().date() + datetime.timedelta( days=1) next_meeting.save() url = '/en/receive_sms/' sms_data = { 'Body': 'Sorry, I won\'t make it, have family responsibilities this week :(', 'From': '+12812347890' } resp = c.post(url, sms_data) self.assertEqual(len(mail.outbox), 1) self.assertTrue(mail.outbox[0].subject.find('+12812347890') > 0) self.assertTrue(mail.outbox[0].subject.find('Test User') > 0) self.assertIn( StudyGroup.objects.get(pk=1).facilitator.email, mail.outbox[0].to) self.assertIn( '{0}/{1}/rsvp/?user=%2B12812347890&study_group=1&meeting_date={2}&attending=yes&sig=' .format( settings.DOMAIN, get_language(), urllib.parse.quote( next_meeting.meeting_datetime().isoformat())), mail.outbox[0].body) self.assertIn( '{0}/{1}/rsvp/?user=%2B12812347890&study_group=1&meeting_date={2}&attending=no&sig=' .format( settings.DOMAIN, get_language(), urllib.parse.quote( next_meeting.meeting_datetime().isoformat())), mail.outbox[0].body)
def setUp(self): with patch('custom_registration.signals.send_email_confirm_email'): user = create_user('*****@*****.**', 'b', 't', 'password', False) user.save() self.facilitator = user sg = StudyGroup.objects.get(pk=1) sg.facilitator = user sg.save() meeting = Meeting() meeting.study_group = sg meeting.meeting_time = timezone.now().time() meeting.meeting_date = timezone.now().date() - datetime.timedelta( days=1) meeting.save() self.meeting = meeting
def test_weekly_report(self): organizer = create_user('*****@*****.**', 'organ', 'test', 'password', False) faci1 = create_user('*****@*****.**', 'faci1', 'test', 'password', False) StudyGroup.objects.filter(pk=1).update(facilitator=faci1) StudyGroup.objects.filter(pk=3).update(facilitator=faci1) StudyGroup.objects.filter(pk=3).update(deleted_at=timezone.now()) team = Team.objects.create(name='test team') TeamMembership.objects.create(team=team, user=organizer, role=TeamMembership.ORGANIZER) TeamMembership.objects.create(team=team, user=faci1, role=TeamMembership.MEMBER) study_group = StudyGroup.objects.get(pk=1) active_meeting = Meeting.objects.create( study_group=study_group, meeting_time=datetime.time(16, 0), meeting_date=datetime.date(2016, 11, 24) # Thursday ) study_group = StudyGroup.objects.get(pk=2) meeting = Meeting() meeting.study_group = study_group meeting.meeting_time = datetime.time(16, 0) meeting.meeting_date = datetime.date(2016, 11, 25) # Thursday meeting.save() Meeting.objects.create( study_group=StudyGroup.objects.get(pk=3), meeting_time=datetime.time(16, 0), meeting_date=datetime.date(2016, 11, 21) # Monday ) c = Client() c.login(username='******', password='******') resp = c.get('/en/report/weekly/{0}/'.format( datetime.date(2016, 11, 21).strftime("%Y-%m-%d"))) self.assertEqual(resp.status_code, 200) self.assertEqual(len(resp.context['meetings']), 1) self.assertEqual(resp.context['meetings'][0].pk, active_meeting.pk)
def test_feedback_submit(self): organizer = User.objects.create_user('*****@*****.**', '*****@*****.**', '1234') faci1 = User.objects.create_user('*****@*****.**', '*****@*****.**', '1234') StudyGroup.objects.filter(pk=1).update(facilitator=faci1) # create team team = Team.objects.create(name='test team') TeamMembership.objects.create(team=team, user=organizer, role=TeamMembership.ORGANIZER) TeamMembership.objects.create(team=team, user=faci1, role=TeamMembership.MEMBER) c = Client() c.login(username='******', password='******') study_group = StudyGroup.objects.get(pk=1) meeting = Meeting() meeting.study_group = study_group meeting.meeting_time = timezone.now().time() meeting.meeting_date = timezone.now().date() - datetime.timedelta( days=1) meeting.save() feedback_data = { 'study_group_meeting': '{0}'.format(meeting.id), 'feedback': 'Test some feedback', 'reflection': 'Please help me', 'attendance': '9', 'rating': '5', } feedback_url = '/en/studygroup/1/meeting/{0}/feedback/create/'.format( meeting.id) self.assertEqual(len(mail.outbox), 0) resp = c.post(feedback_url, feedback_data) self.assertEqual(resp.status_code, 302) # make sure email was sent to organizers self.assertEqual(len(mail.outbox), 1) self.assertEqual( Feedback.objects.filter(study_group_meeting=meeting).count(), 1)
def test_dont_send_weekly_report(self): organizer = User.objects.create_user('*****@*****.**', '*****@*****.**', 'password') faci1 = User.objects.create_user('*****@*****.**', '*****@*****.**', 'password') StudyGroup.objects.filter(pk=1).update(facilitator=faci1) team = Team.objects.create(name='test team') TeamMembership.objects.create(team=team, user=organizer, role=TeamMembership.ORGANIZER) TeamMembership.objects.create(team=team, user=faci1, role=TeamMembership.MEMBER) study_group = StudyGroup.objects.get(pk=1) meeting = Meeting() meeting.study_group = study_group meeting.meeting_time = datetime.time(9) meeting.meeting_date = datetime.date(2018, 8, 14) meeting.save() study_group = StudyGroup.objects.get(pk=2) meeting = Meeting() meeting.study_group = study_group meeting.meeting_time = datetime.time(9) meeting.meeting_date = datetime.date(2018, 8, 14) meeting.save() with freeze_time("2018-08-28 10:01:00"): send_weekly_update() self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to[0], '*****@*****.**')