Check that folder is a dir before checking for mail using get_email; fix unit test for --quiet

This commit is contained in:
Garret Wassermann 2016-10-20 01:39:24 -04:00
parent e3c9e04feb
commit b7ef83f7d2
2 changed files with 6 additions and 4 deletions

View File

@ -18,7 +18,7 @@ import poplib
import re import re
import socket import socket
from os import listdir, unlink from os import listdir, unlink
from os.path import isfile, join from os.path import isfile, isdir, join
from datetime import timedelta from datetime import timedelta
from email.header import decode_header from email.header import decode_header
@ -97,7 +97,7 @@ def process_email(quiet=False):
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
if quiet: if quiet:
logger.propagate = False # do not propagate to root logger that would log to console logger.propagate = False # do not propagate to root logger that would log to console
logdir = q.logging_dir or '/var/log/helpdesk/' logdir = q.logging_dir if isdir(q.logging_dir) else '/var/log/helpdesk/'
handler = logging.FileHandler(logdir + q.slug + '_get_email.log') handler = logging.FileHandler(logdir + q.slug + '_get_email.log')
logger.addHandler(handler) logger.addHandler(handler)
@ -212,7 +212,7 @@ def process_queue(q, logger):
server.logout() server.logout()
elif email_box_type == 'local': elif email_box_type == 'local':
mail_dir = q.email_box_local_dir or '/var/lib/mail/helpdesk/' mail_dir = q.email_box_local_dir if isdir(q.email_box_local_dir) else '/var/lib/mail/helpdesk/'
mail = [join(mail_dir, f) for f in listdir(mail_dir) if isfile(join(mail_dir, f))] mail = [join(mail_dir, f) for f in listdir(mail_dir) if isfile(join(mail_dir, f))]
logger.info("Found %s messages in local mailbox directory" % str(len(mail))) logger.info("Found %s messages in local mailbox directory" % str(len(mail)))
for m in mail: for m in mail:

View File

@ -29,8 +29,10 @@ class GetEmailTestCase(TestCase):
# tests correct syntax for command line option # tests correct syntax for command line option
def test_get_email_quiet_option(self): def test_get_email_quiet_option(self):
with mock.patch('helpdesk.management.commands.get_email.process_email') as mocked_processemail: with mock.patch('helpdesk.management.commands.get_email.process_email') as mocked_processemail:
management.call_command('get_email', '-q') management.call_command('get_email', '--quiet')
mocked_processemail.assert_called_with(quiet=True) mocked_processemail.assert_called_with(quiet=True)
management.call_command('get_email')
mocked_processemail.assert_called_with(quiet=False)
# tests reading emails from a queue and creating tickets # tests reading emails from a queue and creating tickets
def test_read_email(self): def test_read_email(self):