Skip to content

Commit

Permalink
Fix user status in translation comments (mozilla#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathjazz authored Oct 14, 2024
1 parent 8ed6f69 commit 4dec832
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pontoon/base/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def __str__(self):
return self.content

def serialize(self):
locale = self.locale or self.translation.locale
return {
"author": self.author.name_or_email,
"username": self.author.username,
"user_status": self.author.status(self.locale),
"user_status": self.author.status(locale),
"user_gravatar_url_small": self.author.gravatar_url(88),
"created_at": self.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": self.timestamp.isoformat(),
Expand Down
33 changes: 33 additions & 0 deletions pontoon/base/tests/models/test_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from pontoon.test.factories import TeamCommentFactory, TranslationCommentFactory


@pytest.mark.django_db
def test_serialize_comments():
tr = TranslationCommentFactory.create()
team = TeamCommentFactory.create()

assert tr.serialize() == {
"author": tr.author.name_or_email,
"username": tr.author.username,
"user_status": tr.author.status(tr.translation.locale),
"user_gravatar_url_small": tr.author.gravatar_url(88),
"created_at": tr.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": tr.timestamp.isoformat(),
"content": tr.content,
"pinned": tr.pinned,
"id": tr.id,
}

assert team.serialize() == {
"author": team.author.name_or_email,
"username": team.author.username,
"user_status": team.author.status(team.locale),
"user_gravatar_url_small": team.author.gravatar_url(88),
"created_at": team.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": team.timestamp.isoformat(),
"content": team.content,
"pinned": team.pinned,
"id": team.id,
}
20 changes: 20 additions & 0 deletions pontoon/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from pontoon.base.models import (
ChangedEntityLocale,
Comment,
Entity,
Locale,
LocaleCodeHistory,
Expand Down Expand Up @@ -142,6 +143,25 @@ class IdenticalTranslationFactory(TranslationFactory):
entity = SubFactory(EntityFactory, string=SelfAttribute("..string"))


class TranslationCommentFactory(DjangoModelFactory):
content = Sequence(lambda n: f"Comment {n}")
author = SubFactory(UserFactory)
translation = SubFactory(TranslationFactory)

class Meta:
model = Comment


class TeamCommentFactory(DjangoModelFactory):
content = Sequence(lambda n: f"Comment {n}")
author = SubFactory(UserFactory)
entity = SubFactory(EntityFactory)
locale = SubFactory(LocaleFactory)

class Meta:
model = Comment


class TranslationMemoryFactory(DjangoModelFactory):
source = Sequence(lambda n: f"source {n}")
target = Sequence(lambda n: f"target {n}")
Expand Down

0 comments on commit 4dec832

Please sign in to comment.