Skip to content

Commit

Permalink
Merge tag '20241112_1102_issue3974_remove_notifications' into develop
Browse files Browse the repository at this point in the history
Strip out some unused notifications
  • Loading branch information
Steven-Eardley committed Nov 12, 2024
2 parents 74ee3a4 + 2392ec2 commit ae907eb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 161 deletions.
81 changes: 42 additions & 39 deletions doajtest/functional/make_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from portality import constants
from portality import models, app_email
from portality.core import app
from portality.bll import DOAJ
from portality.events.consumers import application_assed_assigned_notify, \
application_assed_inprogress_notify, \
application_editor_completed_notify, \
Expand All @@ -30,34 +31,36 @@

USER = "richard"

NOTIFICATIONS = [
"application_assed_assigned_notify",
"application_assed_inprogress_notify",
"application_editor_completed_notify",
"application_editor_group_assigned_notify",
"application_editor_inprogress_notify",
"application_maned_ready_notify",
"application_publisher_accepted_notify",
"application_publisher_assigned_notify",
"application_publisher_created_notify",
"application_publisher_inprogress_notify",
"application_publisher_quickreject_notify",
"application_publisher_revision_notify",
"bg_job_finished_notify",
"journal_assed_assigned_notify",
"journal_editor_group_assigned_notify",
"update_request_publisher_accepted_notify",
"update_request_publisher_assigned_notify",
"update_request_publisher_rejected_notify",
UpdateRequestPublisherSubmittedNotify.ID,
]
NOTIFICATIONS = [ec.ID for ec in DOAJ.eventsService().EVENT_CONSUMERS]

# NOTIFICATIONS = [
# "application_assed_assigned_notify",
# "application_assed_inprogress_notify",
# "application_editor_completed_notify",
# "application_editor_group_assigned_notify",
# "application_editor_inprogress_notify",
# "application_maned_ready_notify",
# "application_publisher_accepted_notify",
# "application_publisher_assigned_notify",
# "application_publisher_created_notify",
# "application_publisher_inprogress_notify",
# "application_publisher_quickreject_notify",
# "application_publisher_revision_notify",
# "bg_job_finished_notify",
# "journal_assed_assigned_notify",
# "journal_editor_group_assigned_notify",
# "update_request_publisher_accepted_notify",
# "update_request_publisher_assigned_notify",
# "update_request_publisher_rejected_notify",
# UpdateRequestPublisherSubmittedNotify.ID,
# ]

app.config["ENABLE_EMAIL"] = True
app_email.Mail = MockMail

##############################################
## ApplicationAssedAssignedNotify
if "application_assed_assigned_notify" in NOTIFICATIONS:
if "application:assed:assigned:notify" in NOTIFICATIONS:
aaan_application = ApplicationFixtureFactory.make_application_source()
aaan_application["admin"]["editor"] = USER
aaan_application["bibjson"]["title"] = "Application Assed Assigned Notify"
Expand All @@ -71,7 +74,7 @@

##############################################
## ApplicationAssedAssignedNotify
if "application_assed_inprogress_notify" in NOTIFICATIONS:
if "application:assed:inprogress:notify" in NOTIFICATIONS:
aain_application = ApplicationFixtureFactory.make_application_source()
aain_application["admin"]["editor"] = USER
aain_application["bibjson"]["title"] = "Application Assed In Progress Notify"
Expand All @@ -85,7 +88,7 @@

##############################################
## ApplicationEditorCompletedNotify
if "application_editor_completed_notify" in NOTIFICATIONS:
if "application:editor:completed:notify" in NOTIFICATIONS:
def editor_group_mock_pull(editor_group_id):
return EditorGroup(**{
"editor": USER
Expand All @@ -109,7 +112,7 @@ def editor_group_mock_pull(editor_group_id):

##############################################
## ApplicationEditorGroupAssignedNotify
if "application_editor_group_assigned_notify" in NOTIFICATIONS:
if "application:editor_group:assigned:notify" in NOTIFICATIONS:
def editor_group_mock_pull(key, value):
return EditorGroup(**{
"editor": USER
Expand All @@ -133,7 +136,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationEditorInprogressNotify
if "application_editor_inprogress_notify" in NOTIFICATIONS:
if "application:editor:inprogress:notify" in NOTIFICATIONS:
def editor_group_mock_pull(editor_group_id):
return EditorGroup(**{
"editor": USER
Expand All @@ -157,7 +160,7 @@ def editor_group_mock_pull(editor_group_id):

##############################################
## ApplicationManedReadyNotify
if "application_maned_ready_notify" in NOTIFICATIONS:
if "application:maned:ready:notify" in NOTIFICATIONS:
def editor_group_mock_pull(key, value):
return EditorGroup(**{
"maned": USER
Expand All @@ -181,7 +184,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherAcceptedNotify
if "application_publisher_accepted_notify" in NOTIFICATIONS:
if "application:publisher:accepted:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher Accepted Notify"
Expand All @@ -195,7 +198,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherAssignedNotify
if "application_publisher_assigned_notify" in NOTIFICATIONS:
if "application:publisher:assigned:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher Assigned Notify"
Expand All @@ -209,7 +212,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherCreatedNotify
if "application_publisher_created_notify" in NOTIFICATIONS:
if "application:publisher:created:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher Created Notify"
Expand All @@ -223,7 +226,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherInprogressNotify
if "application_publisher_inprogress_notify" in NOTIFICATIONS:
if "application:publisher:inprogress:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher In Progress Notify"
Expand All @@ -237,7 +240,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherQuickRejectNotify
if "application_publisher_quickreject_notify" in NOTIFICATIONS:
if "application:publisher:quickreject:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher Quick Reject Notify"
Expand All @@ -251,7 +254,7 @@ def editor_group_mock_pull(key, value):

##############################################
## ApplicationPublisherQuickRejectNotify
if "application_publisher_revision_notify" in NOTIFICATIONS:
if "application:publisher:revision:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Application Publisher Revision Notify"
Expand All @@ -267,7 +270,7 @@ def editor_group_mock_pull(key, value):
## BGJobFinishedNotify
if "bg_job_finished_notify" in NOTIFICATIONS:
job = models.BackgroundJob(**{
"id": "bg_job_finished_notify",
"id": "bg:job_finished:notify",
"user": USER,
"action": "bg_job_finished_notify",
"status": "complete"
Expand All @@ -281,7 +284,7 @@ def editor_group_mock_pull(key, value):

##############################################
## JournalAssedAssignedNotify
if "journal_assed_assigned_notify" in NOTIFICATIONS:
if "journal:assed:assigned:notify" in NOTIFICATIONS:
journal = JournalFixtureFactory.make_journal_source(in_doaj=True)
journal["admin"]["editor"] = USER
journal["bibjson"]["title"] = "Journal Assed Assigned Notify"
Expand All @@ -295,7 +298,7 @@ def editor_group_mock_pull(key, value):

##############################################
## JournalEditorGroupAssignedNotify
if "journal_editor_group_assigned_notify" in NOTIFICATIONS:
if "journal:editor_group:assigned:notify" in NOTIFICATIONS:
def editor_group_mock_pull(key, value):
return EditorGroup(**{
"editor": USER
Expand All @@ -320,7 +323,7 @@ def editor_group_mock_pull(key, value):

##############################################
## UpdateRequestPublisherAcceptedNotify
if "update_request_publisher_accepted_notify" in NOTIFICATIONS:
if "update_request:publisher:accepted:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Update Request Publisher Accepted Notify"
Expand All @@ -334,7 +337,7 @@ def editor_group_mock_pull(key, value):

##############################################
## UpdateRequestPublisherAssignedNotify
if "update_request_publisher_assigned_notify" in NOTIFICATIONS:
if "update_request:publisher:assigned:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Update Request Publisher Assigned Notify"
Expand All @@ -348,7 +351,7 @@ def editor_group_mock_pull(key, value):

##############################################
## UpdateRequestPublisherRejectedNotify
if "update_request_publisher_rejected_notify" in NOTIFICATIONS:
if "update_request:publisher:rejected:notify" in NOTIFICATIONS:
application = ApplicationFixtureFactory.make_application_source()
application["admin"]["owner"] = USER
application["bibjson"]["title"] = "Update Request Publisher Rejected Notify"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,7 @@ def test_01_maned_review_emails(self):
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')

publisher_template = re.escape(templates.EMAIL_NOTIFICATION)
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Directory of Open Access Journals - Your application ({}) has been assigned to an editor for review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)

assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 2
assert len(re.findall(email_count_string, info_stream_contents)) == 1

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -553,16 +544,7 @@ def test_02_ed_review_emails(self):
info_stream_contents,
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')

publisher_template = templates.EMAIL_NOTIFICATION
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Your update request ({}) has been assigned to an editor for review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)
assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 2
assert len(re.findall(email_count_string, info_stream_contents)) == 1

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -665,17 +647,8 @@ def test_03_assoc_ed_review_emails(self):
processor.finalise()
info_stream_contents = self.info_stream.getvalue()

# We expect one email to be sent here:
# * to the publisher, notifying that an editor is viewing their application
publisher_template = re.escape(templates.EMAIL_NOTIFICATION)
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Directory of Open Access Journals - Your submission ({}) is under review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)
assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 1
# We expect no emails
assert len(re.findall(email_count_string, info_stream_contents)) == 0

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -936,17 +909,7 @@ def test_01_maned_review_emails(self):
info_stream_contents,
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')

publisher_template = templates.EMAIL_NOTIFICATION
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Your update request ({}) has been assigned to an editor for review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)

assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 2
assert len(re.findall(email_count_string, info_stream_contents)) == 1

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -1125,16 +1088,7 @@ def test_02_ed_review_emails(self):
info_stream_contents,
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')

publisher_template = templates.EMAIL_NOTIFICATION
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Your update request ({}) has been assigned to an editor for review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)
assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 2
assert len(re.findall(email_count_string, info_stream_contents)) == 1

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -1240,17 +1194,8 @@ def test_03_assoc_ed_review_emails(self):
processor.finalise()
info_stream_contents = self.info_stream.getvalue()

# We expect one email to be sent here:
# * to the publisher, notifying that an editor is viewing their application
publisher_template = re.escape(templates.EMAIL_NOTIFICATION)
publisher_to = re.escape(owner.email)
publisher_subject = re.escape('Your submission ({}) is under review'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

publisher_email_matched = re.search(email_log_regex % (publisher_template, publisher_to, publisher_subject),
info_stream_contents,
re.DOTALL)
assert bool(publisher_email_matched)
assert len(re.findall(email_count_string, info_stream_contents)) == 1
# We expect no email to be sent
assert len(re.findall(email_count_string, info_stream_contents)) == 0

# Clear the stream for the next part
self.info_stream.truncate(0)
Expand Down Expand Up @@ -1328,27 +1273,8 @@ def test_01_maned_review_emails(self):
# check the associate was changed
assert processor.target.editor == "associate_3"

# We expect 2 emails to be sent:
# * to the editor of the assigned group,
# * to the AssEd who's been assigned,
editor_template = re.escape(templates.EMAIL_NOTIFICATION)
editor_to = re.escape('[email protected]')
editor_subject = re.escape('Directory of Open Access Journals - New journal ({}) assigned to your group'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

editor_email_matched = re.search(email_log_regex % (editor_template, editor_to, editor_subject),
info_stream_contents,
re.DOTALL)
assert bool(editor_email_matched)

assEd_template = re.escape(templates.EMAIL_NOTIFICATION)
assEd_to = re.escape(models.Account.pull('associate_3').email)
assEd_subject = re.escape('Directory of Open Access Journals - New journal ({}) assigned to you'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

assEd_email_matched = re.search(email_log_regex % (assEd_template, assEd_to, assEd_subject),
info_stream_contents,
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')
assert len(re.findall(email_count_string, info_stream_contents)) == 2
# We expect no emails to be sent
assert len(re.findall(email_count_string, info_stream_contents)) == 0
ctx.pop()

def test_02_ed_review_emails(self):
Expand All @@ -1369,16 +1295,7 @@ def test_02_ed_review_emails(self):
# check the associate was changed
assert processor.target.editor == "associate_2"

# We expect 1 email to be sent:
# * to the AssEd who's been assigned
assEd_template = re.escape(templates.EMAIL_NOTIFICATION)
assEd_to = re.escape(models.Account.pull('associate_2').email)
assEd_subject = re.escape('Directory of Open Access Journals - New journal ({}) assigned to you'.format(', '.join(issn for issn in processor.source.bibjson().issns())))

assEd_email_matched = re.search(email_log_regex % (assEd_template, assEd_to, assEd_subject),
info_stream_contents,
re.DOTALL)
assert bool(assEd_email_matched), info_stream_contents.strip('\x00')
assert len(re.findall(email_count_string, info_stream_contents)) == 1
# We no email to be sent
assert len(re.findall(email_count_string, info_stream_contents)) == 0

ctx.pop()
Loading

0 comments on commit ae907eb

Please sign in to comment.