From 6418194b85549de23e56315bf9a5e79cf5d05c96 Mon Sep 17 00:00:00 2001 From: Garret Wassermann Date: Thu, 20 Oct 2016 02:21:43 -0400 Subject: [PATCH] Fix command line arg for Django 1.7 and make Python 2 and 3 compatible test --- helpdesk/management/commands/get_email.py | 3 ++- helpdesk/tests/test_get_email.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index bfe5dce3..ee2367bd 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -55,9 +55,10 @@ class Command(BaseCommand): if VERSION < (1, 8): self.option_list += ( make_option( - '--quiet', '-q', + '--quiet', default=False, action='store_true', + dest='quiet', help='Hide details about each queue/message as they are processed'), ) diff --git a/helpdesk/tests/test_get_email.py b/helpdesk/tests/test_get_email.py index 630af619..d1646dbe 100644 --- a/helpdesk/tests/test_get_email.py +++ b/helpdesk/tests/test_get_email.py @@ -4,6 +4,7 @@ from django.test import TestCase from django.core import mail from django.core.management import call_command from django.test.client import Client +from django.utils import six from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404 @@ -38,13 +39,13 @@ class GetEmailTestCase(TestCase): test_email = "To: update.public@example.com\nFrom: comment@example.com\nSubject: Some Comment\n\nThis is the helpdesk comment via email." with mock.patch('helpdesk.management.commands.get_email.listdir') as mocked_listdir, \ mock.patch('helpdesk.management.commands.get_email.isfile') as mocked_isfile, \ - mock.patch('builtins.open', mock.mock_open(read_data=test_email)): + mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=test_email)): mocked_isfile.return_value = True mocked_listdir.return_value = ['filename1', 'filename2'] call_command('get_email') - mocked_listdir.assert_called_with('/var/lib/mail/helpdesk') + mocked_listdir.assert_called_with('/var/lib/mail/helpdesk/') mocked_isfile.assert_any_call('/var/lib/mail/helpdesk/filename1') mocked_isfile.assert_any_call('/var/lib/mail/helpdesk/filename2')