| 1 |
from django.forms import CharField, Form, PasswordInput |
| 2 |
|
| 3 |
from .base import WidgetTest |
| 4 |
|
| 5 |
|
| 6 |
class PasswordInputTest(WidgetTest): |
| 7 |
widget = PasswordInput() |
| 8 |
|
| 9 |
def test_render(self): |
| 10 |
self.check_html( |
| 11 |
self.widget, "password", "", html='<input type="password" name="password">' |
| 12 |
) |
| 13 |
|
| 14 |
def test_render_ignore_value(self): |
| 15 |
self.check_html( |
| 16 |
self.widget, |
| 17 |
"password", |
| 18 |
"secret", |
| 19 |
html='<input type="password" name="password">', |
| 20 |
) |
| 21 |
|
| 22 |
def test_render_value_true(self): |
| 23 |
""" |
| 24 |
The render_value argument lets you specify whether the widget should |
| 25 |
render its value. For security reasons, this is off by default. |
| 26 |
""" |
| 27 |
widget = PasswordInput(render_value=True) |
| 28 |
self.check_html( |
| 29 |
widget, "password", "", html='<input type="password" name="password">' |
| 30 |
) |
| 31 |
self.check_html( |
| 32 |
widget, "password", None, html='<input type="password" name="password">' |
| 33 |
) |
| 34 |
self.check_html( |
| 35 |
widget, |
| 36 |
"password", |
| 37 |
"[email protected]", |
| 38 |
html='<input type="password" name="password" value="[email protected]">', |
| 39 |
) |
| 40 |
|
| 41 |
def test_fieldset(self): |
| 42 |
class TestForm(Form): |
| 43 |
template_name = "forms_tests/use_fieldset.html" |
| 44 |
field = CharField(widget=self.widget) |
| 45 |
|
| 46 |
form = TestForm() |
| 47 |
self.assertIs(self.widget.use_fieldset, False) |
| 48 |
self.assertHTMLEqual( |
| 49 |
'<div><label for="id_field">Field:</label>' |
| 50 |
'<input type="password" name="field" required id="id_field"></div>', |
| 51 |
form.render(), |
| 52 |
) |