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

feat: pluggable url for idv location #35494

Merged
merged 3 commits into from
Sep 25, 2024
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
6 changes: 5 additions & 1 deletion lms/djangoapps/verify_student/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.utils.timezone import now
from django.utils.translation import gettext as _
from openedx_filters.learning.filters import IDVPageURLRequested

from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.models import User
Expand Down Expand Up @@ -244,7 +245,10 @@ def get_verify_location(cls, course_id=None):
location = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification'
if course_id:
location += f'?course_id={quote(str(course_id))}'
return location

# .. filter_implemented_name: IDVPageURLRequested
# .. filter_type: org.openedx.learning.idv.page.url.requested.v1
return IDVPageURLRequested.run_filter(location)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add:

# .. filter_implemented_name: IDVPageURLRequested
# .. filter_type: org.openedx.learning.idv.page.url.requested.v1

So it's easier to identify later on. Thanks!


@classmethod
def get_verification_details_by_id(cls, attempt_id):
Expand Down
33 changes: 32 additions & 1 deletion lms/djangoapps/verify_student/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

import ddt
from django.conf import settings
from django.test import TestCase
from django.test import TestCase, override_settings
from django.utils.timezone import now
from django.utils.translation import gettext as _
from freezegun import freeze_time
from openedx_filters import PipelineStep
from pytz import utc

from common.djangoapps.student.tests.factories import UserFactory
Expand All @@ -33,6 +34,16 @@
}


class TestIdvPageUrlRequestedPipelineStep(PipelineStep):
""" Utility function to test a configured pipeline step """
TEST_URL = 'example.com/verify'

def run_filter(self, url): # pylint: disable=arguments-differ
return {
"url": self.TEST_URL
}


@patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS)
@ddt.ddt
class TestIDVerificationService(ModuleStoreTestCase):
Expand Down Expand Up @@ -167,6 +178,26 @@ def test_get_verify_location_from_string(self):
expected_path = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification'
assert path == (expected_path + '?course_id=course-v1%3AedX%2BDemoX%2BDemo_Course')

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.idv.page.url.requested.v1": {
"pipeline": [
"lms.djangoapps.verify_student.tests.test_services.TestIdvPageUrlRequestedPipelineStep",
],
"fail_silently": False,
},
},
)
def test_get_verify_location_with_filter_step(self):
"""
Test IDV flow location can be customized with an openedx filter
"""
url = IDVerificationService.get_verify_location()
assert url == TestIdvPageUrlRequestedPipelineStep.TEST_URL

url = IDVerificationService.get_verify_location('course-v1:edX+DemoX+Demo_Course')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: is there a reason that the urls tested are both the same here? I'm not sure if this would make a difference, but would it be better for the urls to be different. Or is the point that they should in fact be the same? Maybe I'm misunderstanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the output the same because I'm validating the url is overridden by the filter hook in both cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test the case when the filter is not configured so we know it's not getting overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup! The existing tests above this one cover the default behavior with no filter configured

assert url == TestIdvPageUrlRequestedPipelineStep.TEST_URL

def test_get_expiration_datetime(self):
"""
Test that the latest expiration datetime is returned if there are multiple records
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ openedx-events==9.14.0
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.9.0
openedx-filters==1.10.0
# via
# -r requirements/edx/kernel.in
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ openedx-events==9.14.0
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.9.0
openedx-filters==1.10.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ openedx-events==9.14.0
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.9.0
openedx-filters==1.10.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ openedx-events==9.14.0
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.9.0
openedx-filters==1.10.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down
Loading