-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from h.models import Mention | ||
from h.presenters.mention_json import MentionJSONPresenter | ||
|
||
|
||
class TestMentionJSONPresenter: | ||
def test_as_dict(self, user, annotation): | ||
mention = Mention(annotation=annotation, user=user, username=user.username) | ||
|
||
data = MentionJSONPresenter(mention).asdict() | ||
|
||
assert data == { | ||
"userid": user.userid, | ||
"username": user.username, | ||
"display_name": user.display_name, | ||
"link": user.uri, | ||
} | ||
|
||
@pytest.fixture | ||
def user(self, factories): | ||
return factories.User.build() | ||
|
||
@pytest.fixture | ||
def annotation(self, factories): | ||
return factories.Annotation.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from h.services import MentionService | ||
|
||
|
||
class TestMentionService: | ||
def test_update_mentions( | ||
self, db_session, mention_service, user_service, annotation, user | ||
): | ||
annotation.text = f'Hello <a data-hyp-mention data-userid="{user.userid}">@{user.display_name}</a>' | ||
user_service.fetch_all.return_value = [user] | ||
|
||
mention_service.update_mentions(annotation) | ||
|
||
assert len(annotation.mentions) == 1 | ||
assert annotation.mentions[0].user == user | ||
|
||
@pytest.fixture | ||
def annotation(self, factories): | ||
return factories.Annotation() | ||
|
||
@pytest.fixture | ||
def user(self, factories): | ||
return factories.User() | ||
|
||
|
||
@pytest.fixture | ||
def mention_service(db_session, user_service): | ||
return MentionService(db_session, user_service) |