Example #1
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))
Example #2
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())
Example #3
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())
Example #4
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))
Example #5
0
    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)')
Example #6
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))
Example #7
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))
Example #8
0
    def test_post_with_valid_data_does_not_create_action_instance_if_exception_raised(
            self):
        scenario = self._create_scenario(email_args=dict(
            subject=u'Subject',
            text=u'Content',
            processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.txt',
                                              content=u'content',
                                              content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.html',
                                              content=u'<p>content</p>',
                                              content_type=u'text/html')
        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:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(
                    url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
Example #9
0
 def test_order_by_processed_query_method(self):
     dates = [
             u'2010-11-06 10:19:11',
             u'2014-10-06 10:19:11',
             u'2014-10-05 10:20:11',
             u'2014-10-05 11:20:11',
             u'2014-10-05 13:20:11',
             u'2014-10-06 13:20:11',
             u'2014-10-06 13:20:12.000000', # Many same dates to ckeck secondary sorting by pk
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000000',
             u'2014-10-06 13:20:12.000001',
             u'2014-10-06 13:20:12.000001',
             u'2014-10-06 13:20:12.000001',
             u'2014-10-06 13:20:12.000001',
             u'2014-10-06 13:20:12.000001',
             u'2014-10-06 13:20:12.000001',
             u'2014-11-06 10:19:11',
             ]
     random.shuffle(dates)
     msgs = [self._create_message(processed=utc_datetime_from_local(d)) for d in dates]
     result = Message.objects.order_by_processed()
     self.assertEqual(list(result), sorted(msgs, key=lambda o: (o.processed, o.pk)))
Example #10
0
def datachecks(superficial, autofix):
    u"""
    Checks that every ``Attachment`` instance has its file working, and there are not any orphaned
    attachment files.
    """
    # This check is a bit slow. We skip it if running from cron or the user asked for
    # superficial tests only.
    if superficial:
        return

    attachments = Attachment.objects.all()
    attachment_names = {a.file.name for a in attachments}

    for attachment in attachments:
        try:
            try:
                attachment.file.open(u'rb')
            finally:
                attachment.file.close()
        except IOError:
            yield datacheck.Error(u'{} is missing its file: "{}".',
                    attachment, attachment.file.name)

    field = Attachment._meta.get_field(u'file')
    if not field.storage.exists(field.upload_to):
        return
    for file_name in field.storage.listdir(field.upload_to)[1]:
        attachment_name = u'{}/{}'.format(field.upload_to, file_name)
        modified_time = utc_datetime_from_local(field.storage.modified_time(attachment_name))
        timedelta = utc_now() - modified_time
        if timedelta > datetime.timedelta(days=5) and attachment_name not in attachment_names:
            yield datacheck.Info(squeeze(u"""
                    There is no Attachment instance for file: "{}". The file is {} days old, so you
                    can probably remove it.
                    """), attachment_name, timedelta.days)
Example #11
0
 def test_order_by_processed_query_method(self):
     dates = [
         u'2010-11-06 10:19:11',
         u'2014-10-06 10:19:11',
         u'2014-10-05 10:20:11',
         u'2014-10-05 11:20:11',
         u'2014-10-05 13:20:11',
         u'2014-10-06 13:20:11',
         u'2014-10-06 13:20:12.000000',  # Many same dates to ckeck secondary sorting by pk
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000000',
         u'2014-10-06 13:20:12.000001',
         u'2014-10-06 13:20:12.000001',
         u'2014-10-06 13:20:12.000001',
         u'2014-10-06 13:20:12.000001',
         u'2014-10-06 13:20:12.000001',
         u'2014-10-06 13:20:12.000001',
         u'2014-11-06 10:19:11',
     ]
     random.shuffle(dates)
     msgs = [
         self._create_message(processed=utc_datetime_from_local(d))
         for d in dates
     ]
     result = Message.objects.order_by_processed()
     self.assertEqual(list(result),
                      sorted(msgs, key=lambda o: (o.processed, o.pk)))
Example #12
0
def datachecks(superficial, autofix):
    u"""
    Checks that every ``Attachment`` instance has its file working, and there are not any orphaned
    attachment files.
    """
    # This check is a bit slow. We skip it if running from cron or the user asked for
    # superficial tests only.
    if superficial:
        return

    attachments = Attachment.objects.all()
    attachment_names = {a.file.name for a in attachments}

    for attachment in attachments:
        try:
            try:
                attachment.file.open(u'rb')
            finally:
                attachment.file.close()
        except IOError:
            yield datacheck.Error(u'%r is missing its file: "%s".', attachment,
                                  attachment.file.name)

    field = Attachment._meta.get_field(u'file')
    if not field.storage.exists(field.upload_to):
        return
    for file_name in field.storage.listdir(field.upload_to)[1]:
        attachment_name = u'%s/%s' % (field.upload_to, file_name)
        timedelta = utc_now() - utc_datetime_from_local(
            field.storage.modified_time(attachment_name))
        if timedelta > datetime.timedelta(
                days=5) and attachment_name not in attachment_names:
            yield datacheck.Info(
                u'There is no Attachment instance for file: "%s". The file is %d days old, so you can probably remove it.',
                attachment_name, timedelta.days)
Example #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())
Example #14
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())
Example #15
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)
def forward(apps, schema_editor):
    APPLICANT_ACTION_TYPES = [1, 12, 13]
    OBLIGEE_ACTION_TYPES = [2, 3, 4, 5, 6, 7, 8, 9, 10]
    Action = apps.get_model(u'inforequests', u'Action')
    for action in Action.objects.all():
        action.created = utc_datetime_from_local(action.effective_date, hour=10, microsecond=action.pk)
        action.sent_date = action.effective_date if action.type in APPLICANT_ACTION_TYPES else None
        action.delivered_date = action.effective_date if action.type in OBLIGEE_ACTION_TYPES else None
        action.legal_date = action.effective_date
        action.deadline_base_date = action.effective_date if action.deadline else None
        action.save()
Example #17
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)
Example #18
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)
Example #19
0
    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())
Example #20
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())
Example #21
0
    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())
Example #22
0
    def test_reminder_is_sent_if_last_action_deadline_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')
        inforequest, _, _ = self._create_inforequest_scenario(
                u'clarification_request',
                # deadline was missed at 2010-10-11, but then it was extended by 3 days; it will be
                # missed at 2010-10-14 again.
                (u'clarification_response', dict(deadline=5, extension=3, 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())
Example #23
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())
def forward(apps, schema_editor):
    APPLICANT_ACTION_TYPES = [1, 12, 13]
    OBLIGEE_ACTION_TYPES = [2, 3, 4, 5, 6, 7, 8, 9, 10]
    Action = apps.get_model(u'inforequests', u'Action')
    for action in Action.objects.all():
        action.created = utc_datetime_from_local(action.effective_date,
                                                 hour=10,
                                                 microsecond=action.pk)
        action.sent_date = action.effective_date if action.type in APPLICANT_ACTION_TYPES else None
        action.delivered_date = action.effective_date if action.type in OBLIGEE_ACTION_TYPES else None
        action.legal_date = action.effective_date
        action.deadline_base_date = action.effective_date if action.deadline else None
        action.save()
Example #25
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)
Example #26
0
    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())
Example #27
0
    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())
Example #28
0
    def test_reminder_is_sent_if_last_action_deadline_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')
        inforequest, _, _ = self._create_inforequest_scenario(
            u'clarification_request',
            # deadline was missed at 2010-10-11, but then it was extended by 3 days; it will be
            # missed at 2010-10-14 again.
            (u'clarification_response',
             dict(deadline=5, extension=3, 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_undecided_oldest_newest_and_order_by_query_methods(self):
        inforequest = self._create_inforequest()
        _, rel4 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 13:22'),
            reltype=InforequestEmail.TYPES.APPLICANT_ACTION)
        _, rel2 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 11:22'),
            reltype=InforequestEmail.TYPES.UNRELATED)
        _, rel5 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 14:22'),
            reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)
        _, rel3 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 12:22'),
            reltype=InforequestEmail.TYPES.UNDECIDED)
        _, rel7 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 16:22'),
            reltype=InforequestEmail.TYPES.UNRELATED)
        _, rel6 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 15:22'),
            reltype=InforequestEmail.TYPES.UNDECIDED)
        _, rel1 = self._create_inforequest_email(
            inforequest=inforequest,
            processed=utc_datetime_from_local(u'2014-10-10 10:22'),
            reltype=InforequestEmail.TYPES.UNKNOWN)

        # Oldest
        self.assertEqual(list(InforequestEmail.objects.oldest()), [rel1])
        # Newest
        self.assertEqual(list(InforequestEmail.objects.newest()), [rel7])
        # All undecided
        self.assertItemsEqual(InforequestEmail.objects.undecided(),
                              [rel6, rel3])
        # Oldest undecided
        self.assertEqual(list(InforequestEmail.objects.undecided().oldest()),
                         [rel3])
        # Newest undecided
        self.assertEqual(list(InforequestEmail.objects.undecided().newest()),
                         [rel6])
        # order_by_pk
        self.assertEqual(list(InforequestEmail.objects.order_by_pk()),
                         [rel4, rel2, rel5, rel3, rel7, rel6, rel1])
        # order_by_email
        self.assertEqual(list(InforequestEmail.objects.order_by_email()),
                         [rel1, rel2, rel3, rel4, rel5, rel6, rel7])
Example #30
0
    def test_post_with_valid_data_creates_action_instance(self):
        scenario = self._create_scenario(email_args=dict(
            subject=u'Subject',
            text=u'Content',
            processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.txt',
                                              content=u'content',
                                              content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.html',
                                              content=u'<p>content</p>',
                                              content_type=u'text/html')
        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.email, scenario.email)
        self.assertEqual(action.type, self.action_type)
        self.assertEqual(action.subject, u'Subject')
        self.assertEqual(action.content, u'Content')
        self.assertEqual(action.effective_date, naive_date(u'2010-10-05'))

        attachments = [(a.name, a.content, a.content_type)
                       for a in action.attachment_set.all()]
        self.assertItemsEqual(attachments, [
            (u'filename.txt', u'content', u'text/plain'),
            (u'filename.html', u'<p>content</p>', u'text/html'),
        ])

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type,
                         InforequestEmail.TYPES.OBLIGEE_ACTION)
    def test_undecided_oldest_newest_and_order_by_query_methods(self):
        inforequest = self._create_inforequest()
        _, rel4 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 13:22'), reltype=InforequestEmail.TYPES.APPLICANT_ACTION)
        _, rel2 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 11:22'), reltype=InforequestEmail.TYPES.UNRELATED)
        _, rel5 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 14:22'), reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)
        _, rel3 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 12:22'), reltype=InforequestEmail.TYPES.UNDECIDED)
        _, rel7 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 16:22'), reltype=InforequestEmail.TYPES.UNRELATED)
        _, rel6 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 15:22'), reltype=InforequestEmail.TYPES.UNDECIDED)
        _, rel1 = self._create_inforequest_email(inforequest=inforequest, processed=utc_datetime_from_local(u'2014-10-10 10:22'), reltype=InforequestEmail.TYPES.UNKNOWN)

        # Oldest
        self.assertEqual(list(InforequestEmail.objects.oldest()), [rel1])
        # Newest
        self.assertEqual(list(InforequestEmail.objects.newest()), [rel7])
        # All undecided
        self.assertItemsEqual(InforequestEmail.objects.undecided(), [rel6, rel3])
        # Oldest undecided
        self.assertEqual(list(InforequestEmail.objects.undecided().oldest()), [rel3])
        # Newest undecided
        self.assertEqual(list(InforequestEmail.objects.undecided().newest()), [rel6])
        # order_by_pk
        self.assertEqual(list(InforequestEmail.objects.order_by_pk()), [rel4, rel2, rel5, rel3, rel7, rel6, rel1])
        # order_by_email
        self.assertEqual(list(InforequestEmail.objects.order_by_email()), [rel1, rel2, rel3, rel4, rel5, rel6, rel7])
Example #32
0
 def test_utc_datetime_from_local(self):
     value = utc_datetime_from_local(self._parse_dt(u'2014-08-15 03:45:00'))
     self._check_dt(value, u'2014-08-15 01:45:00.000000 UTC +0000')
Example #33
0
 def test_utc_datetime_from_local_with_from_tz_as_string(self):
     value = utc_datetime_from_local(self._parse_dt(u'2014-08-15 03:45:00'), from_tz=u'America/Montreal')
     self._check_dt(value, u'2014-08-15 07:45:00.000000 UTC +0000')
Example #34
0
 def test_utc_datetime_from_local_with_from_tz_as_string(self):
     value = utc_datetime_from_local(self._parse_dt(u'2014-08-15 03:45:00'),
                                     from_tz=u'America/Montreal')
     self._check_dt(value, u'2014-08-15 07:45:00.000000 UTC +0000')
Example #35
0
    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)')
Example #36
0
 def test_created_field_with_explicit_value(self):
     obj = self._create_instance(
         created=utc_datetime_from_local(u'2014-10-05 15:33:10'))
     self.assertEqual(obj.created,
                      utc_datetime_from_local(u'2014-10-05 15:33:10'))
Example #37
0
 def test_created_field_with_explicit_value(self):
     obj = self._create_instance(created=utc_datetime_from_local(u'2014-10-05 15:33:10'))
     self.assertEqual(obj.created, utc_datetime_from_local(u'2014-10-05 15:33:10'))
    def test_post_with_valid_data_creates_action_instance(self):
        scenario = self._create_scenario(email_args=dict(subject=u'Subject', text=u'Content', processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email, name=u'filename.txt', content=u'content', content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email, name=u'filename.html', content=u'<p>content</p>', content_type=u'text/html')
        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.email, scenario.email)
        self.assertEqual(action.type, self.action_type)
        self.assertEqual(action.subject, u'Subject')
        self.assertEqual(action.content, u'Content')
        self.assertEqual(action.effective_date, naive_date(u'2010-10-05'))

        attachments = [(a.name, a.content, a.content_type) for a in action.attachment_set.all()]
        self.assertItemsEqual(attachments, [
            (u'filename.txt', u'content', u'text/plain'),
            (u'filename.html', u'<p>content</p>', u'text/html'),
            ])

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.OBLIGEE_ACTION)
Example #39
0
 def test_utc_datetime_from_local(self):
     value = utc_datetime_from_local(self._parse_dt(u'2014-08-15 03:45:00'))
     self._check_dt(value, u'2014-08-15 01:45:00.000000 UTC +0000')
    def test_post_with_valid_data_does_not_create_action_instance_if_exception_raised(self):
        scenario = self._create_scenario(email_args=dict(subject=u'Subject', text=u'Content', processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email, name=u'filename.txt', content=u'content', content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email, name=u'filename.html', content=u'<p>content</p>', content_type=u'text/html')
        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:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
Example #41
0
 def test_processed_field_with_explicit_value(self):
     msg = self._create_message(
         processed=utc_datetime_from_local(u'2014-10-04 13:22:12'))
     self.assertEqual(msg.processed,
                      utc_datetime_from_local(u'2014-10-04 13:22:12'))
Example #42
0
 def test_processed_field_with_explicit_value(self):
     msg = self._create_message(processed=utc_datetime_from_local(u'2014-10-04 13:22:12'))
     self.assertEqual(msg.processed, utc_datetime_from_local(u'2014-10-04 13:22:12'))