-
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
5 changed files
with
222 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from h.emails import reply_notification, reset_password, signup | ||
from h.emails import mention_notification, reply_notification, reset_password, signup | ||
|
||
__all__ = ("mention_notification", "reply_notification", "reset_password", "signup") |
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,86 @@ | ||
from unittest.mock import call | ||
|
||
import pytest | ||
|
||
from h.notification.mention import Notification, get_notifications | ||
|
||
|
||
class TestGetNotifications: | ||
def test_it( | ||
self, annotation, mentioning_user, mentioned_user, pyramid_request, user_service | ||
): | ||
result = get_notifications(pyramid_request, annotation, "create") | ||
|
||
user_service.fetch.assert_has_calls( | ||
[call(mentioning_user.userid), call(mentioned_user.userid)] | ||
) | ||
|
||
assert len(result) == 1 | ||
assert isinstance(result[0], Notification) | ||
assert result[0].mentioning_user == mentioning_user | ||
assert result[0].mentioned_user == mentioned_user | ||
assert result[0].annotation == annotation | ||
assert result[0].document == annotation.document | ||
|
||
def test_it_returns_empty_list_when_action_is_not_create( | ||
self, pyramid_request, annotation | ||
): | ||
assert get_notifications(pyramid_request, annotation, "NOT_CREATE") == [] | ||
|
||
def test_it_returns_empty_list_when_mentioning_user_does_not_exist( | ||
self, pyramid_request, annotation, user_service, factories | ||
): | ||
user_service.fetch.side_effect = (None, factories.User()) | ||
|
||
assert get_notifications(pyramid_request, annotation, "create") == [] | ||
|
||
def test_it_returns_empty_list_when_mentioned_user_does_not_exist( | ||
self, pyramid_request, annotation, user_service, factories | ||
): | ||
user_service.fetch.side_effect = (factories.User(), None) | ||
|
||
assert get_notifications(pyramid_request, annotation, "create") == [] | ||
|
||
def test_it_returns_empty_list_when_mentioned_user_has_no_email_address( | ||
self, pyramid_request, annotation, mentioned_user | ||
): | ||
mentioned_user.email = None | ||
assert get_notifications(pyramid_request, annotation, "create") == [] | ||
|
||
def test_it_returns_empty_list_when_mentioning_the_same_user( | ||
self, pyramid_request, annotation, user_service, factories | ||
): | ||
single_user = factories.User() | ||
user_service.fetch.side_effect = (single_user, single_user) | ||
|
||
assert get_notifications(pyramid_request, annotation, "create") == [] | ||
|
||
def test_it_returns_empty_list_when_annotation_document_is_empty( | ||
self, pyramid_request, annotation | ||
): | ||
annotation.document = None | ||
|
||
assert get_notifications(pyramid_request, annotation, "create") == [] | ||
|
||
@pytest.fixture | ||
def annotation(self, factories, mentioning_user, mention): | ||
return factories.Annotation( | ||
userid=mentioning_user.userid, shared=True, mentions=[mention] | ||
) | ||
|
||
@pytest.fixture | ||
def mentioned_user(self, factories): | ||
return factories.User(nipsa=False) | ||
|
||
@pytest.fixture | ||
def mentioning_user(self, factories): | ||
return factories.User(nipsa=False) | ||
|
||
@pytest.fixture | ||
def mention(self, factories, mentioned_user): | ||
return factories.Mention(user=mentioned_user) | ||
|
||
@pytest.fixture(autouse=True) | ||
def user_service(self, user_service, mentioning_user, mentioned_user): | ||
user_service.fetch.side_effect = (mentioning_user, mentioned_user) | ||
return user_service |
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