From 33b48b2f7307ab28ebcad20b5134b5189c05c54f Mon Sep 17 00:00:00 2001 From: Thomas Chamberlin Date: Fri, 9 Mar 2018 17:02:50 -0500 Subject: [PATCH] Bug fixes for Django versions 1.8 and 1.9 These are versions in which a "compatibility mode" is in place for argument handling, and things didn't work quite the way I expected --- django_mailbox/tests/test_processincomingmessage.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/django_mailbox/tests/test_processincomingmessage.py b/django_mailbox/tests/test_processincomingmessage.py index 8110913..5ec2432 100644 --- a/django_mailbox/tests/test_processincomingmessage.py +++ b/django_mailbox/tests/test_processincomingmessage.py @@ -42,7 +42,7 @@ class CommandsTestCase(TestCase): args, kwargs = handle.call_args try: self.assertEqual(kwargs['mailbox_name'], mailbox_name) - except KeyError: + except (AssertionError, KeyError): # Handle Django 1.7 # It uses optparse instead of argparse, so instead of being # in kwargs, mailbox_name is in args @@ -53,6 +53,13 @@ class CommandsTestCase(TestCase): # 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 - if LooseVersion(django.get_version()) >= LooseVersion('1.8'): + # 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')