From 2f93c7ee2f9af9830d03f14b3ca2a45ffbaeed08 Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 8 Nov 2024 17:10:04 -0300 Subject: [PATCH] chore: Updated the place where the list is reversed --- learning_assistant/api.py | 4 ++-- learning_assistant/views.py | 2 +- tests/test_api.py | 4 ++-- tests/test_views.py | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/learning_assistant/api.py b/learning_assistant/api.py index 272e201..2006b26 100644 --- a/learning_assistant/api.py +++ b/learning_assistant/api.py @@ -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 diff --git a/learning_assistant/views.py b/learning_assistant/views.py index 02c3fca..b1b5c03 100644 --- a/learning_assistant/views.py +++ b/learning_assistant/views.py @@ -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) diff --git a/tests/test_api.py b/tests/test_api.py index 8b66845..1344dea 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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)) diff --git a/tests/test_views.py b/tests/test_views.py index 42ad0b3..1d567b8 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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())