Skip to content

Commit

Permalink
#280 Add review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
viliambalaz committed Jul 11, 2021
1 parent 736508d commit 7c2bd35
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions chcemvediet/apps/inforequests/tests/test_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

class CronTestCaseMixin(TestCase):

def _pre_setup(self):
super(CronTestCaseMixin, self)._pre_setup()
Inforequest.objects.all().delete()

def _call_runcrons(self):
# ``runcrons`` command runs ``logging.debug()`` that somehow spoils stderr.
with mock.patch(u'django_cron.logging'):
Expand All @@ -39,13 +35,13 @@ def assert_times_job_is_run_at(self, cronjob):
)

for time, expected in tests:
timewarp.jump(date=local_datetime_from_local(u'2010-10-05 %s' % time))
timewarp.jump(date=local_datetime_from_local(u'2010-10-05 {}'.format(time)))
with mock_cron_jobs() as mock_jobs:
self._call_runcrons()
if expected:
self.assertEqual(mock_jobs[cronjob].call_count, 1, u'Cron job was not run at %s.' % time)
self.assertEqual(mock_jobs[cronjob].call_count, 1, u'Cron job was not run at {}.'.format(time))
else:
self.assertEqual(mock_jobs[cronjob].call_count, 0, u'Cron job not run at %s.' % time)
self.assertEqual(mock_jobs[cronjob].call_count, 0, u'Cron job not run at {}.'.format(time))


class UndecidedEmailReminderCronJobTest(CronTestCaseMixin, InforequestsTestCaseMixin, TestCase):
Expand Down Expand Up @@ -325,7 +321,7 @@ def test_reminder_is_not_sent_if_last_action_snooze_is_not_missed(self):
inforequest, _, _ = self._create_inforequest_scenario(
u'clarification_request',
# snooze is missed at 2010-10-14
(u'clarification_response', dict(delivered_date=naive_date(u'2010-10-05'))),
u'clarification_response',
)

timewarp.jump(local_datetime_from_local(u'2010-10-10 10:33:00'))
Expand All @@ -337,7 +333,7 @@ def test_reminder_is_sent_if_last_action_snooze_is_missed(self):
inforequest, _, _ = self._create_inforequest_scenario(
u'clarification_request',
# snooze is missed at 2010-10-14
(u'clarification_response', dict(delivered_date=naive_date(u'2010-10-05'))),
u'clarification_response',
)

timewarp.jump(local_datetime_from_local(u'2010-10-14 10:33:00'))
Expand All @@ -350,7 +346,7 @@ def test_reminder_is_not_sent_if_last_action_snooze_was_already_missed_when_last
inforequest, _, _ = self._create_inforequest_scenario(
u'clarification_request',
# snooze is missed at 2010-10-14
(u'clarification_response', dict(delivered_date=naive_date(u'2010-10-05'), last_deadline_reminder=last)),
(u'clarification_response', dict(last_deadline_reminder=last)),
)

timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00'))
Expand All @@ -363,7 +359,7 @@ def test_reminder_is_sent_if_last_action_snooze_was_not_missed_yet_when_last_rem
inforequest, _, _ = self._create_inforequest_scenario(
u'clarification_request',
# snooze is missed at 2010-10-14
(u'clarification_response', dict(delivered_date=naive_date(u'2010-10-05'), last_deadline_reminder=last)),
(u'clarification_response', dict(last_deadline_reminder=last)),
)

timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00'))
Expand All @@ -372,12 +368,12 @@ def test_reminder_is_sent_if_last_action_snooze_was_not_missed_yet_when_last_rem

def test_reminder_is_sent_if_last_action_snooze_was_already_missed_when_last_reminder_was_sent_but_it_was_extended_later(self):
timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00'))
last = utc_datetime_from_local(u'2010-10-12 10:33:00')
last = utc_datetime_from_local(u'2010-10-16 10:33:00')
inforequest, _, _ = self._create_inforequest_scenario(
u'clarification_request',
# snooze was missed at 2010-10-13, but then it was extended by 5 days; it will be
# snooze was missed at 2010-10-14, but then it was extended by 4 days; it will be
# missed at 2010-10-18 again.
(u'extension', dict(delivered_date=naive_date(u'2010-10-05'), extension=5, last_deadline_reminder=last)),
(u'clarification_response', dict(last_deadline_reminder=last, snooze=naive_date(u'2010-10-17'))),
)

timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00'))
Expand Down

0 comments on commit 7c2bd35

Please sign in to comment.