summaryrefslogtreecommitdiff
path: root/tests/get_earliest_or_latest
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-10 09:16:28 +0100
committerGitHub <noreply@github.com>2021-03-10 09:16:28 +0100
commitba9a2b754452b542d3f472f0acce6f940911aced (patch)
tree3ef805503af0ff58dedba310ae18a0b1f14c8edd /tests/get_earliest_or_latest
parent6f5dbe9dbe45b23b3befe4f1cd2ea13b6049ab96 (diff)
downloaddjango-ba9a2b754452b542d3f472f0acce6f940911aced.tar.gz
Refs #32508 -- Raised TypeError instead of using "assert" on unsupported operations for sliced querysets.
Diffstat (limited to 'tests/get_earliest_or_latest')
-rw-r--r--tests/get_earliest_or_latest/tests.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/get_earliest_or_latest/tests.py b/tests/get_earliest_or_latest/tests.py
index 96ebe19f32..0234deb195 100644
--- a/tests/get_earliest_or_latest/tests.py
+++ b/tests/get_earliest_or_latest/tests.py
@@ -81,6 +81,11 @@ class EarliestOrLatestTests(TestCase):
Article.objects.model._meta.get_latest_by = ('pub_date', 'expire_date')
self.assertEqual(Article.objects.filter(pub_date=datetime(2005, 7, 28)).earliest(), a4)
+ def test_earliest_sliced_queryset(self):
+ msg = 'Cannot change a query once a slice has been taken.'
+ with self.assertRaisesMessage(TypeError, msg):
+ Article.objects.all()[0:5].earliest()
+
def test_latest(self):
# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
with self.assertRaises(Article.DoesNotExist):
@@ -143,6 +148,11 @@ class EarliestOrLatestTests(TestCase):
Article.objects.model._meta.get_latest_by = ('pub_date', 'expire_date')
self.assertEqual(Article.objects.filter(pub_date=datetime(2005, 7, 27)).latest(), a3)
+ def test_latest_sliced_queryset(self):
+ msg = 'Cannot change a query once a slice has been taken.'
+ with self.assertRaisesMessage(TypeError, msg):
+ Article.objects.all()[0:5].latest()
+
def test_latest_manual(self):
# You can still use latest() with a model that doesn't have
# "get_latest_by" set -- just pass in the field name manually.