Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AXM-288] Change response to represent Future assignments #2550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 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,20 +267,28 @@ def get_course_assignments(self, model: CourseEnrollment) -> Optional[Dict[str,
self.context.get('request'),
include_past_dates=True
)
next_assignment = None
past_assignment = []
past_assignments = []
future_assignments = []

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)
past_assignments.append(assignment)
else:
next_assignment = DateSummarySerializer(assignment).data
break
if not assignment.complete:
future_assignments.append(assignment)

if future_assignments:
future_assignment_date = future_assignments[0].date.date()
next_assignments = [
assignment for assignment in future_assignments if assignment.date.date() == future_assignment_date
]
else:
next_assignments = []

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

class Meta:
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
Loading