Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion common/djangoapps/student/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
from openedx_filters.learning.filters import CourseEnrollmentStarted, CourseUnenrollmentStarted, DashboardRenderStarted
from rest_framework import status

from common.djangoapps.student.models import CourseEnrollment, EnrollmentNotAllowed, UnenrollmentNotAllowed
from common.djangoapps.student.models import (
CourseEnrollment,
EnrollmentNotAllowed,
Registration,
UnenrollmentNotAllowed,
)
from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory
from common.djangoapps.student.views.management import compose_activation_email
from openedx.core.djangolib.testing.utils import skip_unless_lms
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
Expand Down Expand Up @@ -111,6 +117,18 @@ def run_filter(self, context, template_name): # pylint: disable=arguments-diffe
)


class ActivationEmailWaldoEnricher(PipelineStep):
"""
Test pipeline step for the AccountActivationEmailContextGenerated filter
which adds a `show_waldo` context key.
"""

def run_filter(self, user, message_context): # pylint: disable=arguments-differ
"""Pipeline step that stamps a fake show_waldo flag onto the activation email context."""
message_context["show_waldo"] = True
return {"user": user, "message_context": message_context}


@skip_unless_lms
class EnrollmentFiltersTest(ModuleStoreTestCase):
"""
Expand Down Expand Up @@ -464,3 +482,58 @@ def test_dashboard_render_without_filter_config(self):

self.assertContains(response, self.first_course.id)
self.assertContains(response, self.second_course.id)


@skip_unless_lms
class AccountActivationEmailFiltersTest(ModuleStoreTestCase):
"""
Tests for the Open edX Filters associated with the account activation email context.

This class guarantees that the following filter is triggered when the activation email
context is generated:
- AccountActivationEmailContextGenerated
"""

def setUp(self): # pylint: disable=arguments-differ
super().setUp()
self.user = UserFactory()
self.registration = Registration()
self.registration.register(self.user)
self.registration.save()

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.authentication.account_activation.email.context.generated.v1": {
"pipeline": [
"common.djangoapps.student.tests.test_filters.ActivationEmailWaldoEnricher",
],
"fail_silently": False,
},
},
)
def test_activation_email_context_generated_filter_executed(self):
"""
Test whether the activation email context filter is triggered before the
activation email message context is finalized.

Expected result:
- AccountActivationEmailContextGenerated is triggered and executes
ActivationEmailWaldoEnricher.
- The composed message's context contains the pipeline step's modification.
"""
message = compose_activation_email(self.user, self.registration)

assert message.context["show_waldo"] is True

@override_settings(OPEN_EDX_FILTERS_CONFIG={})
def test_activation_email_context_generated_without_filter_config(self):
"""
Test that compose_activation_email succeeds with no pipeline steps configured.

Expected result:
- AccountActivationEmailContextGenerated executes a noop (empty pipeline).
- No 'show_waldo' key is injected into the message context.
"""
message = compose_activation_email(self.user, self.registration)

assert "show_waldo" not in message.context
8 changes: 6 additions & 2 deletions common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# Note that this lives in LMS, so this dependency should be refactored.
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from openedx_filters.authentication.filters import AccountActivationEmailContextGenerated
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.permissions import IsAuthenticated

Expand Down Expand Up @@ -114,7 +115,6 @@
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
from openedx.features.course_experience.url_helpers import make_learning_mfe_courseware_url
from openedx.features.discounts.applicability import FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG
from openedx.features.enterprise_support.utils import is_enterprise_learner
from xmodule.modulestore.django import modulestore # pylint: disable=wrong-import-order

log = logging.getLogger("edx.student")
Expand Down Expand Up @@ -236,7 +236,6 @@ def compose_activation_email(
message_context = generate_activation_email_context(user, user_registration)
message_context.update({
'confirm_activation_link': _get_activation_confirmation_link(message_context['key'], redirect_url),
'is_enterprise_learner': is_enterprise_learner(user),
'is_first_purchase_discount_overridden': FIRST_PURCHASE_DISCOUNT_OVERRIDE_FLAG.is_enabled(),
'route_enabled': route_enabled,
'routed_user': user.username,
Expand All @@ -245,6 +244,11 @@ def compose_activation_email(
'registration_flow': registration_flow,
'show_auto_generated_username': show_auto_generated_username(user.username),
})
# .. filter_implemented_name: AccountActivationEmailContextGenerated
# .. filter_type: org.openedx.authentication.account_activation.email.context.generated.v1
__, message_context = AccountActivationEmailContextGenerated.run_filter(
user=user, message_context=message_context,
)

if route_enabled:
dest_addr = getattr(settings, 'REROUTE_ACTIVATION_EMAIL', False)
Expand Down
1 change: 0 additions & 1 deletion openedx/core/djangoapps/user_authn/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def test_ComposeEmail(self):
assert self.msg.context['routed_user_email'] == self.student.email
assert self.msg.context['routed_profile_name'] == ''
assert self.msg.context['registration_flow'] is False
assert self.msg.context['is_enterprise_learner'] is False
assert self.msg.context['is_first_purchase_discount_overridden'] is False

@mock.patch('time.sleep', mock.Mock(return_value=None))
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ constraint-dependencies = [
"sphinx-autoapi<3.6.1",
"setuptools<82",
"astroid==4.0.4",
"edx-enterprise==8.11.0",
"edx-enterprise==8.14.0",
"djangorestframework<3.18",
]
[tool.edx_lint]
Expand Down Expand Up @@ -407,7 +407,7 @@ uv_constraints = [
# The team that owns this package will manually bump this package rather than
# having it pulled in automatically. This is to allow them to better control its
# deployment and to do it in a process that works better for them.
"edx-enterprise==8.11.0",
"edx-enterprise==8.14.0",
# Date: 2026-08-31
# DRF 3.18.0 changes many=True validation errors from a list to a dict keyed by
# item index, which breaks the error response shape of several write endpoints.
Expand Down
4 changes: 2 additions & 2 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ edx-drf-extensions==10.9.0
# openedx-authz
# openedx-core
# openedx-platform
edx-enterprise==8.11.0
edx-enterprise==8.14.0
# via openedx-platform
edx-event-bus-kafka==6.1.0
# via openedx-platform
Expand Down Expand Up @@ -845,7 +845,7 @@ openedx-events==11.2.0
# openedx-core
# openedx-platform
# ora2
openedx-filters==3.13.0
openedx-filters==3.14.0
# via
# edx-enterprise
# lti-consumer-xblock
Expand Down
4 changes: 2 additions & 2 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ edx-drf-extensions==10.9.0
# openedx-authz
# openedx-core
# openedx-platform
edx-enterprise==8.11.0
edx-enterprise==8.14.0
# via openedx-platform
edx-event-bus-kafka==6.1.0
# via openedx-platform
Expand Down Expand Up @@ -947,7 +947,7 @@ openedx-events==11.2.0
# openedx-core
# openedx-platform
# ora2
openedx-filters==3.13.0
openedx-filters==3.14.0
# via
# edx-enterprise
# lti-consumer-xblock
Expand Down
14 changes: 7 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading