Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
 def _test_deadline_missed_aux(self, **kwargs):
     inforequest = self._create_inforequest()
     branch = self._create_branch(inforequest=inforequest)
     action = self._create_action(branch=branch, effective_date=naive_date(u'2010-10-05'), **kwargs)
     timewarp.jump(local_datetime_from_local(u'2010-10-10 10:33:00'))
     with mock.patch(u'chcemvediet.apps.inforequests.models.action.workdays.between', side_effect=lambda a,b: (b-a).days):
         yield action
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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())
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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())
Ejemplo n.º 11
0
    def assert_times_job_is_run_at(self, cronjob):
        tests = (
            (u'07:10', False),
            (u'07:50', False),
            (u'08:10', False),
            (u'08:50', False),
            (u'09:10', True),
            (u'09:50', False),
            (u'10:10', True),
            (u'10:50', False),
            (u'11:10', True),
            (u'11:50', False),
            (u'12:10', True),
            (u'12:50', False),
            (u'13:10', True),
            (u'13:50', False),
            (u'14:10', True),
            (u'14:50', False),
            (u'15:10', False),
            (u'15:50', False),
            (u'16:10', False),
            (u'16:50', False),
        )

        for time, expected in tests:
            timewarp.jump(date=local_datetime_from_local(u'2010-10-05 %s' %
                                                         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)
            else:
                self.assertEqual(mock_jobs[cronjob].call_count, 0,
                                 u'Cron job not run at %s.' % time)
Ejemplo n.º 12
0
    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())
Ejemplo n.º 13
0
    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())
Ejemplo n.º 14
0
    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())
Ejemplo n.º 15
0
    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())
Ejemplo n.º 16
0
    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())
Ejemplo n.º 17
0
 def test_message_send_date(self):
     timewarp.enable()
     timewarp.jump(local_datetime_from_utc(u'2010-10-05 10:13:35'))
     msg = self._create_message()
     rcpt = self._create_recipient(message=msg)
     result = self._run_mail_cron_job()
     self.assertEqual(result[0].headers[u'Date'], [u'Tue, 05 Oct 2010 10:13:35 -0000'])
     timewarp.reset()
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    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))
Ejemplo n.º 20
0
    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))
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
 def test_message_send_date(self):
     timewarp.enable()
     timewarp.jump(local_datetime_from_utc(u'2010-10-05 10:13:35'))
     msg = self._create_message()
     rcpt = self._create_recipient(message=msg)
     result = self._run_mail_cron_job()
     self.assertEqual(result[0].headers[u'Date'],
                      [u'Tue, 05 Oct 2010 10:13:35 -0000'])
     timewarp.reset()
Ejemplo n.º 23
0
    def test_sessions_newer_than_two_weeks_are_kept(self):
        timewarp.jump(utc_datetime_from_local(u'2014-10-01 09:30:00'))
        user = User.objects.create_user(u'aaa', password=u'ppp')
        self.client.login(username=user.username, password=u'ppp')

        timewarp.jump(utc_datetime_from_local(u'2014-10-14 09:30:00'))
        self.assertTrue(Session.objects.exists())
        clear_expired_sessions().do()
        self.assertTrue(Session.objects.exists())
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
    def test_sessions_newer_than_two_weeks_are_kept(self):
        timewarp.jump(utc_datetime_from_local(u'2014-10-01 09:30:00'))
        user = User.objects.create_user(u'aaa', password=u'ppp')
        self.client.login(username=user.username, password=u'ppp')

        timewarp.jump(utc_datetime_from_local(u'2014-10-14 09:30:00'))
        self.assertTrue(Session.objects.exists())
        clear_expired_sessions().do()
        self.assertTrue(Session.objects.exists())
Ejemplo n.º 26
0
    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())
Ejemplo n.º 27
0
    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())
Ejemplo n.º 28
0
    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())
Ejemplo n.º 29
0
    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())
Ejemplo n.º 30
0
    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)
Ejemplo n.º 31
0
    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())
Ejemplo n.º 32
0
 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()
Ejemplo n.º 33
0
    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())
Ejemplo n.º 34
0
    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)
Ejemplo n.º 35
0
    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)
Ejemplo n.º 36
0
    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())
Ejemplo n.º 37
0
    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)
Ejemplo n.º 38
0
    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)
Ejemplo n.º 39
0
    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)
Ejemplo n.º 40
0
    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())
Ejemplo n.º 41
0
    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)
Ejemplo n.º 42
0
    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())
Ejemplo n.º 43
0
    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)
Ejemplo n.º 44
0
    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)
Ejemplo n.º 45
0
    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)
Ejemplo n.º 46
0
    def test_draft_effective_date_may_be_from_future(self):
        timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00'))
        scenario = self._create_scenario()
        data = self._create_post_data(button=u'draft', effective_date=naive_date(u'2014-11-06'))
        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')
Ejemplo n.º 47
0
    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())
Ejemplo n.º 48
0
 def _test_deadline_missed_aux(self, **kwargs):
     inforequest = self._create_inforequest()
     branch = self._create_branch(inforequest=inforequest)
     action = self._create_action(branch=branch,
                                  effective_date=naive_date(u'2010-10-05'),
                                  **kwargs)
     timewarp.jump(local_datetime_from_local(u'2010-10-10 10:33:00'))
     with mock.patch(
             u'chcemvediet.apps.inforequests.models.action.workdays.between',
             side_effect=lambda a, b: (b - a).days):
         yield action
Ejemplo n.º 49
0
    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)
Ejemplo n.º 50
0
    def test_effective_date_field_may_not_be_from_future(self):
        timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00'))
        scenario = self._create_scenario()
        data = self._create_post_data(branch=scenario.branch, effective_date=naive_date(u'2010-10-06'))
        url = self._create_url(scenario)

        self._login_user()
        response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFormError(response, u'form', u'effective_date', 'May not be from future.')

        data = json.loads(response.content)
        self.assertEqual(data[u'result'], u'invalid')
Ejemplo n.º 51
0
    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())
Ejemplo n.º 52
0
    def test_post_with_default_button_and_valid_data_creates_action_with_effective_date_today(self):
        timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00'))
        scenario = self._create_scenario()
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        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 = action_set.get()

        self.assertEqual(action.effective_date, naive_date(u'2010-03-05'))
Ejemplo n.º 53
0
    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])
Ejemplo n.º 54
0
    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)
Ejemplo n.º 55
0
    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())
Ejemplo n.º 56
0
    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))
Ejemplo n.º 57
0
    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))
Ejemplo n.º 58
0
    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())
Ejemplo n.º 59
0
    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)