Skip to content

Conversation

@sjasti-sonata-svg
Copy link
Contributor

@sjasti-sonata-svg sjasti-sonata-svg commented Nov 18, 2025

…ress Report

**This PR introduces a new unenrollment filter to the Learner Progress Report (LPR) and updates the ordering of existing filters.

Added Unenrollment option(Enrolled and UnEnrolled) to LPR filters.

Comment on lines 311 to 321
def filter_search_enrollment(self, queryset, search_enrollment):
now=timezone.localdate()

if search_enrollment == 'enrolled':
return queryset.filter(
Q(unenrollment_date__isnull=True) | Q(unenrollment_date__gt=now)
)
elif search_enrollment == 'unenrolled':
return queryset.filter(unenrollment_date__lte=now)
return queryset

Copy link
Contributor

Choose a reason for hiding this comment

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

As per my understanding, unenrollment_date will never be in the future. So we can simplify the code as shown below. I believe this will also simplify the unit tests.

def filter_search_enrollment(self, queryset, status):
    """
    Filter enrollments based on enrollment `status`.

    Args:
        status (str): Enrollment status to filter by. Can be one of:
            'enrolled'   : unenrollment_date is NULL (currently enrolled)
            'unenrolled' : unenrollment_date is NOT NULL (no longer enrolled)

   Returns:
       QuerySet: Filtered queryset of enrollments.
    """

    if status == "enrolled":
        return queryset.filter(unenrollment_date__isnull=True)

    if status == "unenrolled":
        return queryset.filter(unenrollment_date__isnull=False)

    return queryset

Copy link
Contributor

@muhammad-ammar muhammad-ammar left a comment

Choose a reason for hiding this comment

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

Good Work. One last thing. For every PR, you also need make changes in CHANGELOG.rst and https://github.com/openedx/edx-enterprise-data/blob/master/enterprise_data/__init__.py

Please see #641 to understand what changes are needed in the files mentioned above.

)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["count"], 2) No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a new line at the end of file.

super().tearDown()
EnterpriseLearnerEnrollment.objects.all().delete()

def _get_url(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of creating this method, we can declare a variable in setUp as shown below

self.url = reverse(
    'v1:enterprise-learner-enrollment-list',
    kwargs={'enterprise_id': self.enterprise_id}
)

Comment on lines 411 to 413
# -----------------------------
# 1. Test for enrolled learners
# -----------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

The standard practice is to add docstrings in test functions. Please add docstrings in all tests and remove these comments.

For example,

def test_filter_enrolled(self):
"""
Test that the enrollments API returns the correct data when filtered by the 'enrolled' status.
"""

Comment on lines 416 to 438
enterprise_learner = EnterpriseLearnerFactory(
enterprise_customer_uuid=self.enterprise_id
)

enrolled = EnterpriseLearnerEnrollmentFactory(
enterprise_user=enterprise_learner,
enterprise_customer_uuid=self.enterprise_id,
unenrollment_date=None,
)

# Create unenrolled learner (unenrollment_date != NULL)
EnterpriseLearnerEnrollmentFactory(
enterprise_user=enterprise_learner,
enterprise_customer_uuid=self.enterprise_id,
unenrollment_date=timezone.now(),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

In all tests, we are creating data inside the tests, it would be great if we can move all the test data creation inside the setUp method.

letter_grade = factory.lazy_attribute(lambda x: ' '.join(FAKER.words(nb=2)).title())
progress_status = factory.lazy_attribute(lambda x: ' '.join(FAKER.words(nb=2)).title())
enterprise_user_id = factory.Sequence(lambda n: n)
#enterprise_user_id = factory.Sequence(lambda n: n)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this was left by mistake?

enterprise_user = factory.SubFactory(
EnterpriseLearnerFactory,
enterprise_user_id=factory.Sequence(lambda n: n+1)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain why we need to make changes in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous one was giving an error. FOREIGN KEY constraint failed when I was running Unit test cases.

@sjasti-sonata-svg sjasti-sonata-svg force-pushed the subhashini/ENT-10811 branch 9 times, most recently from 1035350 to 304fbae Compare November 29, 2025 16:58
@sjasti-sonata-svg sjasti-sonata-svg force-pushed the subhashini/ENT-10811 branch 2 times, most recently from 23cda29 to 9627c87 Compare December 2, 2025 16:56
…ress Report

correcting CHANGELOG.rst version number

Fixed issues for checks failing.

fixing issues for failing tests.

Fixing test failures

fixing whitespaces

fixing issuse

fixing qulity issues
@muhammad-ammar muhammad-ammar merged commit 403cf60 into openedx:master Dec 4, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants