Skip to content
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
2 changes: 1 addition & 1 deletion src/forum/backends/mysql/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def threads_presentor(
is_read, unread_count = read_states.get(
str(thread.pk), (False, thread.comment_count)
)
is_endorsed = threads_endorsed.get(thread.pk, False)
is_endorsed = threads_endorsed.get(str(thread.pk), False)
abuse_flagged_count = threads_flagged.get(str(thread.pk), 0)
presenters.append(
cls.prepare_thread(
Expand Down
50 changes: 49 additions & 1 deletion tests/test_backends/test_mysql/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.auth import get_user_model

from forum.backends.mysql.api import MySQLBackend as backend
from forum.backends.mysql.models import AbuseFlagger, CommentThread, CourseStat
from forum.backends.mysql.models import AbuseFlagger, Comment, CommentThread, CourseStat
from forum.serializers.thread import ThreadSerializer

User = get_user_model()
Expand Down Expand Up @@ -175,6 +175,54 @@ def test_update_stats_for_course_calls_build_course_stats() -> None:
mock_build_course_stats.assert_called_once_with(str(user.pk), course_id)


@pytest.mark.django_db
def test_threads_presentor_includes_endorsed_status() -> None:
"""Test that threads_presentor marks threads with an endorsed response as endorsed."""
user = User.objects.create(username="testuser")
course_id = "course123"
answered_thread = CommentThread.objects.create(
author=user,
course_id=course_id,
title="Answered question",
body="This question has an endorsed response",
thread_type="question",
context="course",
)
unanswered_thread = CommentThread.objects.create(
author=user,
course_id=course_id,
title="Unanswered question",
body="This question has no endorsed response",
thread_type="question",
context="course",
)
Comment.objects.create(
author=user,
course_id=course_id,
body="Endorsed response",
comment_thread=answered_thread,
endorsed=True,
)
Comment.objects.create(
author=user,
course_id=course_id,
body="Unendorsed response",
comment_thread=unanswered_thread,
)

presented = backend.threads_presentor(
[str(answered_thread.pk), str(unanswered_thread.pk)],
str(user.pk),
course_id,
)

endorsed_by_id = {str(thread["_id"]): thread["endorsed"] for thread in presented}
assert endorsed_by_id == {
str(answered_thread.pk): True,
str(unanswered_thread.pk): False,
}


@pytest.mark.django_db
class TestMongoAPI(unittest.TestCase):
"""
Expand Down
Loading