Skip to content

Commit

Permalink
feat: [AXM-288] Change response to represent Future assignments the s…
Browse files Browse the repository at this point in the history
…ame way as past assignments
  • Loading branch information
KyryloKireiev committed Apr 19, 2024
1 parent 9a9a356 commit da5a27d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lms/djangoapps/mobile_api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def get_progress(self, model: CourseEnrollment) -> Dict[str, int]:
"""
return self.calculate_progress(model)

def get_course_assignments(self, model: CourseEnrollment) -> Optional[Dict[str, List[Dict[str, str]]]]:
def get_course_assignments(self, model: CourseEnrollment) -> Dict[str, Optional[List[Dict[str, str]]]]:
"""
Returns the future assignment data and past assignments data for the user in the course.
"""
Expand All @@ -267,19 +267,26 @@ def get_course_assignments(self, model: CourseEnrollment) -> Optional[Dict[str,
self.context.get('request'),
include_past_dates=True
)
next_assignment = None
next_assignment_all = []
next_assignment = []
past_assignment = []

timezone = get_user_timezone_or_last_seen_timezone_or_utc(model.user)
for assignment in sorted(assignments, key=lambda x: x.date):
if assignment.date < datetime.now(timezone):
past_assignment.append(assignment)
else:
next_assignment = DateSummarySerializer(assignment).data
break
if not assignment.complete:
next_assignment_all.append(assignment)

if next_assignment_all:
future_assignment_date = next_assignment_all[0].date.date()
next_assignment = [
assignment for assignment in next_assignment_all if assignment.date.date() == future_assignment_date
]

return {
'future_assignment': next_assignment,
'future_assignments': DateSummarySerializer(next_assignment, many=True).data,
'past_assignments': DateSummarySerializer(past_assignment, many=True).data,
}

Expand Down
15 changes: 15 additions & 0 deletions lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,21 @@ def test_user_enrollment_api_v4_status_all(self):
self.assertEqual(enrollments['results'][2]['course']['id'], str(old_course.id))
self.assertNotIn('primary', response.data)

@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_response_contains_primary_enrollment_assignments_info(self, cache_mock: MagicMock):
self.login()
course = CourseFactory.create(org='edx', mobile_available=True)
self.enroll(course.id)

response = self.api_response(api_version=API_V4)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('course_assignments', response.data['primary'])
self.assertIn('past_assignments', response.data['primary']['course_assignments'])
self.assertIn('future_assignments', response.data['primary']['course_assignments'])
self.assertListEqual(response.data['primary']['course_assignments']['past_assignments'], [])
self.assertListEqual(response.data['primary']['course_assignments']['future_assignments'], [])


@override_settings(MKTG_URLS={'ROOT': 'dummy-root'})
class TestUserEnrollmentCertificates(UrlResetMixin, MobileAPITestCase, MilestonesTestCaseMixin):
Expand Down

0 comments on commit da5a27d

Please sign in to comment.