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: Implement IDV URL Filters #213

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 19 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,22 @@ def run_filter(cls, context: dict, template_name: str):
"""
data = super().run_pipeline(context=context, template_name=template_name, )
return data.get("context"), data.get("template_name")


class IDVPageURLRequested(OpenEdxPublicFilter):
"""
Custom class used to create filters to act on ID verification page URL requests.
"""

filter_type = "org.openedx.learning.idv.page.url.requested.v1"

@classmethod
def run_filter(cls, url):

Choose a reason for hiding this comment

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

Could you add type annotations to the method definition, since that seems to be the pattern in this repository, please?

"""
Execute a filter with the specified signature.

Arguments:
url (str): The url for the ID verification page to be modified.
"""
data = super().run_pipeline(url=url)
return data.get("url")
24 changes: 24 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CourseRunAPIRenderStarted,
CourseUnenrollmentStarted,
DashboardRenderStarted,
IDVPageURLRequested,
InstructorDashboardRenderStarted,
ORASubmissionViewRenderStarted,
RenderXBlockStarted,
Expand Down Expand Up @@ -728,3 +729,26 @@ def test_course_run_api_render_started(self):
result = CourseRunAPIRenderStarted.run_filter(serialized_courserun)

self.assertEqual(serialized_courserun, result)


class TestIDVFilters(TestCase):
"""
Test class to verify standard behavior of the ID verification filters.
You'll find test suites for:

- IDVPageURLRequested
"""

def test_course_idv_page_url_requested(self):
Copy link
Member

Choose a reason for hiding this comment

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

nit: is there a reason that the test case includes course in it? Wondering if it should be:

Suggested change
def test_course_idv_page_url_requested(self):
def test_idv_page_url_requested(self):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this is another artifact from me copy/pasting tests.

"""
Test IDVPageURLRequested filter behavior under normal conditions.

Expected behavior:
- The filter must have the signature specified.
- The filter should return the url.
"""
url = Mock(), Mock()

Choose a reason for hiding this comment

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

I'm curious why you need a tuple here. url should be a single value. Does url = Mock() not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove this when I copy/pasted an earlier test


result = IDVPageURLRequested.run_filter(url)

self.assertEqual(url, result)