Skip to content

Commit

Permalink
Update mention json payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomilov committed Feb 7, 2025
1 parent a3a53e9 commit c614b6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion h/presenters/mention_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from h.models import Mention
from h.util.user import format_userid


class MentionJSONPresenter:
Expand All @@ -12,7 +13,10 @@ def __init__(self, mention: Mention):
def asdict(self) -> dict[str, Any]:
return {
"userid": self._mention.user.userid,
"username": self._mention.username,
"original_userid": format_userid(
self._mention.username, self._mention.user.authority
),
"username": self._mention.user.username,
"display_name": self._mention.user.display_name,
"link": self._mention.user.uri,
}
10 changes: 10 additions & 0 deletions tests/unit/h/presenters/mention_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from h.models import Mention
from h.presenters.mention_json import MentionJSONPresenter
from h.util.user import format_userid


class TestMentionJSONPresenter:
Expand All @@ -12,11 +13,20 @@ def test_as_dict(self, user, annotation):

assert data == {
"userid": user.userid,
"original_userid": user.userid,
"username": user.username,
"display_name": user.display_name,
"link": user.uri,
}

def test_as_dict_with_different_username(self, user, annotation):
new_username = "new_username"
mention = Mention(annotation=annotation, user=user, username=new_username)

data = MentionJSONPresenter(mention).asdict()

assert data["original_userid"] == format_userid(new_username, user.authority)

@pytest.fixture
def user(self, factories):
return factories.User.build()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/h/services/mention_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_it(self, pyramid_request, user_service, MentionService):
session=pyramid_request.db,
user_service=user_service,
)

assert service == MentionService.return_value

@pytest.fixture
Expand Down

0 comments on commit c614b6f

Please sign in to comment.