Skip to content

Commit

Permalink
Merge pull request #1969 from ResearchHub/paper-serializer-peer-review
Browse files Browse the repository at this point in the history
Return peer reviews with paper view
  • Loading branch information
gzurowski authored Nov 7, 2024
2 parents da8c815 + 508ee1b commit dd2eea1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/paper/serializers/paper_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from researchhub.serializers import DynamicModelFieldSerializer
from researchhub.settings import PAGINATION_PAGE_SIZE, TESTING
from researchhub_document.utils import update_unified_document_to_paper
from review.serializers.peer_review_serializer import PeerReviewSerializer
from user.models import Author
from user.serializers import (
AuthorSerializer,
Expand Down Expand Up @@ -856,6 +857,7 @@ class DynamicPaperSerializer(
file = serializers.SerializerMethodField()
pdf_url = serializers.SerializerMethodField()
pdf_copyright_allows_display = serializers.SerializerMethodField()
peer_reviews = PeerReviewSerializer(many=True, read_only=True)
version = serializers.SerializerMethodField()
version_list = serializers.SerializerMethodField()

Expand Down
19 changes: 19 additions & 0 deletions src/paper/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from paper.models import PaperVersion
from paper.serializers import DynamicPaperSerializer, PaperSerializer
from paper.tests import helpers
from review.models.peer_review_model import PeerReview
from user.tests.helpers import create_random_default_user


class PaperSerializersTests(TestCase):
Expand Down Expand Up @@ -141,3 +143,20 @@ def test_dynamic_paper_serializer_paper_versions(self):
},
],
)

def test_peer_reviews(self):
# Arrange
paper = helpers.create_paper(title="paper1")
user1 = create_random_default_user("user1")
user2 = create_random_default_user("user2")
peer_review1 = PeerReview.objects.create(paper=paper, user=user1)
peer_review2 = PeerReview.objects.create(paper=paper, user=user2)

# Act
actual = DynamicPaperSerializer(paper)

# Assert
self.assertTrue(len(actual.data["peer_reviews"]) == 2)
peer_review_ids = {review["id"] for review in actual.data["peer_reviews"]}
expected_ids = {peer_review1.id, peer_review2.id}
self.assertEqual(peer_review_ids, expected_ids)
2 changes: 2 additions & 0 deletions src/paper/views/paper_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def prefetch_lookups(self):
"hubs__subscribers",
"votes",
"flags",
"peer_reviews",
"purchases",
"threads",
"threads__comments",
Expand Down Expand Up @@ -440,6 +441,7 @@ def retrieve(self, request, *args, **kwargs):
"pdf_license",
"pdf_url",
"pdf_copyright_allows_display",
"peer_reviews",
"purchases",
"raw_authors",
"score",
Expand Down

0 comments on commit dd2eea1

Please sign in to comment.