def test_inforequest_is_skipped_if_exception_raised_while_sending_reminder( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequests = [self._create_inforequest() for i in range(3)] emails = [ self._create_inforequest_email(inforequest=ir) for ir in inforequests ] timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) with mock.patch(u'chcemvediet.apps.inforequests.cron.nop', side_effect=[None, None, None, None, Exception, None]): with mock.patch(u'chcemvediet.apps.inforequests.cron.cron_logger' ) as logger: message_set = self._call_cron_job() self.assertEqual(message_set.count(), 2) self.assertEqual(len(logger.mock_calls), 3) self.assertRegexpMatches( logger.mock_calls[0][1][0], u'Sent undecided email reminder: <Inforequest: %s>' % inforequests[0].pk) self.assertRegexpMatches( logger.mock_calls[1][1][0], u'Sending undecided email reminder failed: <Inforequest: %s>' % inforequests[1].pk) self.assertRegexpMatches( logger.mock_calls[2][1][0], u'Sent undecided email reminder: <Inforequest: %s>' % inforequests[2].pk)
def test_reminder_is_not_sent_for_inforequest_without_undecided_email(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest = self._create_inforequest() timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_branch_is_skipped_if_exception_raised_while_sending_reminder( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, actions = self._create_inforequest_scenario( (u'advancement', [u'clarification_request'], [u'clarification_request'], [u'clarification_request'])) _, (_, ((_, (_, action1)), (_, (_, action2)), (_, (_, action3)))) = actions timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) with mock.patch(u'chcemvediet.apps.inforequests.cron.nop', side_effect=[None, None, None, None, Exception, None]): with mock.patch(u'chcemvediet.apps.inforequests.cron.cron_logger' ) as logger: message_set = self._call_cron_job() self.assertEqual(message_set.count(), 2) self.assertEqual(len(logger.mock_calls), 3) self.assertRegexpMatches( logger.mock_calls[0][1][0], u'Sent applicant deadline reminder: <Action: %s>' % action1.pk) self.assertRegexpMatches( logger.mock_calls[1][1][0], u'Sending applicant deadline reminder failed: <Action: %s>' % action2.pk) self.assertRegexpMatches( logger.mock_calls[2][1][0], u'Sent applicant deadline reminder: <Action: %s>' % action3.pk)
def test_reminder_is_not_sent_if_last_action_does_not_have_applicant_deadline(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario(u'clarification_request', u'clarification_response') timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_inforequest_is_skipped_if_exception_raised_while_checking_it( self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenarios = [self._create_inforequest_scenario() for i in range(3)] timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) with mock.patch(u'chcemvediet.apps.inforequests.cron.nop', side_effect=[None, Exception, None, None, None]): with mock.patch(u'chcemvediet.apps.inforequests.cron.cron_logger' ) as logger: with created_instances(Action.objects) as action_set: self._call_cron_job() self.assertEqual(action_set.count(), 2) self.assertEqual(Inforequest.objects.closed().count(), 2) self.assertEqual(len(logger.mock_calls), 3) self.assertRegexpMatches( logger.mock_calls[0][1][0], u'Checking if inforequest should be closed failed: <Inforequest: %s>' % scenarios[1][0].pk) self.assertRegexpMatches( logger.mock_calls[1][1][0], u'Closed inforequest: <Inforequest: %s>' % scenarios[0][0].pk) self.assertRegexpMatches( logger.mock_calls[2][1][0], u'Closed inforequest: <Inforequest: %s>' % scenarios[2][0].pk)
def test_obligee_deadline_reminder_with_inforequest_with_multiple_branches(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario((u'advancement', [], [], [])) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 3)
def test_reminder_is_sent_for_not_closed_inforequest_without_undecided_email(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario(u'clarification_request') timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_applicant_deadline_reminder_with_multiple_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenarios = [self._create_inforequest_scenario(u'clarification_request') for i in range(4)] timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 4)
def test_obligee_deadline_reminder_with_multiple_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenarios = [self._create_inforequest_scenario() for i in range(4)] timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 4)
def test_expiration_not_added_if_inforequest_is_already_closed(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) _, branch, _ = self._create_inforequest_scenario(dict(closed=True)) timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) with created_instances(branch.action_set) as action_set: self._call_cron_job() self.assertFalse(action_set.exists())
def test_undecided_email_reminder_with_multiple_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequests = [self._create_inforequest() for i in range(5)] emails = [self._create_inforequest_email(inforequest=ir) for ir in inforequests] timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 5)
def test_reminder_is_not_sent_twice_for_one_action(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-11 10:33:00') inforequest, _, _ = self._create_inforequest_scenario((u'clarification_request', dict(last_deadline_reminder=last))) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_reminder_is_sent_for_not_closed_inforequest_without_undecided_email( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario() timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_expiration_not_added_if_last_action_does_not_have_obligee_deadline(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) _, branch, _ = self._create_inforequest_scenario(u'disclosure') timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) with created_instances(branch.action_set) as action_set: self._call_cron_job() self.assertFalse(action_set.exists())
def test_close_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario() timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) self._call_cron_job() inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertTrue(inforequest.closed)
def test_expiration_not_added_if_last_action_does_not_have_obligee_deadline( self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) _, branch, _ = self._create_inforequest_scenario(u'disclosure') timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) with created_instances(branch.action_set) as action_set: self._call_cron_job() self.assertFalse(action_set.exists())
def test_created_field_unchanged_when_saving_existing_instance(self): timewarp.jump(local_datetime_from_local(u'2014-10-05 15:33:10')) obj = self._create_instance() self.assertAlmostEqual(obj.created, utc_datetime_from_local(u'2014-10-05 15:33:10'), delta=datetime.timedelta(seconds=10)) timewarp.jump(local_datetime_from_local(u'2014-10-07 20:23:11')) obj.name = u'changed' obj.save() self.assertAlmostEqual(obj.created, utc_datetime_from_local(u'2014-10-05 15:33:10'), delta=datetime.timedelta(seconds=10))
def test_reminder_is_not_sent_for_closed_inforequest_with_undecided_email( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest = self._create_inforequest(closed=True) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_clone_method_clone_has_old_created_value(self): timewarp.jump(local_datetime_from_local(u'2014-10-05 15:33:10')) obj = self._create_instance() self.assertAlmostEqual(obj.created, utc_datetime_from_local(u'2014-10-05 15:33:10'), delta=datetime.timedelta(seconds=10)) timewarp.jump(local_datetime_from_local(u'2014-10-07 20:23:11')) new = obj.clone(obj.generic_object) new.save() self.assertAlmostEqual(new.created, utc_datetime_from_local(u'2014-10-05 15:33:10'), delta=datetime.timedelta(seconds=10))
def test_reminder_is_not_sent_if_last_action_does_not_have_applicant_deadline( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( u'clarification_request', u'clarification_response') timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_reminder_is_not_sent_for_inforequest_with_undecided_email(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( u'clarification_request') email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_reminder_is_not_sent_twice_for_one_action(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-11 10:33:00') inforequest, _, _ = self._create_inforequest_scenario( (u'clarification_request', dict(last_deadline_reminder=last))) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_obligee_deadline_reminder_with_inforequest_with_multiple_branches( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( (u'advancement', [], [], [])) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 3)
def test_job_is_run_again_after_timeout(self): timewarp.enable() with mock_cron_jobs() as mock_jobs: timewarp.jump(date=local_datetime_from_local(u'2010-10-05 10:00:00')) self._call_runcrons() timewarp.jump(date=local_datetime_from_local(u'2010-10-05 10:01:10')) self._call_runcrons() self.assertEqual(mock_jobs[u'poleno.mail.cron.mail'].call_count, 2) timewarp.reset()
def test_utc_date_and_local_date_filters(self): u""" Tests ``datetime|utc_date`` and ``datetime|local_date`` filter. The filters are tested with datetimes in UTC, in local timezone and in some other explicitly set timezone. The filters are also tested with points in time respresenting different date in local timezone than in UTC. """ with timezone.override(u'Europe/Bratislava'): # UTC +1 # 2014-12-11 00:20:00 in Europe/Bratislava == 2014-12-10 23:20:00 UTC; Still yesterday in UTC utc = utc_datetime_from_local(2014, 12, 11, 0, 20, 0) local = local_datetime_from_local(2014, 12, 11, 0, 20, 0) rendered = self._render( u'{% load utc_date local_date from poleno.utils %}' u'({{ utc|utc_date|date:"Y-m-d" }})' u'({{ local|utc_date|date:"Y-m-d" }})' u'({{ utc|local_date|date:"Y-m-d" }})' u'({{ local|local_date|date:"Y-m-d" }})' u'', utc=utc, local=local) self.assertEqual(rendered, u'(2014-12-10)(2014-12-10)(2014-12-11)(2014-12-11)') # 2014-12-11 10:20:00 in Europe/Bratislava == 2014-12-11 09:20:00 UTC; The same day in UTC utc = utc_datetime_from_local(2014, 12, 11, 10, 20, 0) local = local_datetime_from_local(2014, 12, 11, 10, 20, 0) rendered = self._render( u'{% load utc_date local_date from poleno.utils %}' u'({{ utc|utc_date|date:"Y-m-d" }})' u'({{ local|utc_date|date:"Y-m-d" }})' u'({{ utc|local_date|date:"Y-m-d" }})' u'({{ local|local_date|date:"Y-m-d" }})' u'', utc=utc, local=local) self.assertEqual(rendered, u'(2014-12-11)(2014-12-11)(2014-12-11)(2014-12-11)') with timezone.override(u'America/Montreal'): # UTC -5 # 2014-12-11 22:20:00 in America/Montreal == 2014-12-12 03:20:00 UTC; Already tomorrow in UTC utc = utc_datetime_from_local(2014, 12, 11, 22, 20, 0) local = local_datetime_from_local(2014, 12, 11, 22, 20, 0) rendered = self._render( u'{% load utc_date local_date from poleno.utils %}' u'({{ utc|utc_date|date:"Y-m-d" }})' u'({{ local|utc_date|date:"Y-m-d" }})' u'({{ utc|local_date|date:"Y-m-d" }})' u'({{ local|local_date|date:"Y-m-d" }})' u'', utc=utc, local=local) self.assertEqual(rendered, u'(2014-12-12)(2014-12-12)(2014-12-11)(2014-12-11)') # 2014-12-11 04:20:00 in Europe/Bratislava == 2014-12-11 03:20:00 UTC == 2014-12-10 22:20:00 in America/Montreal with timezone.override(u'Europe/Bratislava'): # UTC +1 other = local_datetime_from_local(2014, 12, 11, 4, 20, 0) other_tz = timezone.get_current_timezone() rendered = self._render( u'{% load utc_date local_date from poleno.utils %}' u'({{ other|utc_date|date:"Y-m-d" }})' u'({{ other|local_date|date:"Y-m-d" }})' u'({{ other|local_date:other_tz|date:"Y-m-d" }})' u'', other=other, other_tz=other_tz) self.assertEqual(rendered, u'(2014-12-11)(2014-12-10)(2014-12-11)')
def test_last_action_last_deadline_reminder_is_not_updated_if_remider_is_not_sent(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, (_, clarification_request) = self._create_inforequest_scenario( (u'clarification_request', dict(last_deadline_reminder=None))) timewarp.jump(local_datetime_from_local(u'2010-10-06 10:33:00')) message_set = self._call_cron_job() clarification_request = Action.objects.get(pk=clarification_request.pk) self.assertIsNone(clarification_request.last_deadline_reminder)
def test_close_inforequests_with_multiple_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenarios = [self._create_inforequest_scenario() for i in range(5)] timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) self._call_cron_job() for inforequest, _, _ in scenarios: inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertTrue(inforequest.closed)
def test_last_action_last_deadline_reminder_is_not_updated_if_remider_is_not_sent(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-11-10 17:00:00') inforequest, _, (request,) = self._create_inforequest_scenario((u'request', dict(last_deadline_reminder=last))) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() request = Action.objects.get(pk=request.pk) self.assertEqual(request.last_deadline_reminder, last)
def test_reminder_is_sent_if_last_action_applicant_deadline_is_already_missed(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( # deadline is missed at 2010-10-11 (u'clarification_request', dict(deadline=5)), ) timewarp.jump(local_datetime_from_local(u'2010-10-11 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_datetime_output_format(self): with translation(u'en'): class Form(forms.Form): field = forms.DateTimeField(localize=True) form = Form(initial=dict(field=local_datetime_from_local(u'2006-10-25 14:30:59.000200'))) self.assertHTMLEqual(str(form[u'field']), u'<input id="id_field" name="field" type="text" value="10/25/2006 14:30:59">') form = Form(initial=dict(field=local_datetime_from_local(u'2006-10-25'))) self.assertHTMLEqual(str(form[u'field']), u'<input id="id_field" name="field" type="text" value="10/25/2006 00:00:00">')
def test_expiration_added_if_last_action_has_obligee_deadline(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) _, branch, _ = self._create_inforequest_scenario() timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) with created_instances(branch.action_set) as action_set: self._call_cron_job() action = action_set.get() self.assertEqual(action.type, Action.TYPES.EXPIRATION)
def test_reminder_is_not_sent_if_last_action_deadline_will_be_missed_in_more_than_2_days(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( # deadline is missed at 2010-10-11 (u'clarification_request', dict(deadline=5)), ) timewarp.jump(local_datetime_from_local(u'2010-10-07 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_reminder_is_sent_if_last_action_applicant_deadline_is_already_missed( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( # deadline is missed at 2010-10-11 (u'clarification_request', dict(deadline=5)), ) timewarp.jump(local_datetime_from_local(u'2010-10-11 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_reminder_is_not_sent_if_last_action_deadline_will_be_missed_in_more_than_2_days( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( # deadline is missed at 2010-10-11 (u'clarification_request', dict(deadline=5)), ) timewarp.jump(local_datetime_from_local(u'2010-10-07 10:33:00')) message_set = self._call_cron_job() self.assertFalse(message_set.exists())
def test_post_with_default_button_and_invalid_data_does_not_add_expiration_if_expired(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenario = self._create_scenario(inforequest_scenario=[u'request']) data = self._create_post_data(branch=u'invalid') url = self._create_url(scenario) timewarp.jump(local_datetime_from_local(u'2010-08-06 10:33:00')) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') self.assertFalse(action_set.exists())
def test_inforequest_last_undecided_email_reminder_is_not_updated_if_reminder_is_not_sent(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-10 17:00:00') inforequest = self._create_inforequest(last_undecided_email_reminder=last) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertEqual(inforequest.last_undecided_email_reminder, last)
def test_reminder_is_sent_if_newest_undecided_email_is_at_least_5_days_old(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest = self._create_inforequest() email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-15 10:33:00')) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_inforequest_is_closed_if_last_action_deadline_was_missed_at_least_100_days_ago(self): timewarp.jump(local_datetime_from_local(u'2010-03-01 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario((u'request', dict(deadline=10))) # Request deadline was missed at 2010-03-11. 100 days after missing the deadline will pass # at 2010-06-19. timewarp.jump(local_datetime_from_local(u'2010-06-19 10:33:00')) self._call_cron_job() inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertTrue(inforequest.closed)
def test_undecided_email_reminder_with_multiple_inforequests(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequests = [self._create_inforequest() for i in range(5)] emails = [ self._create_inforequest_email(inforequest=ir) for ir in inforequests ] timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertEqual(message_set.count(), 5)
def test_draft_effective_date_may_be_older_than_one_month(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenario = self._create_scenario() timewarp.jump(local_datetime_from_local(u'2012-11-17 10:33:00')) data = self._create_post_data(button=u'draft', effective_date=naive_date(u'2010-10-16')) url = self._create_url(scenario) self._login_user() response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') data = json.loads(response.content) self.assertEqual(data[u'result'], u'success')
def test_reminder_is_sent_if_last_action_deadline_was_not_missed_yet_when_last_reminder_was_sent(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-10 10:33:00') inforequest, _, _ = self._create_inforequest_scenario( u'clarification_request', # deadline is missed at 2010-10-11 (u'clarification_response', dict(deadline=5, last_deadline_reminder=last)), ) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_reminder_is_sent_for_last_action_even_if_it_was_sent_for_previous_actions(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-11 10:33:00') inforequest, _, _ = self._create_inforequest_scenario( (u'clarification_request', dict(last_deadline_reminder=last)), u'clarification_response', (u'clarification_request', dict(last_deadline_reminder=None)), ) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_reminder_is_sent_if_newest_undecided_email_is_at_least_5_days_old( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest = self._create_inforequest() email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-15 10:33:00')) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_last_action_last_deadline_reminder_is_not_updated_if_remider_is_not_sent( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-11-10 17:00:00') inforequest, _, (request, ) = self._create_inforequest_scenario( (u'request', dict(last_deadline_reminder=last))) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() request = Action.objects.get(pk=request.pk) self.assertEqual(request.last_deadline_reminder, last)
def test_last_action_last_deadline_reminder_is_not_updated_if_remider_is_not_sent( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) inforequest, _, ( _, clarification_request) = self._create_inforequest_scenario( (u'clarification_request', dict(last_deadline_reminder=None))) timewarp.jump(local_datetime_from_local(u'2010-10-06 10:33:00')) message_set = self._call_cron_job() clarification_request = Action.objects.get(pk=clarification_request.pk) self.assertIsNone(clarification_request.last_deadline_reminder)
def test_reminder_is_sent_if_newest_undecided_email_newer_than_last_reminder(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-10 17:00:00') inforequest = self._create_inforequest(last_undecided_email_reminder=last) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-10 18:00:00')) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_post_with_default_button_and_valid_data_adds_expiration_if_expired(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenario = self._create_scenario(inforequest_scenario=[u'request']) data = self._create_post_data(branch=scenario.branch) url = self._create_url(scenario) timewarp.jump(local_datetime_from_local(u'2010-08-06 10:33:00')) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') action_types = [a.type for a in action_set.all()] self.assertEqual(action_types, [Action.TYPES.EXPIRATION, Action.TYPES.APPEAL])
def test_post_with_default_button_and_invalid_data_does_not_add_expiration_if_expired( self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenario = self._create_scenario(inforequest_scenario=[u'request']) data = self._create_post_data(branch=u'invalid') url = self._create_url(scenario) timewarp.jump(local_datetime_from_local(u'2010-08-06 10:33:00')) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post( url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') self.assertFalse(action_set.exists())
def test_inforequest_last_undecided_email_reminder_is_not_updated_if_reminder_is_not_sent( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-10 17:00:00') inforequest = self._create_inforequest( last_undecided_email_reminder=last) email = self._create_inforequest_email(inforequest=inforequest) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertEqual(inforequest.last_undecided_email_reminder, last)
def test_reminder_is_sent_for_last_action_even_if_it_was_sent_for_previous_actions( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-11 10:33:00') inforequest, _, _ = self._create_inforequest_scenario( (u'clarification_request', dict(last_deadline_reminder=last)), u'clarification_response', (u'clarification_request', dict(last_deadline_reminder=None)), ) timewarp.jump(local_datetime_from_local(u'2010-11-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())
def test_inforequest_is_closed_if_last_action_deadline_was_missed_at_least_100_days_ago( self): timewarp.jump(local_datetime_from_local(u'2010-03-01 10:33:00')) inforequest, _, _ = self._create_inforequest_scenario( (u'request', dict(deadline=10))) # Request deadline was missed at 2010-03-11. 100 days after missing the deadline will pass # at 2010-06-19. timewarp.jump(local_datetime_from_local(u'2010-06-19 10:33:00')) self._call_cron_job() inforequest = Inforequest.objects.get(pk=inforequest.pk) self.assertTrue(inforequest.closed)
def test_reminder_is_sent_if_last_action_deadline_was_not_missed_yet_when_last_reminder_was_sent( self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) last = utc_datetime_from_local(u'2010-10-10 10:33:00') inforequest, _, _ = self._create_inforequest_scenario( u'clarification_request', # deadline is missed at 2010-10-11 (u'clarification_response', dict(deadline=5, last_deadline_reminder=last)), ) timewarp.jump(local_datetime_from_local(u'2010-10-20 10:33:00')) message_set = self._call_cron_job() self.assertTrue(message_set.exists())