From 5e998d717f7b4220a1728bd49b66ca0162e2a6cb Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 9 Dec 2024 15:43:01 +0000 Subject: [PATCH] Refs #35987 -- Added extra tests for ErrorList and ErrorDict copy methods. --- tests/forms_tests/tests/test_utils.py | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/forms_tests/tests/test_utils.py b/tests/forms_tests/tests/test_utils.py index 85f7094212..a50f86c934 100644 --- a/tests/forms_tests/tests/test_utils.py +++ b/tests/forms_tests/tests/test_utils.py @@ -162,6 +162,24 @@ class FormsUtilsTestCase(SimpleTestCase): 'example', ) + def test_error_list_copy(self): + e = ErrorList( + [ + ValidationError( + message="message %(i)s", + params={"i": 1}, + ), + ValidationError( + message="message %(i)s", + params={"i": 2}, + ), + ] + ) + + e_copy = copy.copy(e) + self.assertEqual(e, e_copy) + self.assertEqual(e.as_data(), e_copy.as_data()) + def test_error_list_copy_attributes(self): class CustomRenderer(DjangoTemplates): pass @@ -195,6 +213,16 @@ class FormsUtilsTestCase(SimpleTestCase): e_deepcopy = copy.deepcopy(e) self.assertEqual(e, e_deepcopy) + def test_error_dict_copy_attributes(self): + class CustomRenderer(DjangoTemplates): + pass + + renderer = CustomRenderer() + e = ErrorDict(renderer=renderer) + + e_copy = copy.copy(e) + self.assertEqual(e.renderer, e_copy.renderer) + def test_error_dict_html_safe(self): e = ErrorDict() e["username"] = "Invalid username."