Skip to content

Commit

Permalink
apps/moderatorfeedback: add ai_report serialiser
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Aug 14, 2023
1 parent 208f7c0 commit 45d197a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/ai_reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ class AiReport(TimeStampedModel):
on_delete=models.CASCADE,
related_name="ai_report",
)

def __str__(self):
return "%s" % (self.explanation)
13 changes: 13 additions & 0 deletions apps/ai_reports/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework import serializers

from apps.ai_reports.models import AiReport


class AiReportSerializer(serializers.ModelSerializer):
class Meta:
model = AiReport
fields = (
"explanation",
"category",
"comment",
)
5 changes: 2 additions & 3 deletions apps/moderatorfeedback/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ def get_last_edit(self, feedback):

class CommentWithFeedbackSerializer(a4_serializers.CommentSerializer):
moderator_feedback = ModeratorCommentFeedbackSerializer(read_only=True)
ai_report = serializers.StringRelatedField(read_only=True)

class Meta:
model = Comment
read_only_fields = a4_serializers.CommentSerializer.Meta.read_only_fields + (
"moderator_comment_feedback",
)
read_only_fields = a4_serializers.CommentSerializer.Meta.read_only_fields
exclude = ("creator",)


Expand Down
3 changes: 3 additions & 0 deletions changelog/7571.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Ai report serializer for comments viewset (#7571)
2 changes: 2 additions & 0 deletions tests/moderatorfeedback/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pytest_factoryboy import register

from tests.ai_reports.factories import AiReportFactory
from tests.ideas.factories import IdeaFactory

from .factories import ModeratorCommentFeedbackFactory

register(AiReportFactory)
register(IdeaFactory)
register(ModeratorCommentFeedbackFactory)
33 changes: 33 additions & 0 deletions tests/moderatorfeedback/test_moderator_comment_feedback_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
from apps.moderatorfeedback.models import ModeratorCommentFeedback


@pytest.mark.django_db
def test_moderator_and_ai_report_added_in_comment(
idea,
comment_factory,
apiclient,
moderator_comment_feedback_factory,
ai_report_factory,
):
comment = comment_factory(content_object=idea)
feedback = moderator_comment_feedback_factory(
comment=comment,
)
assert feedback.project == comment.project

ai_report = ai_report_factory(comment=comment)
url = reverse(
"comments-detail",
kwargs={
"pk": comment.pk,
"content_type": comment.content_type.pk,
"object_pk": comment.object_pk,
},
)
response = apiclient.get(url)
assert (
feedback.feedback_text in response.data["moderator_feedback"]["feedback_text"]
)
assert comment.ai_report.explanation == ai_report.explanation

assert ai_report.explanation in response.data["ai_report"]
assert response.status_code == 200


@pytest.mark.django_db
def test_anonymous_cannot_add_feedback(apiclient, idea, comment_factory):
comment = comment_factory(pk=1, content_object=idea)
Expand Down

0 comments on commit 45d197a

Please sign in to comment.