diff --git a/figures/filters.py b/figures/filters.py index 30038ebf1..062a3f10d 100644 --- a/figures/filters.py +++ b/figures/filters.py @@ -9,6 +9,9 @@ See the following for breaking changes when upgrading to Django Filter 1.0: https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-1-0 + +TODO: Rename classes so they eiher all end with "Filter" or "FilterSet" then + update the test class names in "tests/test_filters.py" to match. """ from django.contrib.auth import get_user_model @@ -166,7 +169,7 @@ def filter_only_completed(self, queryset, name, value): # pylint: disable=unuse """ The "value" parameter is either `True` or `False` """ - if value: + if value == True: return queryset.filter(sections_possible__gt=0, sections_worked=F('sections_possible')) else: @@ -176,7 +179,7 @@ def filter_exclude_completed(self, queryset, name, value): # pylint: disable=un """ The "value" parameter is either `True` or `False` """ - if value: + if value == True: # This is a hack until we add `completed` field to LCGM return queryset.filter(sections_worked__lt=F('sections_possible')) else: diff --git a/tests/test_filters.py b/tests/test_filters.py index 7d7d0bf60..fb361c369 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -10,6 +10,7 @@ import pytest from django.contrib.auth import get_user_model from django.contrib.sites.models import Site +from django.db.models import F from django.test import TestCase from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -19,6 +20,7 @@ CourseDailyMetricsFilter, CourseEnrollmentFilter, CourseOverviewFilter, + EnrollmentMetricsFilter, SiteDailyMetricsFilter, CourseMauMetricsFilter, SiteMauMetricsFilter, @@ -30,6 +32,7 @@ SiteDailyMetrics, CourseMauMetrics, SiteMauMetrics, + LearnerCourseGradeMetrics, ) from tests.factories import ( @@ -37,6 +40,7 @@ CourseEnrollmentFactory, CourseMauMetricsFactory, CourseOverviewFactory, + LearnerCourseGradeMetricsFactory, SiteDailyMetricsFactory, SiteMauMetricsFactory, SiteFactory, @@ -278,6 +282,54 @@ def test_get_by_date(self): lambda o: o.id, ordered=False) +@pytest.mark.skipif(django_filters_pre_v1(), + reason='Django Filter backward compatibility not implemented') +@pytest.mark.django_db +class EnrollmentMetricsFilterTest(TestCase): + """ + Initially adding coverage where view tests are not covering + """ + def setUp(self): + self.site = SiteFactory() + + self.not_complete = LearnerCourseGradeMetricsFactory(site=self.site, + sections_worked=1, + sections_possible=2) + self.complete = LearnerCourseGradeMetricsFactory(site=self.site, + sections_worked=2, + sections_possible=2) + self.site_qs = LearnerCourseGradeMetrics.objects.filter(site=self.site) + self.filter = EnrollmentMetricsFilter(queryset=self.site_qs) + + def test_filter_only_completed(self): + qs = self.filter.filter_only_completed(queryset=self.site_qs, + name='only_completed', + value=True) + assert qs.count() == 1 and qs[0] == self.complete + + def test_filter_only_completed_no_value(self): + """Test that the method returns the queryset passed in + """ + qs = self.filter.filter_only_completed(queryset=self.site_qs, + name='only_completed', + value=False) + assert qs ==self.site_qs + + def test_filter_exclude_completed(self): + qs = self.filter.filter_exclude_completed(queryset=self.site_qs, + name='exclude_completed', + value=True) + assert qs.count() == 1 and qs[0] == self.not_complete + + def test_filter_only_completed_no_value(self): + """Test that the method returns the queryset passed in + """ + qs = self.filter.filter_exclude_completed(queryset=self.site_qs, + name='exclude_completed', + value=False) + assert qs ==self.site_qs + + @pytest.mark.skipif(django_filters_pre_v1(), reason='Django Filter backward compatibility not implemented') @pytest.mark.django_db diff --git a/tests/views/test_enrollment_metrics_viewset.py b/tests/views/test_enrollment_metrics_viewset.py index 7728c453a..9862d7dc7 100644 --- a/tests/views/test_enrollment_metrics_viewset.py +++ b/tests/views/test_enrollment_metrics_viewset.py @@ -133,7 +133,7 @@ def make_request(self, monkeypatch, request_path, site, caller, action): view = self.view_class.as_view({'get': action}) return view(request) - def test_list_method(self, monkeypatch, enrollment_test_data): + def test_list_method_all(self, monkeypatch, enrollment_test_data): site = enrollment_test_data['site'] users = enrollment_test_data['users']