-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/3570_incorrect_issns
- Loading branch information
Showing
40 changed files
with
604 additions
and
105 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
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 |
---|---|---|
|
@@ -8,4 +8,3 @@ featuremap: ~~Team:Fragment->TeamData:Template~~ | |
|
||
--- | ||
|
||
|
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,15 @@ | ||
suite: Public Site | ||
testset: ToC | ||
tests: | ||
- title: Test Correctly Displayed Discontinued Date | ||
context: | ||
role: anonymous | ||
steps: | ||
- step: To prepare to do this test make sure there are 3 journals publically available in DOAJ | ||
one with discontinued date in the past | ||
one with discontinued date in the future | ||
one with discontinued date today | ||
- step: Search for every journal from the list above | ||
results: | ||
- On the ToC of the journal with discontinued date in the past or today - the discontinued date is displayed | ||
- On the ToC of the journal with discontinued date in the future - the discontinued date is not displayed |
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
86 changes: 86 additions & 0 deletions
86
doajtest/unit/event_consumers/test_journal_discontinuing_soon_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,86 @@ | ||
from portality import models | ||
from portality import constants | ||
from portality.bll import exceptions | ||
from doajtest.helpers import DoajTestCase | ||
from doajtest.fixtures import JournalFixtureFactory, ApplicationFixtureFactory | ||
from portality.events.consumers.journal_discontinuing_soon_notify import JournalDiscontinuingSoonNotify | ||
from doajtest.fixtures import BackgroundFixtureFactory | ||
import time | ||
|
||
# Mock required to make application lookup work | ||
@classmethod | ||
def pull_application(cls, id): | ||
app = models.Application(**ApplicationFixtureFactory.make_application_source()) | ||
return app | ||
|
||
@classmethod | ||
def pull_by_key(cls, key, value): | ||
ed = models.EditorGroup() | ||
acc = models.Account() | ||
acc.set_id('testuser') | ||
acc.set_email("test@example.com") | ||
acc.save(blocking=True) | ||
ed.set_maned(acc.id) | ||
ed.save(blocking=True) | ||
|
||
return ed | ||
|
||
class TestJournalDiscontinuingSoonNotify(DoajTestCase): | ||
def setUp(self): | ||
super(TestJournalDiscontinuingSoonNotify, self).setUp() | ||
self.pull_application = models.Application.pull | ||
models.Application.pull = pull_application | ||
self.pull_by_key = models.EditorGroup.pull_by_key | ||
models.EditorGroup.pull_by_key = pull_by_key | ||
|
||
def tearDown(self): | ||
super(TestJournalDiscontinuingSoonNotify, self).tearDown() | ||
models.Application.pull = self.pull_application | ||
models.EditorGroup.pull_by_key = self.pull_by_key | ||
|
||
def test_consumes(self): | ||
|
||
event = models.Event("test:event", context={"data" : {"1234"}}) | ||
assert not JournalDiscontinuingSoonNotify.consumes(event) | ||
|
||
event = models.Event("test:event", context={"data": {}}) | ||
assert not JournalDiscontinuingSoonNotify.consumes(event) | ||
|
||
event = models.Event(constants.EVENT_JOURNAL_DISCONTINUING_SOON) | ||
assert not JournalDiscontinuingSoonNotify.consumes(event) | ||
|
||
event = models.Event(constants.EVENT_JOURNAL_DISCONTINUING_SOON, context = {"journal": {"1234"}, "discontinue_date": "2002-22-02"}) | ||
assert JournalDiscontinuingSoonNotify.consumes(event) | ||
|
||
def test_consume_success(self): | ||
self._make_and_push_test_context("/") | ||
|
||
source = BackgroundFixtureFactory.example() | ||
bj = models.BackgroundJob(**source) | ||
# bj.save(blocking=True) | ||
|
||
acc = models.Account() | ||
acc.set_id('testuser') | ||
acc.set_email("test@example.com") | ||
acc.add_role('admin') | ||
acc.save(blocking=True) | ||
|
||
source = JournalFixtureFactory.make_journal_source() | ||
journal = models.Journal(**source) | ||
journal.save(blocking=True) | ||
|
||
event = models.Event(constants.BACKGROUND_JOB_FINISHED, context={"job" : bj.data, "journal" : journal.id}) | ||
JournalDiscontinuingSoonNotify.consume(event) | ||
|
||
time.sleep(2) | ||
ns = models.Notification.all() | ||
assert len(ns) == 1 | ||
|
||
n = ns[0] | ||
assert n.who == acc.id | ||
assert n.created_by == JournalDiscontinuingSoonNotify.ID | ||
assert n.classification == constants.NOTIFICATION_CLASSIFICATION_STATUS | ||
assert n.long is not None | ||
assert n.short is not None | ||
assert n.action is not None | ||
assert not n.is_seen() |
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,93 @@ | ||
import unittest | ||
import datetime | ||
|
||
from doajtest.helpers import DoajTestCase, patch_config | ||
|
||
from portality import models | ||
from portality.tasks import find_discontinued_soon | ||
from portality.ui.messages import Messages | ||
from doajtest.fixtures import JournalFixtureFactory | ||
|
||
# Expect a notification for journals discontinuing in 1 days time (tomorrow) | ||
DELTA = 1 | ||
|
||
|
||
class TestDiscontinuedSoon(DoajTestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls) -> None: | ||
super().setUpClass() | ||
cls.orig_config = patch_config(cls.app_test, { | ||
'DISCONTINUED_DATE_DELTA': DELTA | ||
}) | ||
|
||
@classmethod | ||
def tearDownClass(cls) -> None: | ||
super().tearDownClass() | ||
patch_config(cls.app_test, cls.orig_config) | ||
|
||
@staticmethod | ||
def _date_to_find(): | ||
return (datetime.datetime.today() + datetime.timedelta(days=DELTA)).strftime('%Y-%m-%d') | ||
|
||
@staticmethod | ||
def _date_too_late(): | ||
return (datetime.datetime.today() + datetime.timedelta(days=DELTA+1)).strftime('%Y-%m-%d') | ||
|
||
def test_discontinued_soon_found(self): | ||
|
||
# Both these should be found | ||
journal_discontinued_to_found_1 = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) | ||
journal_discontinued_to_found_1.set_id("1") | ||
jbib = journal_discontinued_to_found_1.bibjson() | ||
jbib.title = "Discontinued Tomorrow 1" | ||
jbib.discontinued_date = self._date_to_find() | ||
journal_discontinued_to_found_1.save(blocking=True) | ||
|
||
journal_discontinued_to_found_2 = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) | ||
journal_discontinued_to_found_2.set_id("2") | ||
jbib = journal_discontinued_to_found_2.bibjson() | ||
jbib.title = "Discontinued Tomorrow 2" | ||
jbib.discontinued_date = self._date_to_find() | ||
journal_discontinued_to_found_2.save(blocking=True) | ||
|
||
# that shouldn't be found | ||
journal_discontinued_too_late = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) | ||
journal_discontinued_too_late.set_id("3") | ||
jbib = journal_discontinued_too_late.bibjson() | ||
jbib.title = "Discontinued In 2 days" | ||
jbib.discontinued_date = self._date_too_late() | ||
journal_discontinued_too_late.save(blocking=True) | ||
|
||
job = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask.prepare("system") | ||
task = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask(job) | ||
task.run() | ||
|
||
assert len(job.audit) == 3 # Journals 1 & 2, and a message to say notification is sent | ||
assert job.audit[0]["message"] == Messages.DISCONTINUED_JOURNAL_FOUND_LOG.format(id="1") | ||
assert job.audit[1]["message"] == Messages.DISCONTINUED_JOURNAL_FOUND_LOG.format(id="2") | ||
assert job.audit[2]["message"] == Messages.DISCONTINUED_JOURNALS_FOUND_NOTIFICATION_SENT_LOG | ||
|
||
def test_discontinued_soon_not_found(self): | ||
|
||
# None of these should be found - this one discontinues in 2 days | ||
journal_discontinued_too_late = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) | ||
journal_discontinued_too_late.set_id("1") | ||
jbib = journal_discontinued_too_late.bibjson() | ||
jbib.title = "Discontinued In 2 days" | ||
jbib.discontinued_date = self._date_too_late() | ||
journal_discontinued_too_late.save(blocking=True) | ||
|
||
# this one is not in doaj | ||
journal_not_in_doaj = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=False)) | ||
journal_not_in_doaj.set_id("2") | ||
jbib = journal_not_in_doaj.bibjson() | ||
jbib.discontinued_date = self._date_to_find() | ||
journal_not_in_doaj.save(blocking=True) | ||
|
||
job = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask.prepare("system") | ||
task = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask(job) | ||
task.run() | ||
|
||
assert len(job.audit) == 1 | ||
assert job.audit[0]["message"] == Messages.NO_DISCONTINUED_JOURNALS_FOUND_LOG |
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
Oops, something went wrong.