fix: ensure goal reminder command respects flag cofiguration of individual users (#29071)

This commit is contained in:
Matthew Piatetsky
2021-10-20 15:03:38 -04:00
committed by GitHub
parent 9ee8df0980
commit e0d2cda697
2 changed files with 13 additions and 2 deletions

View File

@@ -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

View File

@@ -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()