mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
Upgrade to last Django & Python supported versions
This commit is contained in:
parent
462fdd3e49
commit
1c7ddca6ca
10 changed files with 63 additions and 66 deletions
|
|
@ -1,4 +1,3 @@
|
|||
from distutils.version import LooseVersion
|
||||
from unittest import mock
|
||||
|
||||
from django.core.management import call_command, CommandError
|
||||
|
|
@ -20,14 +19,7 @@ class CommandsTestCase(TestCase):
|
|||
args, kwargs = handle.call_args
|
||||
|
||||
# Make sure that we called with the right arguments
|
||||
try:
|
||||
self.assertEqual(kwargs['mailbox_name'], mailbox_name)
|
||||
except KeyError:
|
||||
# Handle Django 1.7
|
||||
# It uses optparse instead of argparse, so instead of being
|
||||
# set to None, mailbox_name is simply left out altogether
|
||||
# Thus we expect an empty tuple here
|
||||
self.assertEqual(args, tuple())
|
||||
self.assertEqual(kwargs['mailbox_name'], mailbox_name)
|
||||
|
||||
|
||||
def test_processincomingmessage_with_arg(self):
|
||||
|
|
@ -40,26 +32,11 @@ class CommandsTestCase(TestCase):
|
|||
|
||||
call_command('processincomingmessage', mailbox_name)
|
||||
args, kwargs = handle.call_args
|
||||
try:
|
||||
self.assertEqual(kwargs['mailbox_name'], mailbox_name)
|
||||
except (AssertionError, KeyError):
|
||||
# Handle Django 1.7
|
||||
# It uses optparse instead of argparse, so instead of being
|
||||
# in kwargs, mailbox_name is in args
|
||||
self.assertEqual(args[0], mailbox_name)
|
||||
|
||||
self.assertEqual(kwargs['mailbox_name'], mailbox_name)
|
||||
|
||||
def test_processincomingmessage_too_many_args(self):
|
||||
"""Check that processincomingmessage raises an error if too many args"""
|
||||
# Only perform this test for Django versions greater than 1.7.*. This
|
||||
# is because, with optparse, too many arguments doesn't result in an
|
||||
# error, which means this test is worthless anyway
|
||||
# For the "compatibility" versions, unexpected arguments aren't handled
|
||||
# very well, and result in a TypeError
|
||||
if (LooseVersion(django.get_version()) >= LooseVersion('1.8') and
|
||||
LooseVersion(django.get_version()) < LooseVersion('1.10')):
|
||||
with self.assertRaises(TypeError):
|
||||
call_command('processincomingmessage', 'foo_mailbox', 'invalid_arg')
|
||||
# In 1.10 and later a proper CommandError should be raised
|
||||
elif LooseVersion(django.get_version()) >= LooseVersion('1.10'):
|
||||
with self.assertRaises(CommandError):
|
||||
call_command('processincomingmessage', 'foo_mailbox', 'invalid_arg')
|
||||
|
||||
with self.assertRaises(CommandError):
|
||||
call_command('processincomingmessage', 'foo_mailbox', 'invalid_arg')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue