From 65441bbdb02427655869c42791a0bc5a9c631292 Mon Sep 17 00:00:00 2001 From: Michael Angeletti Date: Sun, 22 Feb 2015 22:06:41 -0500 Subject: Fixed #24391 -- Made BoundField.value() cache callable values. --- tests/forms_tests/tests/test_forms.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/forms_tests') diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 4024f0359e..589a9cfc84 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import copy import datetime import json +import uuid from django.core.exceptions import NON_FIELD_ERRORS from django.core.files.uploadedfile import SimpleUploadedFile @@ -1369,6 +1370,20 @@ class FormsTestCase(TestCase): self.assertEqual(bound['password'].value(), 'foo') self.assertEqual(unbound['password'].value(), None) + def test_boundfield_initial_called_once(self): + """ + Multiple calls to BoundField().value() in an unbound form should return + the same result each time (#24391). + """ + class MyForm(Form): + name = CharField(max_length=10, initial=uuid.uuid4) + + form = MyForm() + name = form['name'] + self.assertEqual(name.value(), name.value()) + # BoundField is also cached + self.assertIs(form['name'], name) + def test_boundfield_rendering(self): """ Python 2 issue: Test that rendering a BoundField with bytestring content -- cgit v1.3