-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add maned update request assigned notification
- Loading branch information
1 parent
04e708d
commit 65adf10
Showing
4 changed files
with
140 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
doajtest/unit/event_consumers/test_update_request_maned_editor_group_assigned_notify.py
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,79 @@ | ||
from portality import models | ||
from portality import constants | ||
from portality.bll import exceptions | ||
from doajtest.helpers import DoajTestCase | ||
from portality.events.consumers.update_request_maned_editor_group_assigned_notify import UpdateRequestManedEditorGroupAssignedNotify | ||
from doajtest.fixtures import ApplicationFixtureFactory | ||
import time | ||
|
||
|
||
class TestUpdateRequestManedEditorGroupAssignedNotify(DoajTestCase): | ||
def setUp(self): | ||
super(TestUpdateRequestManedEditorGroupAssignedNotify, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TestUpdateRequestManedEditorGroupAssignedNotify, self).tearDown() | ||
|
||
def test_should_consume(self): | ||
event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application" : {}}) | ||
assert UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) | ||
|
||
event = models.Event("test:event", context={"application" : {}}) | ||
assert not UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) | ||
|
||
event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED) | ||
assert not UpdateRequestManedEditorGroupAssignedNotify.should_consume(event) | ||
|
||
def test_consume_success(self): | ||
with self._make_and_push_test_context_manager("/"): | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
app.application_type = constants.APPLICATION_TYPE_UPDATE_REQUEST | ||
|
||
acc = models.Account() | ||
acc.set_id("maned") | ||
acc.set_email("[email protected]") | ||
acc.save() | ||
|
||
eg = models.EditorGroup() | ||
eg.set_name(app.editor_group) | ||
eg.set_maned("maned") | ||
eg.save(blocking=True) | ||
|
||
event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application" : app.data}) | ||
UpdateRequestManedEditorGroupAssignedNotify.consume(event) | ||
|
||
time.sleep(1) | ||
ns = models.Notification.all() | ||
assert len(ns) == 1 | ||
|
||
n = ns[0] | ||
assert n.who == "maned" | ||
assert n.created_by == UpdateRequestManedEditorGroupAssignedNotify.ID | ||
assert n.classification == constants.NOTIFICATION_CLASSIFICATION_ASSIGN | ||
assert n.long is not None | ||
assert n.short is not None | ||
assert n.action is not None | ||
assert not n.is_seen() | ||
|
||
def test_consume_fail(self): | ||
event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application": {"key" : "value"}}) | ||
with self.assertRaises(exceptions.NoSuchObjectException): | ||
UpdateRequestManedEditorGroupAssignedNotify.consume(event) | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
app.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION | ||
# app.save(blocking=True) | ||
|
||
eg = models.EditorGroup() | ||
eg.set_name(app.editor_group) | ||
eg.save(blocking=True) | ||
|
||
event = models.Event(constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED, context={"application": app.data}) | ||
UpdateRequestManedEditorGroupAssignedNotify.consume(event) | ||
|
||
time.sleep(1) | ||
ns = models.Notification.all() | ||
assert len(ns) == 0 |
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
53 changes: 53 additions & 0 deletions
53
portality/events/consumers/update_request_maned_editor_group_assigned_notify.py
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,53 @@ | ||
# ~~ ApplicatioditorGroupAssignedNotify:Consumer~~ | ||
from portality.events import consumer_utils | ||
from portality.util import url_for | ||
from portality.events.consumer import EventConsumer | ||
from portality import constants | ||
from portality import models | ||
from portality.bll import DOAJ | ||
from portality.bll import exceptions | ||
|
||
|
||
class UpdateRequestManedEditorGroupAssignedNotify(EventConsumer): | ||
ID = "update_request:maned:editor_group_assigned:notify" | ||
|
||
@classmethod | ||
def should_consume(cls, event): | ||
return event.id == constants.EVENT_APPLICATION_EDITOR_GROUP_ASSIGNED and \ | ||
event.context.get("application") is not None | ||
|
||
@classmethod | ||
def consume(cls, event): | ||
app_source = event.context.get("application") | ||
|
||
application = consumer_utils.parse_application(app_source) | ||
|
||
if application.application_type != constants.APPLICATION_TYPE_UPDATE_REQUEST: | ||
return | ||
|
||
if not application.editor_group: | ||
return | ||
|
||
editor_group = models.EditorGroup.pull_by_key("name", application.editor_group) | ||
|
||
if not editor_group.maned: | ||
raise exceptions.NoSuchPropertyException("Editor Group {x} does not have property `maned`".format(x=editor_group.id)) | ||
|
||
# ~~-> Notifications:Service ~~ | ||
svc = DOAJ.notificationsService() | ||
|
||
notification = models.Notification() | ||
notification.who = editor_group.maned | ||
notification.created_by = cls.ID | ||
notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN | ||
|
||
notification.long = svc.long_notification(cls.ID).format( | ||
journal_title=application.bibjson().title | ||
) | ||
notification.short = svc.short_notification(cls.ID).format( | ||
issns=application.bibjson().issns_as_text() | ||
) | ||
|
||
notification.action = url_for("editor.application", application_id=application.id) | ||
|
||
svc.notify(notification) |