summaryrefslogtreecommitdiff
path: root/tests/pagination
diff options
context:
space:
mode:
authorMarcelo Galigniana <marcelogaligniana@gmail.com>2023-04-09 22:30:40 -0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-12 14:02:28 +0200
commitdfc720c521062cdefd64bc48a11838b0fa583439 (patch)
tree8b38ad33d223e8c56f21a609fe504ac06cef5b92 /tests/pagination
parent041b0a359a0a80e147b47c6ae5f11bca9dd3b28a (diff)
downloaddjango-dfc720c521062cdefd64bc48a11838b0fa583439.tar.gz
Fixed #27505 -- Allowed customizing Paginator's error messages.
Diffstat (limited to 'tests/pagination')
-rw-r--r--tests/pagination/tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index a04b6dfe8a..1fa9ea2f02 100644
--- a/tests/pagination/tests.py
+++ b/tests/pagination/tests.py
@@ -128,6 +128,34 @@ class PaginationTests(SimpleTestCase):
with self.assertRaises(PageNotAnInteger):
paginator.validate_number(1.2)
+ def test_error_messages(self):
+ error_messages = {
+ "invalid_page": "Wrong page number",
+ "min_page": "Too small",
+ "no_results": "There is nothing here",
+ }
+ paginator = Paginator([1, 2, 3], 2, error_messages=error_messages)
+ msg = "Wrong page number"
+ with self.assertRaisesMessage(PageNotAnInteger, msg):
+ paginator.validate_number(1.2)
+ msg = "Too small"
+ with self.assertRaisesMessage(EmptyPage, msg):
+ paginator.validate_number(-1)
+ msg = "There is nothing here"
+ with self.assertRaisesMessage(EmptyPage, msg):
+ paginator.validate_number(3)
+
+ error_messages = {"min_page": "Too small"}
+ paginator = Paginator([1, 2, 3], 2, error_messages=error_messages)
+ # Custom message.
+ msg = "Too small"
+ with self.assertRaisesMessage(EmptyPage, msg):
+ paginator.validate_number(-1)
+ # Default message.
+ msg = "That page contains no results"
+ with self.assertRaisesMessage(EmptyPage, msg):
+ paginator.validate_number(3)
+
def test_float_integer_page(self):
paginator = Paginator([1, 2, 3], 2)
self.assertEqual(paginator.validate_number(1.0), 1)