Skip to content

Commit

Permalink
feat: [AXIM-6] Add DefaultPagination for UserCourseEnrollmentsList v3
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev authored and GlugovGrGlib committed Nov 20, 2023
1 parent c5cbb96 commit ee4b92c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
25 changes: 24 additions & 1 deletion lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
MobileAuthUserTestMixin,
MobileCourseAccessTestMixin
)
from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2
from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2, API_V3
from openedx.core.lib.courses import course_image_url
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.course_experience.tests.views.helpers import add_course_mode
Expand Down Expand Up @@ -376,6 +376,29 @@ def test_enrollment_with_configs(self):
self.assertDictEqual(response.data['configs'], expected_result)
assert 'enrollments' in response.data

def test_pagination_enrollment(self):
"""
Test pagination for UserCourseEnrollmentsList view v3
for 3rd version of this view we use DefaultPagination
Test for /api/mobile/{api_version}/users/<user_name>/course_enrollments/
api_version = v3
"""
self.login()
# Create and enroll to 15 courses
courses = [CourseFactory.create(org="my_org", mobile_available=True) for _ in range(15)]
for course in courses:
self.enroll(course.id)

response = self.api_response(api_version=API_V3)
assert response.status_code == 200
assert response.data["enrollments"]["count"] == 15
assert response.data["enrollments"]["num_pages"] == 2
assert response.data["enrollments"]["current_page"] == 1
assert len(response.data["enrollments"]["results"]) == 10
assert "next" in response.data["enrollments"]
assert "previous" in response.data["enrollments"]


@override_settings(MKTG_URLS={'ROOT': 'dummy-root'})
class TestUserEnrollmentCertificates(UrlResetMixin, MobileAPITestCase, MilestonesTestCaseMixin):
Expand Down
16 changes: 14 additions & 2 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from rest_framework.response import Response
from xblock.fields import Scope
from xblock.runtime import KeyValueStore
from edx_rest_framework_extensions.paginators import DefaultPagination

from common.djangoapps.student.models import CourseEnrollment, User # lint-amnesty, pylint: disable=reimported
from lms.djangoapps.courseware.access import is_mobile_available_for_user
Expand All @@ -30,7 +31,7 @@
from lms.djangoapps.courseware.block_render import get_block_for_descriptor
from lms.djangoapps.courseware.views.index import save_positions_recursively_up
from lms.djangoapps.mobile_api.models import MobileConfig
from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2
from lms.djangoapps.mobile_api.utils import API_V1, API_V05, API_V2, API_V3
from openedx.features.course_duration_limits.access import check_course_expired
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -372,7 +373,7 @@ def list(self, request, *args, **kwargs):
response = super().list(request, *args, **kwargs)
api_version = self.kwargs.get('api_version')

if api_version == API_V2:
if api_version in (API_V2, API_V3):
enrollment_data = {
'configs': MobileConfig.get_structured_configs(),
'enrollments': response.data
Expand All @@ -381,6 +382,17 @@ def list(self, request, *args, **kwargs):

return response

# pylint: disable=attribute-defined-outside-init
@property
def paginator(self):
super().paginator # pylint: disable=expression-not-assigned
api_version = self.kwargs.get('api_version')

if self._paginator is None and api_version == API_V3:
self._paginator = DefaultPagination()

return self._paginator


@api_view(["GET"])
@mobile_view()
Expand Down
1 change: 1 addition & 0 deletions lms/djangoapps/mobile_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
API_V05 = 'v0.5'
API_V1 = 'v1'
API_V2 = 'v2'
API_V3 = 'v3'


def parsed_version(version):
Expand Down
2 changes: 1 addition & 1 deletion lms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@

if settings.FEATURES.get('ENABLE_MOBILE_REST_API'):
urlpatterns += [
re_path(r'^api/mobile/(?P<api_version>v(2|1|0.5))/', include('lms.djangoapps.mobile_api.urls')),
re_path(r'^api/mobile/(?P<api_version>v(3|2|1|0.5))/', include('lms.djangoapps.mobile_api.urls')),
]

urlpatterns += [
Expand Down

0 comments on commit ee4b92c

Please sign in to comment.