diff --git a/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py index f8d45a7af5..52a86b8c25 100644 --- a/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py @@ -122,8 +122,9 @@ class Command(BaseCommand): count = 0 course_goals = course_goals.exclude(course_key__in=courses_to_exclude).select_related('user').order_by('user') - with emulate_http_request(site=Site.objects.get_current()): # emulate a request for waffle's benefit - for goal in course_goals: + for goal in course_goals: + # emulate a request for waffle's benefit + with emulate_http_request(site=Site.objects.get_current(), user=goal.user): if self.handle_goal(goal, today, sunday_date, monday_date): count += 1 diff --git a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py index 2210a1b5d9..59e9f58c8f 100644 --- a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py @@ -9,6 +9,7 @@ from django.core.management import call_command from django.test import TestCase from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time +from waffle import get_waffle_flag_model # pylint: disable=invalid-django-waffle-import from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import CourseEnrollmentFactory @@ -119,6 +120,15 @@ class TestGoalReminderEmailCommand(TestCase): with override_waffle_flag(COURSE_GOALS_NUMBER_OF_DAYS_GOALS, active=False): self.call_command(expect_sent=False) + def test_feature_enabled_for_user(self): + goal = self.make_valid_goal() + with override_waffle_flag(COURSE_GOALS_NUMBER_OF_DAYS_GOALS, active=None): + # We want to ensure that when we set up a fake request + # it works correctly if the flag is only enabled for specific users + flag = get_waffle_flag_model().get(COURSE_GOALS_NUMBER_OF_DAYS_GOALS.name) + flag.users.add(goal.user) + self.call_command(expect_sent=True) + def test_never_enrolled(self): self.make_valid_goal() CourseEnrollment.objects.all().delete()