Skip to content

Commit

Permalink
Refs #35987 -- Added extra tests for ErrorList and ErrorDict copy met…
Browse files Browse the repository at this point in the history
…hods.
  • Loading branch information
adamchainz authored and sarahboyce committed Dec 10, 2024
1 parent 4806c42 commit 5e998d7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/forms_tests/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ def __str__(self):
'<a href="http://www.example.com/">example</a></li></ul>',
)

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
Expand Down Expand Up @@ -195,6 +213,16 @@ def test_error_dict_copy(self):
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."
Expand Down

0 comments on commit 5e998d7

Please sign in to comment.