-
Notifications
You must be signed in to change notification settings - Fork 19
feature/3991_weekly_email_alert #2549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RK206
wants to merge
9
commits into
develop
Choose a base branch
from
feature/3991_weekly_email_alert
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4af7ae0
Added weekly notification job for article deletion and improved artic…
RK206 5afd898
Merge branch 'develop' of https://github.com/DOAJ/doaj into feature/3…
RK206 a4f6fd3
Added job for weekly notifications to publishers on article deletions
RK206 6fb5fc1
send notification for deleted articles
RK206 b26f7de
Merge branch 'develop' of https://github.com/DOAJ/doaj into feature/3…
RK206 6da3b71
Updated test steps and adjusted cron configuration for article deleti…
RK206 ce2246b
merge up from develop
richard-jones 60fbac3
refactoring, and bringing in new testdrive capabilities for better te…
richard-jones 5958757
final tweak to test script
richard-jones File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
doajtest/testbook/article_deletion_notifications/article_deletion_notifications.yml
This file contains hidden or 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,24 @@ | ||
| suite: Article Deletion Notifications | ||
| testset: Article Deletion Notifications | ||
|
|
||
| tests: | ||
| - title: Article Deletion Notification Generation | ||
| context: | ||
| role: admin | ||
| steps: | ||
| - step: Run the testdrive for deleted_articles to set up the fixtures for this test | ||
| path: /testdrive/deleted_articles | ||
| - step: Log in to the system as an administrator | ||
| - step: Go to the admin notifications page | ||
| path: /admin/notifications | ||
| results: | ||
| - There are no notifications listed for either user account supplied in the testdrive | ||
| - step: Go to the testdrive page without reloading it, and click the button marked "Run background task". | ||
| results: | ||
| - The text beneath the button confirms that the script executed successfully | ||
| - step: Return to the admin notifications page | ||
| results: | ||
| - A new notification is present with the title "Deleted articles in your journal(s) this week". | ||
| - The notification content lists the titles and details of the deleted articles. | ||
| - There is only one notification for the first publisher listed on the testdrive. The second publisher | ||
| does not have a notification |
This file contains hidden or 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 hidden or 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,36 @@ | ||
| from doajtest.testdrive.factory import TestDrive | ||
|
|
||
|
|
||
| class DeletedArticles(TestDrive): | ||
| def setup(self) -> dict: | ||
| # create 2 publisher accounts. The first will have tombstoned articles, | ||
| # the second will not | ||
| publisher1, pw1 = self.publisher_account() | ||
| publisher2, pw2 = self.publisher_account() | ||
|
|
||
| # create one journal for each publisher | ||
| journals1 = self.journals_in_doaj(publisher1, n=1, block=True) | ||
| journals2 = self.journals_in_doaj(publisher2, n=1, block=True) | ||
|
|
||
| # place 10 articles in each journal | ||
| articles1 = self.articles(journals1[0], n=10) | ||
| articles2 = self.articles(journals2[0], n=10) | ||
|
|
||
| # for the first publishers journal, tombstone 10 articles | ||
| tombs1 = self.article_tombstones(journals1[0], n=10) | ||
|
|
||
| report = {} | ||
| self.report_accounts([(publisher1, pw1), (publisher2, pw2)], report) | ||
| self.report_journal_ids(journals1 + journals2, report) | ||
| self.report_article_ids(articles1 + articles2, report) | ||
| self.report_article_tombstone_ids(tombs1, report) | ||
| self.report_script("article_deletion_notifications", "Run background task", report) | ||
|
|
||
| return report | ||
|
|
||
| def teardown(self, params) -> dict: | ||
| self.teardown_accounts(params) | ||
| self.teardown_journals(params) | ||
| self.teardown_articles(params) | ||
| self.teardown_article_tombstones(params) | ||
| return self.SUCCESS |
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
doajtest/unit/test_tasks_article_deletion_notifications.py
This file contains hidden or 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,91 @@ | ||
| from doajtest.helpers import DoajTestCase | ||
| from portality.tasks.article_deletion_notifications import ArticleDeletionNotificationsBackgroundTask | ||
| from portality import models | ||
| from doajtest.fixtures.article import ArticleFixtureFactory | ||
| from doajtest.fixtures.accounts import AccountFixtureFactory | ||
| from portality.lib import dates | ||
| import time | ||
|
|
||
| class TestArticleDeletionNotifications(DoajTestCase): | ||
|
|
||
| def test_article_deletion_notifications(self): | ||
| # 1. Setup data | ||
| # Create two publishers | ||
| pub1 = models.Account(**AccountFixtureFactory.make_publisher_source()) | ||
| pub1.set_id("pub1") | ||
| pub1.save(blocking=True) | ||
|
|
||
| pub2 = models.Account(**AccountFixtureFactory.make_publisher_source()) | ||
| pub2.set_id("pub2") | ||
| pub2.save(blocking=True) | ||
|
|
||
| # Create some ArticleTombstones | ||
| # Recent tombstone for pub1 | ||
| at1 = models.ArticleTombstone(**ArticleFixtureFactory.make_article_source()) | ||
| at1.set_id("at1") | ||
| at1.set_created(dates.format(dates.before_now(1 * 24 * 60 * 60))) | ||
| at1.data['admin'] = {'owner': 'pub1'} | ||
| at1.save(blocking=True) | ||
|
|
||
| # Another recent tombstone for pub1 | ||
| at2 = models.ArticleTombstone(**ArticleFixtureFactory.make_article_source()) | ||
| at2.set_id("at2") | ||
| at2.set_created(dates.format(dates.before_now(2 * 24 * 60 * 60))) | ||
| at2.data['admin'] = {'owner': 'pub1'} | ||
| at2.save(blocking=True) | ||
|
|
||
| # Recent tombstone for pub2 | ||
| at3 = models.ArticleTombstone(**ArticleFixtureFactory.make_article_source()) | ||
| at3.set_id("at3") | ||
| at3.set_created(dates.format(dates.before_now(3 * 24 * 60 * 60))) | ||
| at3.data['admin'] = {'owner': 'pub2'} | ||
| at3.save(blocking=True) | ||
|
|
||
| # Old tombstone (should be ignored) | ||
| at4 = models.ArticleTombstone(**ArticleFixtureFactory.make_article_source()) | ||
| at4.set_id("at4") | ||
| at4.set_created(dates.format(dates.before_now(10 * 24 * 60 * 60))) | ||
| at4.data['admin'] = {'owner': 'pub1'} | ||
| at4.save(blocking=True) | ||
|
|
||
| # 2. Run the task | ||
| job = ArticleDeletionNotificationsBackgroundTask.prepare("system") | ||
| task = ArticleDeletionNotificationsBackgroundTask(job) | ||
| task.run() | ||
|
|
||
| time.sleep(2) | ||
|
|
||
| # 3. Verify notifications | ||
| # Pub1 should have 1 notification with 2 articles | ||
| notes1 = models.Notification.all() | ||
| self.assertEqual(len(notes1), 2) | ||
|
|
||
| note1 = None | ||
| for n in notes1: | ||
| if n.who == "pub1": | ||
| note1 = n | ||
| break | ||
|
|
||
| self.assertIsNotNone(note1) | ||
| self.assertIn("Deleted articles in your journal(s) this week", note1.short) | ||
| # It should contain titles of at1 and at2, but not at4 | ||
| # We need to be careful about what make_article_source produces as titles | ||
|
|
||
| # Pub2 should have 1 notification with 1 article | ||
| note2 = None | ||
| for n in notes1: | ||
| if n.who == "pub2": | ||
| note2 = n | ||
| break | ||
| self.assertIsNotNone(note2) | ||
|
|
||
| def test_no_articles(self): | ||
| # Run task without any tombstones | ||
| job = ArticleDeletionNotificationsBackgroundTask.prepare("system") | ||
| task = ArticleDeletionNotificationsBackgroundTask(job) | ||
| task.run() | ||
|
|
||
| # Verify no notifications sent | ||
| notes = models.Notification.all() | ||
| self.assertEqual(len(notes), 0) | ||
| self.assertIn("No deleted articles in the last week", job.audit[0]['message']) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.