Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
[Fix bug 967026][Fix bug Bug 970395] Fix inactive user notifications.
Browse files Browse the repository at this point in the history
* Make send_remo_mail non-blocking
* Do not cc remobot
* Fix time filter in second report notification
* Exclude users with incomplete profiles from notifications
  • Loading branch information
johngian committed May 7, 2014
1 parent b4de777 commit fa71a69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion remo/base/views.py
Expand Up @@ -283,7 +283,8 @@ def email_mentees(request):

def stats_dashboard(request):
"""Stats dashboard view."""
reps = User.objects.filter(groups__name='Rep')
reps = User.objects.filter(groups__name='Rep',
userprofile__registration_complete=True)

q_active = Q(
ng_reports__report_date__range=[get_date(weeks=-4), get_date(weeks=4)])
Expand Down
4 changes: 3 additions & 1 deletion remo/reports/tasks.py
Expand Up @@ -62,6 +62,7 @@ def send_first_report_notification():
end = today + timedelta(weeks=4)
users = User.objects.filter(
groups__name='Rep',
userprofile__registration_complete=True,
userprofile__first_report_notification__isnull=True)
inactive_users = users.exclude(ng_reports__report_date__range=[start, end])

Expand All @@ -79,7 +80,8 @@ def send_second_report_notification():
end = today + timedelta(weeks=8)
users = User.objects.filter(
groups__name='Rep',
userprofile__first_report_notification__gte=today - timedelta(weeks=4),
userprofile__registration_complete=True,
userprofile__first_report_notification__lte=today - timedelta(weeks=4),
userprofile__second_report_notification__isnull=True)
inactive_users = users.exclude(ng_reports__report_date__range=[start, end])

Expand Down
24 changes: 12 additions & 12 deletions remo/reports/tests/test_tasks.py
Expand Up @@ -93,14 +93,14 @@ def test_base(self):
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 send_mail_mock:
with patch('remo.reports.utils.send_remo_mail.delay') as mail_mock:
send_first_report_notification()

eq_(send_mail_mock.call_count, 2)
eq_(mail_mock.call_count, 2)
expected_call_list = [
call(rep_subject, [rep.email], settings.FROM_EMAIL, mockany),
call(mentor_subject, [mentor.email], settings.FROM_EMAIL, mockany)]
eq_(send_mail_mock.call_args_list, expected_call_list)
call(rep_subject, [rep.email], message=mockany),
call(mentor_subject, [mentor.email], message=mockany)]
eq_(mail_mock.call_args_list, expected_call_list)

def test_with_report_filled(self):
mentor = UserFactory.create(groups=['Mentor'])
Expand All @@ -110,9 +110,9 @@ def test_with_report_filled(self):
NGReportFactory.create(user=rep,
report_date=today - timedelta(weeks=2))

with patch('remo.reports.utils.send_remo_mail') as send_mail_mock:
with patch('remo.reports.utils.send_remo_mail.delay') as mail_mock:
send_second_report_notification()
ok_(not send_mail_mock.called)
ok_(not mail_mock.called)

def test_with_no_report_filled_and_one_notification(self):
mentor = UserFactory.create(groups=['Mentor'])
Expand All @@ -126,14 +126,14 @@ def test_with_no_report_filled_and_one_notification(self):
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 send_mail_mock:
with patch('remo.reports.utils.send_remo_mail.delay') as mail_mock:
send_second_report_notification()

eq_(send_mail_mock.call_count, 2)
eq_(mail_mock.call_count, 2)
expected_call_list = [
call(rep_subject, [rep.email], settings.FROM_EMAIL, mockany),
call(mentor_subject, [mentor.email], settings.FROM_EMAIL, mockany)]
eq_(send_mail_mock.call_args_list, expected_call_list)
call(rep_subject, [rep.email], message=mockany),
call(mentor_subject, [mentor.email], message=mockany)]
eq_(mail_mock.call_args_list, expected_call_list)


class UpdateCurrentStreakCountersTest(RemoTestCase):
Expand Down
7 changes: 3 additions & 4 deletions remo/reports/utils.py
Expand Up @@ -61,7 +61,6 @@ def send_report_notification(reps, weeks):

rep_message = render_to_string(rep_mail_body, ctx_data)
mentor_message = render_to_string(mentor_mail_body, ctx_data)
send_remo_mail(rep_subject, [rep.email], settings.FROM_EMAIL,
rep_message)
send_remo_mail(mentor_subject, [rep.userprofile.mentor.email],
settings.FROM_EMAIL, mentor_message)
send_remo_mail.delay(rep_subject, [rep.email], message=rep_message)
send_remo_mail.delay(mentor_subject, [rep.userprofile.mentor.email],
message=mentor_message)

0 comments on commit fa71a69

Please sign in to comment.