Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug sending 10+ mails to all users #3229

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lego/apps/email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def send_weekly_email(self, logger_context=None):

week_number = timezone.now().isocalendar().week

# Set to just PR and Webkom for testing purposes
all_users = AbakusGroup.objects.get(name="Abakus").restricted_lookup()[0]
# Send to all active students
all_users = set(AbakusGroup.objects.get(name="Students").restricted_lookup()[0])
recipients = []

for user in all_users:
Expand Down
10 changes: 10 additions & 0 deletions lego/apps/email/tests/test_weekly_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setUp(self):
joblisting.save()
pr = AbakusGroup.objects.get(name="PR")
pr.add_user(User.objects.get(pk=10))
students = AbakusGroup.objects.get(name="Students")
students.add_user(User.objects.get(pk=10))

def assertEmailContains(self, send_mass_mail_mock, content):
message = send_mass_mail_mock.call_args.args[0][0][1]
Expand Down Expand Up @@ -78,6 +80,8 @@ def setUp(self):
joblisting.save()
pr = AbakusGroup.objects.get(name="PR")
pr.add_user(User.objects.get(pk=10))
students = AbakusGroup.objects.get(name="Students")
students.add_user(User.objects.get(pk=10))

def test_generate_weekly(self, send_mail_mock):
send_weekly_email()
Expand Down Expand Up @@ -112,6 +116,8 @@ def setUp(self):
joblisting.save()
pr = AbakusGroup.objects.get(name="PR")
pr.add_user(User.objects.get(pk=10))
students = AbakusGroup.objects.get(name="Students")
students.add_user(User.objects.get(pk=10))

def test_generate_weekly(self, send_mail_mock):
send_weekly_email()
Expand Down Expand Up @@ -141,6 +147,8 @@ class WeeklyEmailTestCaseNothing(BaseTestCase):
def setUp(self):
pr = AbakusGroup.objects.get(name="PR")
pr.add_user(User.objects.get(pk=10))
students = AbakusGroup.objects.get(name="Students")
students.add_user(User.objects.get(pk=10))
return

def test_send_mail(self, send_mass_mail_mock):
Expand Down Expand Up @@ -169,6 +177,8 @@ def setUp(self):
joblisting.save()
pr = AbakusGroup.objects.get(name="PR")
pr.add_user(User.objects.get(pk=10))
students = AbakusGroup.objects.get(name="Students")
students.add_user(User.objects.get(pk=10))

def test_email_sent(self, send_mass_mail_mock):
send_weekly_email()
Expand Down