Tested invalid QuerySet.order_by() arguments.

This commit is contained in:
Tim Graham 2016-10-13 20:54:25 -04:00
parent f2dc6b3a99
commit 4cfccc713a
1 changed files with 11 additions and 3 deletions

View File

@ -2946,7 +2946,7 @@ class WhereNodeTest(TestCase):
w.as_sql(compiler, connection)
class IteratorExceptionsTest(TestCase):
class QuerySetExceptionTests(TestCase):
def test_iter_exceptions(self):
qs = ExtraInfo.objects.only('author')
with self.assertRaises(AttributeError):
@ -2956,11 +2956,19 @@ class IteratorExceptionsTest(TestCase):
# Test for #19895 - second iteration over invalid queryset
# raises errors.
qs = Article.objects.order_by('invalid_column')
with self.assertRaises(FieldError):
msg = "Cannot resolve keyword 'invalid_column' into field."
with self.assertRaisesMessage(FieldError, msg):
list(qs)
with self.assertRaises(FieldError):
with self.assertRaisesMessage(FieldError, msg):
list(qs)
def test_invalid_order_by(self):
msg = "Invalid order_by arguments: ['*']"
if six.PY2:
msg = msg.replace("[", "[u")
with self.assertRaisesMessage(FieldError, msg):
list(Article.objects.order_by('*'))
class NullJoinPromotionOrTest(TestCase):
@classmethod