Skip to content

Commit

Permalink
refactor: use CourseEnrollmentQuerysetRequested from openedx-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago committed Mar 2, 2023
1 parent f3745a5 commit 084f19c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: CodelyTV/pr-size-labeler@v1.8.1
- uses: CodelyTV/pr-size-labeler@v1.7.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: '10'
Expand Down
10 changes: 5 additions & 5 deletions eox_tenant/filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class FilterUserCourseEnrollmentsByTenant(PipelineStep):
Filter enrollments list by a tenant.
"""

def run_filter(self, context): # pylint: disable=arguments-differ
def run_filter(self, enrollments): # pylint: disable=arguments-differ
"""
Filter especific user course enrollments by tenant request.
Example Usage:
Add the following configurations to you configuration file
Add the following configurations to your configuration file
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.course_enrollments_site.filter.requested.v1": {
"org.openedx.learning.course_enrollment_queryset.requested.v1": {
"fail_silently": false,
"pipeline": [
"eox_tenant.filters.pipeline.FilterUserCourseEnrollmentsByTenant"
]
}
}
"""
tenant_enrollments = filter_enrollments(context)
return {"context": tenant_enrollments}
tenant_enrollments = filter_enrollments(enrollments)
return {"enrollments": tenant_enrollments}


class FilterRenderCertificatesByOrg(PipelineStep):
Expand Down
35 changes: 7 additions & 28 deletions eox_tenant/filters/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,12 @@
import ddt
import mock
from django.test import TestCase, override_settings
from openedx_filters.learning.filters import CertificateRenderStarted
from openedx_filters.tooling import OpenEdxPublicFilter
from openedx_filters.learning.filters import CertificateRenderStarted, CourseEnrollmentQuerysetRequested

from eox_tenant.filters.pipeline import FilterRenderCertificatesByOrg
from eox_tenant.tenant_aware_functions.enrollments import filter_enrollments


# This class was temporarily added while the filter is added in openedx-filters.
class CourseEnrollmentSiteFilterRequested(OpenEdxPublicFilter):
"""
Custom class used to filter user's course enrollments by site.
"""

filter_type = "org.openedx.learning.course_enrollments_site.filter.requested.v1"

@classmethod
def run_filter(cls, context):
"""
Execute a filter with the signature specified.
Arguments:
context (QuerySet): list of all user's course enrollments.
"""
data = super().run_pipeline(context=context)
return data.get("context")


class FilterUserCourseEnrollmentsByTenantTestCase(TestCase):
"""
FilterUserCourseEnrollmentsByTenant test cases.
Expand All @@ -52,7 +31,7 @@ def setUp(self):

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.course_enrollments_site.filter.requested.v1": {
"org.openedx.learning.course_enrollment_queryset.requested.v1": {
"fail_silently": False,
"pipeline": [
"eox_tenant.filters.pipeline.FilterUserCourseEnrollmentsByTenant"
Expand Down Expand Up @@ -88,8 +67,8 @@ def side_effect_get_value(key, default=None):

expected_result = filter_enrollments(self.course_enrollments)

result = CourseEnrollmentSiteFilterRequested.run_filter(
context=self.course_enrollments
result = CourseEnrollmentQuerysetRequested.run_filter(
enrollments=self.course_enrollments
)
expected_result = list(expected_result)
result = list(result)
Expand All @@ -99,7 +78,7 @@ def side_effect_get_value(key, default=None):

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.course_enrollments_site.filter.requested.v1": {
"org.openedx.learning.course_enrollment_queryset.requested.v1": {
"fail_silently": False,
"pipeline": [
"eox_tenant.filters.pipeline.FilterUserCourseEnrollmentsByTenant"
Expand Down Expand Up @@ -136,8 +115,8 @@ def side_effect_get_value(key, default=None):

expected_result = filter_enrollments(self.course_enrollments)

result = CourseEnrollmentSiteFilterRequested.run_filter(
context=self.course_enrollments
result = CourseEnrollmentQuerysetRequested.run_filter(
enrollments=self.course_enrollments
)

self.assertListEqual(list(expected_result), list(result))
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jsonfield==3.1.0
# via
# -c requirements/constraints.txt
# -r requirements/base.in
openedx-filters==0.8.0
openedx-filters==1.0.0
# via
# -c requirements/constraints.txt
# -r requirements/base.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mock==4.0.3
# via
# -c requirements/constraints.txt
# -r requirements/test.in
openedx-filters==0.8.0
openedx-filters==1.0.0
# via
# -c requirements/constraints.txt
# -r requirements/base.txt
Expand Down

0 comments on commit 084f19c

Please sign in to comment.