Example #1
0
    def test_dont_send_weekly_report(self):
        organizer = create_user('*****@*****.**', 'organ', 'test', '1234',
                                False)
        faci1 = create_user('*****@*****.**', 'faci', 'test', 'password',
                            False)
        StudyGroup.objects.filter(pk=1).update(facilitator=faci1)
        mail.outbox = []

        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], '*****@*****.**')
Example #2
0
    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
Example #3
0
    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_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 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)