예제 #1
0
 def test_get_last_report_future(self):
     past_date = now().date() - timedelta(weeks=5)
     future_date = now().date() + timedelta(weeks=2)
     user = UserFactory.create(groups=['Rep'])
     NGReportFactory.create(user=user, report_date=past_date)
     NGReportFactory.create(user=user, report_date=future_date)
     eq_(get_last_report(user).report_date, past_date)
예제 #2
0
    def test_longest_streak(self, mocked_date):
        """Update current and longest streak counters when the fourth
        report out of five is deleted.
        """

        mocked_date.return_value = datetime.date(2011, 01, 29)
        user = UserFactory.create()
        up = user.userprofile
        start_date = datetime.date(2011, 01, 01)
        end_date = datetime.date(2011, 01, 29)
        # Create 5 reports
        for i in range(0, 5):
            NGReportFactory.create(
                user=user,
                report_date=end_date - datetime.timedelta(weeks=i))

        eq_(up.current_streak_start, start_date)
        eq_(up.longest_streak_start, start_date)
        eq_(up.longest_streak_end, end_date)

        # Delete the report that the user submitted on 22-01-2012
        NGReport.objects.filter(
            user=user,
            report_date=datetime.date(2011, 01, 22)).delete()

        user = User.objects.get(pk=user.id)
        up = user.userprofile
        eq_(up.current_streak_start, end_date)
        eq_(up.longest_streak_start, start_date)
        eq_(up.longest_streak_end, datetime.date(2011, 01, 15))
예제 #3
0
    def test_old_report_redirect(self):
        """Test old report url redirects to list of reports for that month."""
        user = UserFactory.create(groups=['Rep'])
        report_date = datetime.date(2011, 01, 05)
        NGReportFactory.create_batch(3, user=user, report_date=report_date)

        display_name = user.userprofile.display_name
        url = reverse('reports_ng_view_report',
                      kwargs={
                          'display_name': display_name,
                          'month': 'January',
                          'year': 2011
                      })
        response = Client().get(url, follow=True)
        expected_redirect_url = '/reports/rep/{}/'.format(display_name)

        self.assertEqual(response.status_code, 200)
        redirect_full_url, redirect_code = response.redirect_chain[0]
        self.assertEqual(redirect_code, 302)

        redirect_url, redirect_params = redirect_full_url.split('?')

        self.assertEqual(response.status_code, 200)
        self.assertTrue(redirect_url.endswith(expected_redirect_url))
        self.assertEqual(set(redirect_params.split('&')),
                         set(['year=2011', 'month=January']))
        eq_(response.context['number_of_reports'], 3)
예제 #4
0
파일: test_util.py 프로젝트: flaki/remo
 def test_get_last_ten_weeks_reports(self):
     user = UserFactory.create()
     # Add 4 reports more than a day apart
     for i in range(8, 0, -2):
         NGReportFactory.create(user=user, report_date=(now().date() - timedelta(days=i)))
     # Get the reports added in the last 10 weeks
     eq_(count_user_ng_reports(user, period=10), 4)
예제 #5
0
    def test_with_no_report_filled_and_one_notification(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = now().date()
        rep = UserFactory.create(groups=['Rep'],
                                 userprofile__mentor=mentor,
                                 userprofile__first_report_notification=today -
                                 timedelta(weeks=4))
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=9))

        rep_subject = '[Reminder] Please share your recent activities'
        mentor_subject = '[Report] Mentee without report for the last 8 weeks'

        with patch('remo.reports.utils.send_remo_mail') as mail_mock:
            send_second_report_notification()

        eq_(mail_mock.call_count, 2)
        expected_call_list = [
            call(rep_subject, [rep.email],
                 message=mockany,
                 headers={'Reply-To': mentor.email}),
            call(mentor_subject, [mentor.email],
                 message=mockany,
                 headers={'Reply-To': rep.email})
        ]
        eq_(mail_mock.call_args_list, expected_call_list)
예제 #6
0
파일: test_util.py 프로젝트: flaki/remo
 def test_get_last_report_future(self):
     past_date = now().date() - timedelta(weeks=5)
     future_date = now().date() + timedelta(weeks=2)
     user = UserFactory.create(groups=["Rep"])
     NGReportFactory.create(user=user, report_date=past_date)
     NGReportFactory.create(user=user, report_date=future_date)
     eq_(get_last_report(user).report_date, past_date)
예제 #7
0
    def test_base(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = now().date()
        rep = UserFactory.create(
            groups=['Rep'],
            userprofile__mentor=mentor,
            userprofile__date_joined_program=get_date(days=-100))
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=5))

        rep_subject = '[Reminder] Please share your recent activities'
        mentor_subject = '[Report] Mentee without report for the last 4 weeks'

        with patch('remo.reports.utils.send_remo_mail') as mail_mock:
            send_first_report_notification()

        eq_(mail_mock.call_count, 2)
        expected_call_list = [
            call(subject=rep_subject,
                 recipients_list=[rep.email],
                 message=mockany,
                 sender=mentor.email),
            call(subject=mentor_subject,
                 recipients_list=[mentor.email],
                 message=mockany,
                 sender=rep.email)
        ]
        eq_(mail_mock.call_args_list, expected_call_list)
예제 #8
0
    def test_longest_streak(self, mocked_date):
        """Update current and longest streak counters when the fourth
        report out of five is deleted.
        """

        mocked_date.return_value = datetime.date(2011, 1, 29)
        user = UserFactory.create()
        up = user.userprofile
        start_date = datetime.date(2011, 1, 1)
        end_date = datetime.date(2011, 1, 29)
        # Create 5 reports
        for i in range(0, 5):
            NGReportFactory.create(user=user,
                                   report_date=end_date -
                                   datetime.timedelta(weeks=i))

        eq_(up.current_streak_start, start_date)
        eq_(up.longest_streak_start, start_date)
        eq_(up.longest_streak_end, end_date)

        # Delete the report that the user submitted on 22-01-2012
        NGReport.objects.filter(user=user,
                                report_date=datetime.date(2011, 1,
                                                          22)).delete()

        user = User.objects.get(pk=user.id)
        up = user.userprofile
        eq_(up.current_streak_start, end_date)
        eq_(up.longest_streak_start, start_date)
        eq_(up.longest_streak_end, datetime.date(2011, 1, 15))
예제 #9
0
    def test_old_report_redirect(self):
        """Test old report url redirects to list of reports for that month."""
        user = UserFactory.create(groups=['Rep'])
        report_date = datetime.date(2011, 01, 05)
        NGReportFactory.create_batch(3, user=user, report_date=report_date)

        display_name = user.userprofile.display_name
        url = reverse('reports_ng_view_report',
                      kwargs={'display_name': display_name,
                              'month': 'January',
                              'year': 2011})
        response = Client().get(url, follow=True)
        expected_redirect_url = '/reports/rep/{}/'.format(display_name)

        self.assertEqual(response.status_code, 200)
        redirect_full_url, redirect_code = response.redirect_chain[0]
        self.assertEqual(redirect_code, 302)

        redirect_url, redirect_params = redirect_full_url.split('?')

        self.assertEqual(response.status_code, 200)
        self.assertTrue(redirect_url.endswith(expected_redirect_url))
        self.assertEqual(set(redirect_params.split('&')),
                         set(['year=2011', 'month=January']))
        eq_(response.context['number_of_reports'], 3)
예제 #10
0
파일: test_util.py 프로젝트: SamBlake1/remo
 def test_current_streak(self):
     user = UserFactory.create()
     # Add a report every 22 hours for the last 4 days (5 reports)
     for i in range(0, 4):
         NGReportFactory.create(user=user,
                                report_date=(now().date() -
                                             timedelta(days=i)))
     eq_(count_user_ng_reports(user, current_streak=True), 4)
예제 #11
0
 def test_current_streak(self):
     user = UserFactory.create()
     # Add a report every 22 hours for the last 4 days (5 reports)
     for i in range(0, 4):
         NGReportFactory.create(user=user,
                                report_date=(now().date() -
                                             timedelta(days=i)))
     eq_(count_user_ng_reports(user, current_streak=True), 4)
예제 #12
0
    def test_current_streak_counter_with_past_reports(self):
        past_day = now().date() - datetime.timedelta(days=30)

        user = UserFactory.create()
        for i in range(0, 5):
            NGReportFactory.create(user=user, report_date=past_day - datetime.timedelta(days=i))

        ok_(not user.userprofile.current_streak_start)
예제 #13
0
    def test_no_current_streak(self):
        user = UserFactory.create(groups=['Rep'])
        for i in range(4):
            report_date = date(2011, 01, 01) + timedelta(weeks=i)
            NGReportFactory.create(user=user, report_date=report_date)

        calculate_longest_streaks()
        eq_(user.userprofile.longest_streak_start, date(2011, 01, 01))
        eq_(user.userprofile.longest_streak_end, date(2011, 01, 22))
예제 #14
0
 def test_functional_area_list(self):
     functional_area_1 = FunctionalAreaFactory.create()
     functional_area_2 = FunctionalAreaFactory.create()
     report = NGReportFactory.create(functional_areas=[functional_area_1])
     NGReportFactory.create(functional_areas=[functional_area_2])
     url = reverse('list_ng_reports_functional_area',
                   kwargs={'functional_area_slug': functional_area_1.slug})
     response = self.get(url=url)
     eq_(set(response.context['objects'].object_list), set([report]))
예제 #15
0
    def test_with_report_filled(self):
        mentor = UserFactory.create(groups=["Mentor"])
        today = now().date()
        rep = UserFactory.create(groups=["Rep"], userprofile__mentor=mentor)
        NGReportFactory.create(user=rep, report_date=today - timedelta(weeks=2))

        with patch("remo.reports.utils.send_remo_mail") as mail_mock:
            send_second_report_notification()
        ok_(not mail_mock.called)
예제 #16
0
    def test_no_current_streak(self):
        user = UserFactory.create(groups=['Rep'])
        for i in range(4):
            report_date = date(2011, 1, 1) + timedelta(weeks=i)
            NGReportFactory.create(user=user, report_date=report_date)

        calculate_longest_streaks()
        eq_(user.userprofile.longest_streak_start, date(2011, 1, 1))
        eq_(user.userprofile.longest_streak_end, date(2011, 1, 22))
예제 #17
0
 def test_get_last_ten_weeks_reports(self):
     user = UserFactory.create()
     # Add 4 reports more than a day apart
     for i in range(8, 0, -2):
         NGReportFactory.create(user=user,
                                report_date=(now().date() -
                                             timedelta(days=i)))
     # Get the reports added in the last 10 weeks
     eq_(count_user_ng_reports(user, period=10), 4)
예제 #18
0
 def test_functional_area_list(self):
     functional_area_1 = FunctionalAreaFactory.create()
     functional_area_2 = FunctionalAreaFactory.create()
     report = NGReportFactory.create(functional_areas=[functional_area_1])
     NGReportFactory.create(functional_areas=[functional_area_2])
     url = reverse('list_ng_reports_functional_area',
                   kwargs={'functional_area_slug': functional_area_1.slug})
     response = Client().get(url)
     eq_(set(response.context['objects'].object_list), set([report]))
예제 #19
0
    def test_with_report_filled(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = now().date()
        rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor)
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=2))

        with patch('remo.reports.utils.send_remo_mail') as mail_mock:
            send_second_report_notification()
        ok_(not mail_mock.called)
예제 #20
0
    def test_current_longest_streak(self):
        today = now().date()
        user = UserFactory.create()

        for i in range(0, 2):
            NGReportFactory.create(user=user, report_date=today - datetime.timedelta(days=i))

        eq_(user.userprofile.current_streak_start, today - datetime.timedelta(days=1))
        eq_(user.userprofile.longest_streak_start, today - datetime.timedelta(days=1))
        eq_(user.userprofile.longest_streak_end, today)
예제 #21
0
    def test_current_streak_counter_with_past_reports(self):
        past_day = now().date() - datetime.timedelta(days=30)

        user = UserFactory.create()
        for i in range(0, 5):
            NGReportFactory.create(user=user,
                                   report_date=past_day -
                                   datetime.timedelta(days=i))

        ok_(not user.userprofile.current_streak_start)
예제 #22
0
 def test_mentor_functional_area_list(self):
     mentor = UserFactory.create(groups=['Mentor'])
     functional_area = FunctionalAreaFactory.create()
     report = NGReportFactory.create(mentor=mentor, functional_areas=[functional_area])
     NGReportFactory.create(functional_areas=[functional_area])
     url = reverse('list_ng_reports_mentor_functional_area',
                   kwargs={'functional_area_slug': functional_area.slug,
                           'mentor': mentor.userprofile.display_name})
     response = Client().get(url)
     eq_(set(response.context['objects'].object_list), set([report]))
예제 #23
0
    def test_base(self):
        past_day = get_date(-8)
        user = UserFactory.create(groups=['Rep'])
        NGReportFactory.create(user=user, report_date=past_day)
        user.userprofile.current_streak_start = past_day
        user.userprofile.save()

        zero_current_streak()
        user = User.objects.get(pk=user.id)

        ok_(not user.userprofile.current_streak_start)
예제 #24
0
    def test_user_new_future_activity(self):
        report_notification = now().date() - datetime.timedelta(weeks=3)
        new_report_date = now().date() + datetime.timedelta(weeks=6)

        rep = UserFactory.create(
            groups=['Rep'],
            userprofile__first_report_notification=report_notification)
        NGReportFactory.create(user=rep, report_date=new_report_date)

        user = User.objects.get(pk=rep.id)
        eq_(user.userprofile.first_report_notification, report_notification)
예제 #25
0
 def test_rep_functional_area_list(self):
     user = UserFactory.create(groups=['Rep'])
     functional_area = FunctionalAreaFactory.create()
     report = NGReportFactory.create(user=user,
                                     functional_areas=[functional_area])
     NGReportFactory.create(functional_areas=[functional_area])
     url = reverse('list_ng_reports_rep_functional_area',
                   kwargs={'functional_area_slug': functional_area.slug,
                           'rep': user.userprofile.display_name})
     response = self.get(url=url)
     eq_(set(response.context['reports'].object_list), set([report]))
예제 #26
0
파일: test_util.py 프로젝트: flaki/remo
    def test_longest_streak(self):
        user = UserFactory.create()
        past_day = now().date() - timedelta(days=30)
        # Add 7 continuous reports somewhere in the past
        for i in range(0, 7):
            NGReportFactory.create(user=user, report_date=(past_day - timedelta(days=i)))

        # Add a report, one each day for the last 4 days (6 reports)
        for i in range(0, 3):
            NGReportFactory.create(user=user, report_date=(now().date() - timedelta(days=i)))
        eq_(count_user_ng_reports(user, longest_streak=True), 7)
예제 #27
0
    def test_base(self):
        past_day = get_date(-8)
        user = UserFactory.create(groups=['Rep'])
        NGReportFactory.create(user=user, report_date=past_day)
        user.userprofile.current_streak_start = past_day
        user.userprofile.save()

        zero_current_streak()
        user = User.objects.get(pk=user.id)

        ok_(not user.userprofile.current_streak_start)
예제 #28
0
    def test_with_no_report_filled_and_one_notification(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = datetime.utcnow().date()
        rep = UserFactory.create(
            groups=['Rep'], userprofile__mentor=mentor,
            userprofile__last_report_notification=today - timedelta(weeks=1))
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=2))

        with patch('remo.reports.tasks.send_mail') as send_mail_mock:
            send_ng_report_notification()
        ok_(not send_mail_mock.called)
예제 #29
0
    def test_user_new_future_activity(self):
        report_notification = now().date() - datetime.timedelta(weeks=3)
        new_report_date = now().date() + datetime.timedelta(weeks=6)

        rep = UserFactory.create(
            groups=['Rep'],
            userprofile__first_report_notification=report_notification
        )
        NGReportFactory.create(user=rep, report_date=new_report_date)

        user = User.objects.get(pk=rep.id)
        eq_(user.userprofile.first_report_notification, report_notification)
예제 #30
0
 def test_list_rep(self):
     """Test page header context for rep."""
     user = UserFactory.create(groups=['Rep'], first_name='Foo', last_name='Bar')
     name = user.userprofile.display_name
     report = NGReportFactory.create(user=user)
     NGReportFactory.create()
     with self.login(user) as client:
         response = client.get(reverse('list_ng_reports_rep', kwargs={'rep': name}),
                               user=user)
     eq_(response.context['pageheader'], 'Activities for Foo Bar')
     eq_(set(response.context['objects'].object_list),
         set([report]), 'Other Rep reports are listed')
예제 #31
0
 def test_mentor_functional_area_list(self):
     mentor = UserFactory.create(groups=['Mentor'])
     functional_area = FunctionalAreaFactory.create()
     report = NGReportFactory.create(mentor=mentor,
                                     functional_areas=[functional_area])
     NGReportFactory.create(functional_areas=[functional_area])
     url = reverse('list_ng_reports_mentor_functional_area',
                   kwargs={
                       'functional_area_slug': functional_area.slug,
                       'mentor': mentor.userprofile.display_name
                   })
     response = self.get(url=url)
     eq_(set(response.context['objects'].object_list), set([report]))
예제 #32
0
    def test_with_user_unavailable(self):
        mentor = UserFactory.create(groups=["Mentor"])
        today = now().date()
        rep = UserFactory.create(
            groups=["Rep"], userprofile__mentor=mentor, userprofile__date_joined_program=get_date(days=-100)
        )
        UserStatusFactory.create(user=rep)
        NGReportFactory.create(user=rep, report_date=today - timedelta(weeks=5))

        with patch("remo.reports.utils.send_remo_mail") as mail_mock:
            send_first_report_notification()

        ok_(not mail_mock.called)
예제 #33
0
    def test_with_report_filled(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = datetime.utcnow().date()
        rep = UserFactory.create(groups=['Rep'],
                                 userprofile__mentor=mentor,
                                 userprofile__last_report_notification=today -
                                 timedelta(weeks=4))
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=2))

        with patch('remo.reports.tasks.send_mail') as send_mail_mock:
            send_ng_report_notification()
        ok_(not send_mail_mock.called)
예제 #34
0
 def test_rep_functional_area_list(self):
     user = UserFactory.create(groups=['Rep'])
     functional_area = FunctionalAreaFactory.create()
     report = NGReportFactory.create(user=user,
                                     functional_areas=[functional_area])
     NGReportFactory.create(functional_areas=[functional_area])
     url = reverse('list_ng_reports_rep_functional_area',
                   kwargs={
                       'functional_area_slug': functional_area.slug,
                       'rep': user.userprofile.display_name
                   })
     response = Client().get(url)
     eq_(set(response.context['objects'].object_list), set([report]))
예제 #35
0
 def test_longest_streak(self):
     user = UserFactory.create()
     past_day = utc_now().date() - timedelta(days=30)
     # Add 7 continuous reports somewhere in the past
     for i in range(7, 0, -1):
         NGReportFactory.create(user=user,
                                report_date=(past_day - timedelta(days=i)))
     # Add a report, one each day for the last 4 days (5 reports)
     for i in range(6, 0, -1):
         NGReportFactory.create(user=user,
                                report_date=(utc_now().date() -
                                             timedelta(days=i)))
     eq_(count_user_ng_reports(user, longest_streak=True), 7)
예제 #36
0
    def test_with_user_unavailable(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = now().date()
        rep = UserFactory.create(
            groups=['Rep'], userprofile__mentor=mentor,
            userprofile__date_joined_program=get_date(days=-100),
            userprofile__is_unavailable=True)
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=5))

        with patch('remo.reports.utils.send_remo_mail') as mail_mock:
            send_first_report_notification()

        ok_(not mail_mock.called)
예제 #37
0
 def test_list_rep(self):
     """Test page header context for rep."""
     user = UserFactory.create(groups=['Rep'],
                               first_name='Foo',
                               last_name='Bar')
     name = user.userprofile.display_name
     report = NGReportFactory.create(user=user)
     NGReportFactory.create()
     response = self.get(url=reverse('list_ng_reports_rep',
                                     kwargs={'rep': name}),
                         user=user)
     eq_(response.context['pageheader'], 'Activities for Foo Bar')
     eq_(set(response.context['objects'].object_list), set([report]),
         'Other Rep reports are listed')
예제 #38
0
    def test_with_alumnus_mentor(self):
        mentor = UserFactory.create(groups=["Mentor", "Alumni"])
        today = now().date()
        rep = UserFactory.create(groups=["Rep"], userprofile__date_joined_program=get_date(days=-100))
        NGReportFactory.create(user=rep, mentor=mentor, report_date=today - timedelta(weeks=5))

        rep_subject = "[Reminder] Please share your recent activities"

        with patch("remo.reports.utils.send_remo_mail") as mail_mock:
            send_first_report_notification()

        eq_(mail_mock.call_count, 1)
        expected_call_list = [call(rep_subject, [rep.email], message=mockany)]
        eq_(mail_mock.call_args_list, expected_call_list)
예제 #39
0
    def test_current_longest_streak(self):
        today = now().date()
        user = UserFactory.create()

        for i in range(0, 2):
            NGReportFactory.create(user=user,
                                   report_date=today -
                                   datetime.timedelta(days=i))

        eq_(user.userprofile.current_streak_start,
            today - datetime.timedelta(days=1))
        eq_(user.userprofile.longest_streak_start,
            today - datetime.timedelta(days=1))
        eq_(user.userprofile.longest_streak_end, today)
예제 #40
0
    def test_base(self):
        mentor_1 = UserFactory.create(groups=['Mentor'])
        NGReportFactory.create_batch(2, mentor=mentor_1)
        NGReport.objects.update(created_on=date(2014, 1, 1))
        UserFactory.create(groups=['Mentor'])

        with patch('remo.reports.tasks.datetime') as datetime_mock:
            datetime_mock.utcnow().date.return_value = datetime(2014, 1, 1)
            with patch('remo.reports.tasks.send_mail') as send_mail_mock:
                with patch('remo.reports.tasks.DIGEST_SUBJECT', '{date}'):
                    send_report_digest()

        send_mail_mock.assert_called_with(
            'Wed 01 Jan 2014', mockany, settings.FROM_EMAIL, [mentor_1.email])
예제 #41
0
    def test_weeks(self, mock_api_now, mock_utils_now):
        now_return_value = datetime(2015, 3, 1)
        mock_api_now.return_value = now_return_value
        mock_utils_now.return_value = now_return_value

        # Current week
        report_date = date(2015, 2, 26)
        NGReportFactory.create_batch(3, report_date=report_date)

        # Week-1
        report_date = date(2015, 2, 18)
        NGReportFactory.create_batch(2, report_date=report_date)

        # Week-2
        report_date = date(2015, 2, 11)
        NGReportFactory.create_batch(4, report_date=report_date)

        # Week-3
        report_date = date(2015, 2, 4)
        NGReportFactory.create(report_date=report_date)

        # Next week
        report_date = date(2015, 3, 4)
        NGReportFactory.create(report_date=report_date)

        request = self.factory.get(self.url)
        request.query_params = {'weeks': 4}

        response = ActivitiesKPIView().get(request)
        eq_(response.data['week_total'], 3)
        eq_(response.data['week_growth_percentage'], (3 - 2) * 100 / 2.0)
        total_per_week = [{
            'week': 1,
            'activities': 1
        }, {
            'week': 2,
            'activities': 4
        }, {
            'week': 3,
            'activities': 2
        }, {
            'week': 4,
            'activities': 3
        }]

        for entry in response.data['total_per_week']:
            ok_(entry in total_per_week)

        eq_(len(response.data['total_per_week']), 4)
예제 #42
0
    def test_base(self):
        mentor_1 = UserFactory.create(groups=['Mentor'])
        NGReportFactory.create_batch(2, mentor=mentor_1)
        NGReport.objects.update(created_on=date(2014, 1, 1))
        UserFactory.create(groups=['Mentor'])

        with patch('remo.reports.tasks.datetime') as datetime_mock:
            datetime_mock.utcnow().date.return_value = datetime(2014, 1, 1)
            with patch('remo.reports.tasks.send_mail') as send_mail_mock:
                with patch('remo.reports.tasks.DIGEST_SUBJECT', '{date}'):
                    send_report_digest()

        send_mail_mock.assert_called_with('Wed 01 Jan 2014', mockany,
                                          settings.FROM_EMAIL,
                                          [mentor_1.email])
예제 #43
0
    def test_different_current_longest_streak(self):
        today = now().date()
        past_day = now().date() - datetime.timedelta(days=30)
        user = UserFactory.create()
        # longest streak
        for i in range(0, 3):
            NGReportFactory.create(user=user, report_date=past_day - datetime.timedelta(days=i))

        # current streak
        for i in range(0, 2):
            NGReportFactory.create(user=user, report_date=today - datetime.timedelta(days=i))

        eq_(user.userprofile.current_streak_start, today - datetime.timedelta(days=1))
        eq_(user.userprofile.longest_streak_start, past_day - datetime.timedelta(days=2))
        eq_(user.userprofile.longest_streak_end, past_day)
예제 #44
0
파일: test_views.py 프로젝트: Binzzzz/remo
    def test_old_report_redirect(self):
        """Test old report url redirects to list of reports for that month."""
        user = UserFactory.create(groups=['Rep'])
        report_date = datetime.date(2011, 01, 05)
        NGReportFactory.create_batch(3, user=user, report_date=report_date)

        display_name = user.userprofile.display_name
        url = reverse('reports_ng_view_report',
                      kwargs={'display_name': display_name,
                              'month': 'January',
                              'year': 2011})
        response = self.get(url, follow=True)
        redirect_url = '/reports/rep/%s/?year=2011&month=January'
        self.assertRedirects(response, redirect_url % display_name)
        eq_(response.context['number_of_reports'], 3)
예제 #45
0
    def test_list_mentor(self):
        """Test page header context for mentor."""
        mentor = UserFactory.create(groups=['Mentor'], first_name='Foo',
                                    last_name='Bar')
        name = mentor.userprofile.display_name

        report_1 = NGReportFactory.create(mentor=mentor)
        report_2 = NGReportFactory.create(mentor=mentor)
        NGReportFactory.create()
        response = Client().get(reverse('list_ng_reports_mentor',
                                        kwargs={'mentor': name}), user=mentor)
        msg = 'Activities for Reps mentored by Foo Bar'
        eq_(response.context['pageheader'], msg)
        eq_(set(response.context['objects'].object_list),
            set([report_1, report_2]), 'Other Mentor reports are listed')
예제 #46
0
    def test_comment_multiple_users(self, mocked_mail):
        """Test sending email when a new comment is added on a NGReport
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        with mute_signals(post_save):
            for user_obj in users_with_comments:
                NGReportCommentFactory.create(user=user_obj,
                                              report=report,
                                              comment='This is a comment')
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 3)
        msg = '[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report)
        mocked_data = mocked_mail.call_args_list[0][1]
        eq_(mocked_data['subject'], msg)
예제 #47
0
 def test_as_owner(self, redirect_mock):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(report.user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=report.user)
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
예제 #48
0
 def test_get_as_owner(self):
     report = NGReportFactory.create()
     with self.login(report.user) as client:
         response = client.get(report.get_absolute_edit_url(),
                               user=report.user)
     eq_(response.context['report'], report)
     self.assertJinja2TemplateUsed(response, 'edit_ng_report.jinja')
예제 #49
0
 def test_get_as_admin(self):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     with self.login(user) as client:
         response = client.get(report.get_absolute_edit_url(), user=user)
     eq_(response.context['report'], report)
     self.assertJinja2TemplateUsed(response, 'edit_ng_report.jinja')
예제 #50
0
 def test_get_absolute_edit_url(self):
     report = NGReportFactory.create(report_date=datetime.date(
         2012, 01, 01),
                                     id=9999)
     eq_(report.get_absolute_edit_url(),
         ('/u/%s/r/2012/January/1/9999/edit/' %
          report.user.userprofile.display_name))
예제 #51
0
    def test_send_email_on_report_comment_settings_True_multiple_users(self):
        """Test sending email when a new comment is added on a NGReport

        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        for user_obj in users_with_comments:
            NGReportCommentFactoryNoSignals.create(user=user_obj,
                                                   report=report,
                                                   comment='This is a comment')
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 3)
        recipients = [
            reporter.email, users_with_comments[0].email,
            users_with_comments[1].email
        ]
        receivers = [
            mail.outbox[0].to[0], mail.outbox[1].to[0], mail.outbox[2].to[0]
        ]
        eq_(set(recipients), set(receivers))
        msg = ('[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report))
        eq_(mail.outbox[0].subject, msg)
예제 #52
0
파일: test_api.py 프로젝트: Mte90/remo
 def test_get_remo_url(self):
     report = NGReportFactory.create()
     url = '/api/beta/activities/%s' % report.id
     request = RequestFactory().get(url)
     data = ActivitiesDetailedSerializer(
         report, context={'request': request}).data
     ok_(report.get_absolute_url() in data['remo_url'])
예제 #53
0
    def test_base(self):
        mentor = UserFactory.create(groups=['Mentor'])
        today = datetime.utcnow().date()
        rep = UserFactory.create(
            groups=['Rep'], userprofile__mentor=mentor,
            userprofile__last_report_notification=today - timedelta(weeks=4))
        NGReportFactory.create(user=rep,
                               report_date=today - timedelta(weeks=5))

        subject = '[Reminder] Please share your recent activities'

        with patch('remo.reports.tasks.send_mail') as send_mail_mock:
            send_ng_report_notification()

        send_mail_mock.assert_called_with(
            subject, mockany, settings.FROM_EMAIL, [rep.email])
예제 #54
0
파일: test_api.py 프로젝트: Mte90/remo
 def test_base(self):
     mentor = UserFactory.create()
     user = UserFactory.create(userprofile__mentor=mentor)
     event = EventFactory.create()
     functional_areas = [FunctionalAreaFactory.create()]
     campaign = CampaignFactory.create()
     activity = ActivityFactory.create()
     report = NGReportFactory.create(
         functional_areas=functional_areas, mentor=mentor,
         campaign=campaign, user=user, event=event, activity=activity)
     url = '/api/beta/activities/%s' % report.id
     request = RequestFactory().get(url)
     data = ActivitiesDetailedSerializer(report,
                                         context={'request': request}).data
     eq_(data['user']['first_name'], user.first_name)
     eq_(data['user']['last_name'], user.last_name)
     eq_(data['user']['display_name'], user.userprofile.display_name)
     ok_(data['user']['_url'])
     eq_(data['activity'], activity.name)
     eq_(data['initiative'], campaign.name)
     eq_(data['functional_areas'][0]['name'], functional_areas[0].name)
     eq_(data['activity_description'], report.activity_description)
     eq_(data['location'], report.location)
     eq_(data['latitude'], float(report.latitude))
     eq_(data['longitude'], float(report.longitude))
     eq_(data['report_date'], report.report_date.strftime('%Y-%m-%d'))
     eq_(data['link'], report.link)
     eq_(data['link_description'], report.link_description)
     eq_(data['mentor']['first_name'], mentor.first_name)
     eq_(data['mentor']['last_name'], mentor.last_name)
     eq_(data['mentor']['display_name'], mentor.userprofile.display_name)
     ok_(data['mentor']['_url'])
     eq_(data['passive_report'], report.is_passive)
     eq_(data['event']['name'], event.name)
     ok_(data['event']['_url'])
예제 #55
0
 def test_get_absolute_delete_url(self):
     report = NGReportFactory.create(report_date=datetime.date(2012, 1, 1),
                                     id=9999)
     eq_(
         report.get_absolute_delete_url(),
         '/u/{0}/r/2012/January/1/9999/delete/'.format(
             report.user.userprofile.display_name))
예제 #56
0
 def test_get_as_admin(self):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     with self.login(user) as client:
         response = client.get(report.get_absolute_edit_url(), user=user)
     eq_(response.context['report'], report)
     self.assertJinja2TemplateUsed(response, 'edit_ng_report.jinja')
예제 #57
0
 def test_as_admin(self, redirect_mock):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
예제 #58
0
 def test_get_uneditable(self, messages_mock):
     report = NGReportFactory.create(activity__name='Month recap')
     self.get(url=report.get_absolute_edit_url(),
              user=report.user,
              follow=True)
     messages_mock.assert_called_with(mock.ANY,
                                      'You cannot edit this report.')
예제 #59
0
 def test_as_admin(self, redirect_mock):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
예제 #60
0
 def test_as_other_rep(self):
     user = UserFactory.create()
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=user)
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())