Exemple #1
0
    def test_working_with_attachment(self):
        request = FoiRequest.objects.get_by_secret_mail(
            "*****@*****.**")
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 1)

        with open(p("test_mail_02.txt"), 'rb') as f:
            process_mail.delay(f.read())

        request = FoiRequest.objects.get_by_secret_mail(
            "*****@*****.**")
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 2)
        self.assertEqual(
            messages[1].subject,
            u"Fwd: Informationsfreiheitsgesetz des Bundes, Antragsvordruck für Open Data"
        )
        self.assertEqual(len(messages[1].attachments), 2)
        self.assertEqual(messages[1].attachments[0].name,
                         u"TI-IFG-AntragVordruck.docx")
        self.assertTrue(messages[1].attachments[1].name.endswith(u".pdf"))
        self.assertFalse(messages[1].attachments[0].is_converted)
        self.assertTrue(messages[1].attachments[1].is_converted)
        self.assertTrue(messages[1].attachments[1].converted is None)
        self.assertEqual(messages[1].attachments[0].converted,
                         messages[1].attachments[1])
Exemple #2
0
    def test_working_with_attachment(self):
        request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
        domain = request.public_body.email.split('@')[1]
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 1)

        with open(p("test_mail_02.txt"), 'rb') as f:
            mail_string = f.read().replace(b'*****@*****.**', b'abcde@' + domain.encode('ascii'))
            process_mail.delay(mail_string)

        request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 2)
        self.assertEqual(messages[1].subject, u"Fwd: Informationsfreiheitsgesetz des Bundes, Antragsvordruck für Open Data")
        self.assertEqual(len(messages[1].attachments), 2)
        self.assertEqual(messages[1].attachments[0].name,
                         u"TI-IFG-AntragVordruck.docx")
        self.assertTrue(messages[1].attachments[1].name.endswith(u".pdf"))
        self.assertFalse(messages[1].attachments[0].is_converted)
        self.assertTrue(messages[1].attachments[1].is_converted)
        self.assertTrue(messages[1].attachments[1].converted is None)
        self.assertEqual(
            messages[1].attachments[0].converted,
            messages[1].attachments[1]
        )
Exemple #3
0
    def test_working_with_attachment(self):
        request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
        domain = request.public_body.email.split('@')[1]
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 1)

        with open(p("test_mail_02.txt"), 'rb') as f:
            mail_string = f.read().replace(b'*****@*****.**',
                                           b'abcde@' + domain.encode('ascii'))
            process_mail.delay(mail_string)

        request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 2)
        self.assertEqual(
            messages[1].subject,
            "Fwd: Informationsfreiheitsgesetz des Bundes, Antragsvordruck für Open Data"
        )
        self.assertEqual(len(messages[1].attachments), 2)
        self.assertEqual(messages[1].attachments[0].name,
                         "TI-IFG-AntragVordruck.docx")
        self.assertTrue(messages[1].attachments[1].name.endswith(".pdf"))
        self.assertFalse(messages[1].attachments[0].is_converted)
        self.assertTrue(messages[1].attachments[1].is_converted)
        self.assertTrue(messages[1].attachments[1].converted is None)
        self.assertEqual(messages[1].attachments[0].converted,
                         messages[1].attachments[1])
Exemple #4
0
 def test_missing_date(self):
     with open(p("test_mail_08.txt"), 'rb') as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     message = messages[1]
     self.assertEqual(message.timestamp.date(), timezone.now().date())
Exemple #5
0
 def test_missing_date(self):
     with open(p("test_mail_08.txt"), 'rb') as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     message = messages[1]
     self.assertEqual(message.timestamp.date(), timezone.now().date())
Exemple #6
0
 def test_working_with_attachment(self):
     with file(p("test_mail_02.txt")) as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
     messages = request.foimessage_set.all()
     self.assertEqual(len(messages), 2)
     self.assertEqual(messages[1].subject, u"Fwd: Informationsfreiheitsgesetz des Bundes, Antragsvordruck für Open Data")
     self.assertEqual(len(messages[1].attachments), 1)
     self.assertEqual(messages[1].attachments[0].name, u"TI-IFG-AntragVordruck.docx")
Exemple #7
0
 def test_working(self):
     with file(p("test_mail_01.txt")) as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn(u'J\xf6rg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
             datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
Exemple #8
0
 def test_working(self):
     with open(p("test_mail_01.txt"), 'rb') as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn(u'J\xf6rg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
             datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
Exemple #9
0
 def test_additional_domains(self):
     with open(p("test_mail_01.txt"), 'rb') as f:
         process_mail.delay(f.read().replace(b'@fragdenstaat.de', b'@example.com'))
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn('Jörg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
             datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
Exemple #10
0
 def test_additional_domains(self):
     with open(p("test_mail_01.txt"), 'rb') as f:
         process_mail.delay(f.read().replace(b'@fragdenstaat.de', b'@example.com'))
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn('Jörg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
             datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
Exemple #11
0
 def test_working(self):
     with open(p("test_mail_01.txt"), 'rb') as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn('Jörg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
                      datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
Exemple #12
0
 def test_closed(self):
     count_messages = len(self.req.get_messages())
     name, domain = self.req.secret_address.split('@')
     recipient = self.secret_address
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read()
     process_mail.delay(mail)
     self.assertEqual(count_messages,
         FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=recipient)
     self.assertEqual(len(dms), 0)
Exemple #13
0
    def test_bounce(self):
        mail.outbox = []

        with open(p("test_mail_12.txt"), 'rb') as f:
            process_mail.delay(f.read())

        req = FoiRequest.objects.get(pk=self.req.pk)
        self.assertEqual(req.messages[-1].original, req.messages[0])
        # No notification mails, only to managers
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to[0], '*****@*****.**')
Exemple #14
0
 def test_wrong_address(self):
     request = FoiRequest.objects.get_by_secret_mail(u"*****@*****.**")
     request.delete()
     mail.outbox = []
     with file(p("test_mail_01.txt")) as f:
         process_mail.delay(f.read())
     self.assertEqual(len(mail.outbox), len(settings.MANAGERS))
     self.assertTrue(all([_('Unknown FoI-Mail Recipient') in m.subject for m in mail.outbox]))
     recipients = [m.to[0] for m in mail.outbox]
     for manager in settings.MANAGERS:
         self.assertIn(manager[1], recipients)
Exemple #15
0
 def test_spam(self):
     count_messages = len(self.req.messages)
     name, domain = self.req.secret_address.split('@')
     recipient = '*****@*****.**'
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read().decode('ascii').replace('*****@*****.**', '*****@*****.**')
     process_mail.delay(mail.encode('ascii'))
     self.assertEqual(count_messages,
         FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=recipient, spam=True)
     self.assertEqual(len(dms), 1)
Exemple #16
0
 def test_closed(self):
     count_messages = len(self.req.messages)
     name, domain = self.req.secret_address.split('@')
     recipient = self.secret_address
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read()
     process_mail.delay(mail)
     self.assertEqual(count_messages,
                      FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=recipient)
     self.assertEqual(len(dms), 0)
Exemple #17
0
 def test_spam(self):
     count_messages = len(self.req.messages)
     name, domain = self.req.secret_address.split('@')
     recipient = self.secret_address
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read().decode('ascii').replace('*****@*****.**', '*****@*****.**')
     process_mail.delay(mail.encode('ascii'))
     self.assertEqual(count_messages,
         FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=recipient, spam=True)
     self.assertEqual(len(dms), 1)
Exemple #18
0
    def test_bounce(self):
        mail.outbox = []

        with open(p("test_mail_12.txt"), 'rb') as f:
            process_mail.delay(f.read())

        req = FoiRequest.objects.get(pk=self.req.pk)
        bounce_message = req.messages[-1]
        self.assertEqual(bounce_message.original, req.messages[0])
        tags = bounce_message.tags.all().values_list('name', flat=True)
        self.assertIn(BOUNCE_TAG, tags)
        self.assertTrue(
            ProblemReport.objects.filter(
                message=bounce_message.original).exists())
Exemple #19
0
    def test_spam(self):
        mail.outbox = []

        count_messages = len(self.req.get_messages())
        name, domain = self.req.secret_address.split('@')
        recipient = self.secret_address
        with open(p("test_mail_01.txt"), 'rb') as f:
            email = f.read().decode('ascii').replace('*****@*****.**', '*****@*****.**')
        process_mail.delay(email.encode('ascii'))
        self.assertEqual(count_messages,
            FoiMessage.objects.filter(request=self.req).count())
        dms = DeferredMessage.objects.filter(recipient=recipient, spam=None)
        self.assertEqual(len(dms), 1)
        self.assertEqual(len(mail.outbox), 1)
Exemple #20
0
 def test_working(self):
     with open(p("test_mail_01.txt"), 'rb') as f:
         process_mail.delay(f.read())
     request = FoiRequest.objects.get_by_secret_mail(self.secret_address)
     messages = request.messages
     self.assertEqual(len(messages), 2)
     self.assertIn('Jörg Gahl-Killen', [m.sender_name for m in messages])
     message = messages[1]
     self.assertEqual(message.timestamp,
             datetime(2010, 7, 5, 5, 54, 40, tzinfo=timezone.utc))
     self.assertEqual(
         message.subject,
         'Anfrage nach dem Informationsfreiheitsgesetz;  Förderanträge und Verwendungsnachweise der Hanns-Seidel-Stiftung;  Vg. 375-2018'
     )
     self.assertEqual(message.recipient, request.user.display_name())
     self.assertEqual(message.recipient_email, '*****@*****.**')
Exemple #21
0
 def test_deferred(self):
     count_messages = len(self.req.messages)
     name, domain = self.req.secret_address.split('@')
     bad_mail = '@'.join((name + 'x', domain))
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read().decode('ascii')
     mail = mail.replace(self.secret_address, bad_mail)
     process_mail.delay(mail.encode('ascii'))
     self.assertEqual(count_messages,
                      FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=bad_mail)
     self.assertEqual(len(dms), 1)
     dm = dms[0]
     dm.redeliver(self.req)
     req = FoiRequest.objects.get(id=self.req.id)
     self.assertEqual(len(req.messages), count_messages + 1)
     dm = DeferredMessage.objects.get(id=dm.id)
     self.assertEqual(dm.request, req)
Exemple #22
0
    def test_existing_spam(self):
        mail.outbox = []

        count_messages = len(self.req.get_messages())
        name, domain = self.req.secret_address.split('@')
        recipient = self.secret_address
        sender = '*****@*****.**'
        DeferredMessage.objects.create(
            recipient=recipient, spam=True, sender=sender
        )
        with open(p("test_mail_01.txt"), 'rb') as f:
            email = f.read().decode('ascii').replace('*****@*****.**', sender)
        process_mail.delay(email.encode('ascii'))
        self.assertEqual(count_messages,
            FoiMessage.objects.filter(request=self.req).count())
        dms = DeferredMessage.objects.filter(recipient=recipient, spam=True)
        self.assertEqual(len(dms), 2)
        self.assertEqual(len(mail.outbox), 0)
Exemple #23
0
 def test_deferred(self):
     count_messages = len(self.req.messages)
     name, domain = self.req.secret_address.split('@')
     bad_mail = '@'.join((name + 'x', domain))
     with open(p("test_mail_01.txt"), 'rb') as f:
         mail = f.read().decode('ascii')
     mail = mail.replace(u'*****@*****.**', bad_mail)
     process_mail.delay(mail.encode('ascii'))
     self.assertEqual(count_messages,
         FoiMessage.objects.filter(request=self.req).count())
     dms = DeferredMessage.objects.filter(recipient=bad_mail)
     self.assertEqual(len(dms), 1)
     dm = dms[0]
     dm.redeliver(self.req)
     req = FoiRequest.objects.get(id=self.req.id)
     self.assertEqual(len(req.messages), count_messages + 1)
     dm = DeferredMessage.objects.get(id=dm.id)
     self.assertEqual(dm.request, req)
Exemple #24
0
    def test_double_deferred(self):
        count_messages = len(self.req.get_messages())
        name, domain = self.req.secret_address.split('@')
        bad_mail = '@'.join((name + 'x', domain))
        with open(p("test_mail_01.txt"), 'rb') as f:
            mail = f.read().decode('ascii')
        mail = mail.replace(self.secret_address, bad_mail)
        self.assertEqual(DeferredMessage.objects.count(), 0)

        # there is one deferredmessage matching, so deliver to associated request
        DeferredMessage.objects.create(recipient=bad_mail, request=self.req)
        process_mail.delay(mail.encode('ascii'))
        self.assertEqual(count_messages + 1,
            FoiMessage.objects.filter(request=self.req).count())
        self.assertEqual(DeferredMessage.objects.count(), 1)

        # there is more than one deferredmessage matching
        # So delivery is ambiguous, create deferred message instead
        DeferredMessage.objects.create(recipient=bad_mail, request=self.other_req)
        process_mail.delay(mail.encode('ascii'))
        self.assertEqual(count_messages + 1,
            FoiMessage.objects.filter(request=self.req).count())
        self.assertEqual(DeferredMessage.objects.count(), 3)
Exemple #25
0
    def test_double_deferred(self):
        count_messages = len(self.req.messages)
        name, domain = self.req.secret_address.split('@')
        bad_mail = '@'.join((name + 'x', domain))
        with open(p("test_mail_01.txt"), 'rb') as f:
            mail = f.read().decode('ascii')
        mail = mail.replace(self.secret_address, bad_mail)
        self.assertEqual(DeferredMessage.objects.count(), 0)

        # there is one deferredmessage matching, so deliver to associated request
        DeferredMessage.objects.create(recipient=bad_mail, request=self.req)
        process_mail.delay(mail.encode('ascii'))
        self.assertEqual(count_messages + 1,
            FoiMessage.objects.filter(request=self.req).count())
        self.assertEqual(DeferredMessage.objects.count(), 1)

        # there is more than one deferredmessage matching
        # So delivery is ambiguous, create deferred message instead
        DeferredMessage.objects.create(recipient=bad_mail, request=self.other_req)
        process_mail.delay(mail.encode('ascii'))
        self.assertEqual(count_messages + 1,
            FoiMessage.objects.filter(request=self.req).count())
        self.assertEqual(DeferredMessage.objects.count(), 3)
Exemple #26
0
    def test_working_with_attachment(self):
        request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 1)

        with open(p("test_mail_02.txt"), 'rb') as f:
            process_mail.delay(f.read())

        request = FoiRequest.objects.get_by_secret_mail("*****@*****.**")
        messages = request.foimessage_set.all()
        self.assertEqual(len(messages), 2)
        self.assertEqual(messages[1].subject, u"Fwd: Informationsfreiheitsgesetz des Bundes, Antragsvordruck für Open Data")
        self.assertEqual(len(messages[1].attachments), 2)
        self.assertEqual(messages[1].attachments[0].name,
                         u"TI-IFG-AntragVordruck.docx")
        self.assertTrue(messages[1].attachments[1].name.endswith(u".pdf"))
        self.assertFalse(messages[1].attachments[0].is_converted)
        self.assertTrue(messages[1].attachments[1].is_converted)
        self.assertTrue(messages[1].attachments[1].converted is None)
        self.assertEqual(
            messages[1].attachments[0].converted,
            messages[1].attachments[1]
        )