Skip to content

Commit

Permalink
style: [AXM-33] fix pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Apr 8, 2024
1 parent 5f27bbe commit 80b2f9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
13 changes: 8 additions & 5 deletions lms/djangoapps/mobile_api/users/enums.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
"""
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'
IN_PROGRESS = 'in_progress'
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]
1 change: 0 additions & 1 deletion lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


import logging
from datetime import datetime
from functools import cached_property
from typing import List, Optional

Expand Down Expand Up @@ -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']
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 80b2f9c

Please sign in to comment.