mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
make tox -e flake8 work
This commit is contained in:
parent
40263b6670
commit
b6b903c025
7 changed files with 17 additions and 23 deletions
1
.flake8
1
.flake8
|
|
@ -1,2 +1,3 @@
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude = django_mailbox/migrations, django_mailbox/south_migrations
|
exclude = django_mailbox/migrations, django_mailbox/south_migrations
|
||||||
|
ignore = E501,W503,W504 # line too long & line break before and after binary operator
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import email
|
||||||
import logging
|
import logging
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
|
||||||
import uuid
|
import uuid
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
|
|
@ -416,13 +415,12 @@ class Mailbox(models.Model):
|
||||||
|
|
||||||
def get_new_mail(self, condition=None):
|
def get_new_mail(self, condition=None):
|
||||||
"""Connect to this transport and fetch new messages."""
|
"""Connect to this transport and fetch new messages."""
|
||||||
new_mail = []
|
|
||||||
connection = self.get_connection()
|
connection = self.get_connection()
|
||||||
if not connection:
|
if not connection:
|
||||||
return
|
return
|
||||||
for message in connection.get_message(condition):
|
for message in connection.get_message(condition):
|
||||||
msg = self.process_incoming_message(message)
|
msg = self.process_incoming_message(message)
|
||||||
if not msg is None:
|
if msg is not None:
|
||||||
yield msg
|
yield msg
|
||||||
self.last_polling = now()
|
self.last_polling = now()
|
||||||
if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields
|
if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,20 @@ class TestMailbox(TestCase):
|
||||||
|
|
||||||
def test_get_new_mail_update_last_polling(self):
|
def test_get_new_mail_update_last_polling(self):
|
||||||
mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join(
|
mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
'messages',
|
'messages',
|
||||||
'generic_message.eml',
|
'generic_message.eml',
|
||||||
))
|
))
|
||||||
self.assertEqual(mailbox.last_polling, None)
|
self.assertEqual(mailbox.last_polling, None)
|
||||||
list(mailbox.get_new_mail())
|
list(mailbox.get_new_mail())
|
||||||
self.assertNotEqual(mailbox.last_polling, None)
|
self.assertNotEqual(mailbox.last_polling, None)
|
||||||
|
|
||||||
def test_queryset_get_new_mail(self):
|
def test_queryset_get_new_mail(self):
|
||||||
mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join(
|
mailbox = Mailbox.objects.create(uri="mbox://" + os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
'messages',
|
'messages',
|
||||||
'generic_message.eml',
|
'generic_message.eml',
|
||||||
))
|
))
|
||||||
Mailbox.objects.filter(pk=mailbox.pk).get_new_mail()
|
Mailbox.objects.filter(pk=mailbox.pk).get_new_mail()
|
||||||
mailbox.refresh_from_db()
|
mailbox.refresh_from_db()
|
||||||
self.assertNotEqual(mailbox.last_polling, None)
|
self.assertNotEqual(mailbox.last_polling, None)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import gzip
|
import gzip
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
@ -182,7 +181,7 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
# it's ok to call as_string() before passing email_object
|
# it's ok to call as_string() before passing email_object
|
||||||
# to _get_dehydrated_message()
|
# to _get_dehydrated_message()
|
||||||
email_object.as_string()
|
email_object.as_string()
|
||||||
except:
|
except Exception:
|
||||||
it = 'do not works'
|
it = 'do not works'
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
|
|
@ -227,7 +226,7 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
try:
|
try:
|
||||||
# here as_string raises UnicodeEncodeError
|
# here as_string raises UnicodeEncodeError
|
||||||
str_msg = message.as_string()
|
str_msg = message.as_string()
|
||||||
except:
|
except Exception:
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
msg.set_body(str_msg)
|
msg.set_body(str_msg)
|
||||||
|
|
@ -423,8 +422,6 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
|
|
||||||
msg = self.mailbox.process_incoming_message(message)
|
msg = self.mailbox.process_incoming_message(message)
|
||||||
|
|
||||||
actual_email_object = msg.get_email_object()
|
|
||||||
|
|
||||||
self.assertTrue(msg.eml.name.endswith('.eml.gz'))
|
self.assertTrue(msg.eml.name.endswith('.eml.gz'))
|
||||||
|
|
||||||
with gzip.open(msg.eml.name, 'rb') as f:
|
with gzip.open(msg.eml.name, 'rb') as f:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from django.core.management import call_command, CommandError
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
import django
|
import django
|
||||||
|
|
||||||
|
|
||||||
class CommandsTestCase(TestCase):
|
class CommandsTestCase(TestCase):
|
||||||
def test_processincomingmessage_no_args(self):
|
def test_processincomingmessage_no_args(self):
|
||||||
"""Check that processincomingmessage works with no args"""
|
"""Check that processincomingmessage works with no args"""
|
||||||
|
|
@ -29,7 +30,6 @@ class CommandsTestCase(TestCase):
|
||||||
# Thus we expect an empty tuple here
|
# Thus we expect an empty tuple here
|
||||||
self.assertEqual(args, tuple())
|
self.assertEqual(args, tuple())
|
||||||
|
|
||||||
|
|
||||||
def test_processincomingmessage_with_arg(self):
|
def test_processincomingmessage_with_arg(self):
|
||||||
"""Check that processincomingmessage works with mailbox_name given"""
|
"""Check that processincomingmessage works with mailbox_name given"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import sys
|
|
||||||
|
|
||||||
from .base import EmailTransport
|
from .base import EmailTransport
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue