Skip to content

Commit

Permalink
chore: Updated the place where the list is reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Nov 8, 2024
1 parent cc51613 commit 2f93c7e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions learning_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,6 @@ def get_message_history(courserun_key, user, message_count):
Returns a number of messages equal to the message_count value.
"""
message_history = LearningAssistantMessage.objects.filter(
course_id=courserun_key, user=user).order_by('-created')[:message_count]
message_history = list(LearningAssistantMessage.objects.filter(
course_id=courserun_key, user=user).order_by('-created')[:message_count])[::-1]
return message_history
2 changes: 1 addition & 1 deletion learning_assistant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ def get(self, request, course_run_id):
user = request.user

message_count = int(request.GET.get('message_count', 50))
message_history = reversed(list(get_message_history(courserun_key, user, message_count))) # Reversing order
message_history = get_message_history(courserun_key, user, message_count)
data = MessageSerializer(message_history, many=True).data
return Response(status=http_status.HTTP_200_OK, data=data)
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def test_get_message_history(self):

return_value = get_message_history(self.course_key, self.user, message_count)

expected_value = LearningAssistantMessage.objects.filter(
course_id=self.course_key, user=self.user).order_by('-created')[:message_count]
expected_value = list(LearningAssistantMessage.objects.filter(
course_id=self.course_key, user=self.user).order_by('-created')[:message_count])[::-1]

# Ensure same number of entries
self.assertEqual(len(return_value), len(expected_value))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_learning_message_history_view_get(
self.assertEqual(len(data), db_messages_count)

# Ensure values are as expected
for i, expected in enumerate(db_messages):
self.assertEqual(expected.role, data[i]['role'])
self.assertEqual(expected.content, data[i]['content'])
self.assertEqual(expected.created.isoformat(), data[i]['timestamp'])
for i, message in enumerate(data):
self.assertEqual(message['role'], db_messages[i].role)
self.assertEqual(message['content'], db_messages[i].content)
self.assertEqual(message['timestamp'], db_messages[i].created.isoformat())

0 comments on commit 2f93c7e

Please sign in to comment.