From 80b2f9c1a93e15389ed02a9f28c09ae07060c401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=B2=D0=B0=D0=BD=20=D0=9D=D1=94=D0=B4=D1=94=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=96=D1=86=D0=B5=D0=B2?= Date: Mon, 8 Apr 2024 13:29:32 +0300 Subject: [PATCH] style: [AXM-33] fix pylint issues --- lms/djangoapps/mobile_api/users/enums.py | 13 ++++++++----- lms/djangoapps/mobile_api/users/tests.py | 1 - lms/djangoapps/mobile_api/users/views.py | 14 +++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lms/djangoapps/mobile_api/users/enums.py b/lms/djangoapps/mobile_api/users/enums.py index 463572de71e3..2a072b082fff 100644 --- a/lms/djangoapps/mobile_api/users/enums.py +++ b/lms/djangoapps/mobile_api/users/enums.py @@ -1,10 +1,12 @@ +""" +Enums for mobile_api users app. +""" from enum import Enum -from django.utils.functional import classproperty class EnrollmentStatuses(Enum): """ - + Enum for enrollment statuses. """ ALL = 'all' @@ -12,8 +14,9 @@ class EnrollmentStatuses(Enum): COMPLETED = 'completed' EXPIRED = 'expired' - # values = [ALL, IN_PROGRESS, COMPLETED, EXPIRED] - - @classproperty + @classmethod def values(cls): + """ + Returns string representation of all enum values. + """ return [e.value for e in cls] diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 8efe0e46390e..5b842851db0b 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -822,7 +822,6 @@ def test_user_enrollment_api_v4_expired_status(self): self.assertEqual(enrollments['results'][0]['course']['id'], str(old_course.id)) self.assertNotIn('primary', response.data) - def test_user_enrollment_api_v4_expired_course_with_certificate(self): """ Testing that the API returns a course with diff --git a/lms/djangoapps/mobile_api/users/views.py b/lms/djangoapps/mobile_api/users/views.py index b436eb0001a1..4d2ddf2aad7a 100644 --- a/lms/djangoapps/mobile_api/users/views.py +++ b/lms/djangoapps/mobile_api/users/views.py @@ -4,7 +4,6 @@ import logging -from datetime import datetime from functools import cached_property from typing import List, Optional @@ -358,6 +357,11 @@ def get_serializer_class(self): @cached_property def queryset(self): + """ + Find and return the list of course enrollments for the user. + + In v4 added filtering by statuses. + """ api_version = self.kwargs.get('api_version') status = self.request.GET.get('status') username = self.kwargs['username'] @@ -367,7 +371,7 @@ def queryset(self): is_active=True ).order_by('-created') - if api_version == API_V4 and status in EnrollmentStatuses.values: + if api_version == API_V4 and status in EnrollmentStatuses.values(): if status == EnrollmentStatuses.IN_PROGRESS.value: queryset = queryset.in_progress(user_username=username, time_zone=self.user_timezone) elif status == EnrollmentStatuses.COMPLETED.value: @@ -387,7 +391,7 @@ def get_queryset(self): if check_course_expired(self.request.user, enrollment.course) == ACCESS_GRANTED ) - if api_version == API_V4 and status not in EnrollmentStatuses.values: + if api_version == API_V4 and status not in EnrollmentStatuses.values(): primary_enrollment_obj = self.get_primary_enrollment_by_latest_enrollment_or_progress() if primary_enrollment_obj: mobile_available.remove(primary_enrollment_obj) @@ -426,8 +430,8 @@ def list(self, request, *args, **kwargs): 'user_timezone': str(self.user_timezone), 'enrollments': response.data } - if api_version == API_V4 and status not in EnrollmentStatuses.values: - if status in EnrollmentStatuses.values: + if api_version == API_V4 and status not in EnrollmentStatuses.values(): + if status in EnrollmentStatuses.values(): enrollment_data.update({'primary': None}) else: primary_enrollment_obj = self.get_primary_enrollment_by_latest_enrollment_or_progress()