Skip to content

Commit

Permalink
Merge branch 'hotfix/discontinued_date_test_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Aug 8, 2023
2 parents b6b1a71 + fb33c36 commit f7d8b01
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions doajtest/unit/test_task_discontinued_soon.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import unittest
import datetime

from doajtest.helpers import DoajTestCase
from doajtest.helpers import DoajTestCase, patch_config

from portality.core import app
from portality import models
from portality.tasks import find_discontinued_soon
from portality.ui.messages import Messages
from doajtest.fixtures import JournalFixtureFactory

DELTA = app.config.get('DISCONTINUED_DATE_DELTA',1)
# Expect a notification for journals discontinuing in 1 days time (tomorrow)
DELTA = 1


class TestDiscontinuedSoon(DoajTestCase):

def _date_to_found(self):
@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')

def _date_too_late(self):
@staticmethod
def _date_too_late():
return (datetime.datetime.today() + datetime.timedelta(days=DELTA+1)).strftime('%Y-%m-%d')

def test_discontinued_soon_found(self):
Expand All @@ -26,14 +41,14 @@ def test_discontinued_soon_found(self):
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_found()
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_found()
jbib.discontinued_date = self._date_to_find()
journal_discontinued_to_found_2.save(blocking=True)

# that shouldn't be found
Expand All @@ -48,9 +63,10 @@ def test_discontinued_soon_found(self):
task = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask(job)
task.run()

assert len(job.audit) == 2
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):

Expand All @@ -66,7 +82,7 @@ def test_discontinued_soon_not_found(self):
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_found()
jbib.discontinued_date = self._date_to_find()
journal_not_in_doaj.save(blocking=True)

job = find_discontinued_soon.FindDiscontinuedSoonBackgroundTask.prepare("system")
Expand Down

0 comments on commit f7d8b01

Please sign in to comment.