From 084f19c05fe6da47b184c98de29c5721fff3b2f9 Mon Sep 17 00:00:00 2001 From: Juan David Buitrago Date: Mon, 19 Dec 2022 22:41:20 -0500 Subject: [PATCH] refactor: use CourseEnrollmentQuerysetRequested from openedx-filters --- .github/workflows/labeler.yml | 2 +- eox_tenant/filters/pipeline.py | 10 +++---- eox_tenant/filters/test/test_pipeline.py | 35 +++++------------------- requirements/base.txt | 2 +- requirements/test.txt | 2 +- 5 files changed, 15 insertions(+), 36 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index daf2b89b..33dda30a 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -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' diff --git a/eox_tenant/filters/pipeline.py b/eox_tenant/filters/pipeline.py index 3c8745b2..c38ad7d5 100644 --- a/eox_tenant/filters/pipeline.py +++ b/eox_tenant/filters/pipeline.py @@ -13,13 +13,13 @@ 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" @@ -27,8 +27,8 @@ def run_filter(self, context): # pylint: disable=arguments-differ } } """ - tenant_enrollments = filter_enrollments(context) - return {"context": tenant_enrollments} + tenant_enrollments = filter_enrollments(enrollments) + return {"enrollments": tenant_enrollments} class FilterRenderCertificatesByOrg(PipelineStep): diff --git a/eox_tenant/filters/test/test_pipeline.py b/eox_tenant/filters/test/test_pipeline.py index c0b85f4a..1f9580be 100644 --- a/eox_tenant/filters/test/test_pipeline.py +++ b/eox_tenant/filters/test/test_pipeline.py @@ -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. @@ -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" @@ -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) @@ -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" @@ -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)) diff --git a/requirements/base.txt b/requirements/base.txt index ffd675b2..2ed5de70 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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 diff --git a/requirements/test.txt b/requirements/test.txt index 7848d0bd..c674c217 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -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