diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
| commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
| tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/forms_tests/widget_tests/test_checkboxinput.py | |
| parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/forms_tests/widget_tests/test_checkboxinput.py')
| -rw-r--r-- | tests/forms_tests/widget_tests/test_checkboxinput.py | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/tests/forms_tests/widget_tests/test_checkboxinput.py b/tests/forms_tests/widget_tests/test_checkboxinput.py index 8dba2178c9..0f65e876df 100644 --- a/tests/forms_tests/widget_tests/test_checkboxinput.py +++ b/tests/forms_tests/widget_tests/test_checkboxinput.py @@ -7,18 +7,26 @@ class CheckboxInputTest(WidgetTest): widget = CheckboxInput() def test_render_empty(self): - self.check_html(self.widget, 'is_cool', '', html='<input type="checkbox" name="is_cool">') + self.check_html( + self.widget, "is_cool", "", html='<input type="checkbox" name="is_cool">' + ) def test_render_none(self): - self.check_html(self.widget, 'is_cool', None, html='<input type="checkbox" name="is_cool">') + self.check_html( + self.widget, "is_cool", None, html='<input type="checkbox" name="is_cool">' + ) def test_render_false(self): - self.check_html(self.widget, 'is_cool', False, html='<input type="checkbox" name="is_cool">') + self.check_html( + self.widget, "is_cool", False, html='<input type="checkbox" name="is_cool">' + ) def test_render_true(self): self.check_html( - self.widget, 'is_cool', True, - html='<input checked type="checkbox" name="is_cool">' + self.widget, + "is_cool", + True, + html='<input checked type="checkbox" name="is_cool">', ) def test_render_value(self): @@ -27,7 +35,9 @@ class CheckboxInputTest(WidgetTest): checkbox and set the 'value' attribute. """ self.check_html( - self.widget, 'is_cool', 'foo', + self.widget, + "is_cool", + "foo", html='<input checked type="checkbox" name="is_cool" value="foo">', ) @@ -36,11 +46,15 @@ class CheckboxInputTest(WidgetTest): Integers are handled by value, not as booleans (#17114). """ self.check_html( - self.widget, 'is_cool', 0, + self.widget, + "is_cool", + 0, html='<input checked type="checkbox" name="is_cool" value="0">', ) self.check_html( - self.widget, 'is_cool', 1, + self.widget, + "is_cool", + 1, html='<input checked type="checkbox" name="is_cool" value="1">', ) @@ -49,30 +63,43 @@ class CheckboxInputTest(WidgetTest): You can pass 'check_test' to the constructor. This is a callable that takes the value and returns True if the box should be checked. """ - widget = CheckboxInput(check_test=lambda value: value.startswith('hello')) - self.check_html(widget, 'greeting', '', html=( - '<input type="checkbox" name="greeting">' - )) - self.check_html(widget, 'greeting', 'hello', html=( - '<input checked type="checkbox" name="greeting" value="hello">' - )) - self.check_html(widget, 'greeting', 'hello there', html=( - '<input checked type="checkbox" name="greeting" value="hello there">' - )) - self.check_html(widget, 'greeting', 'hello & goodbye', html=( - '<input checked type="checkbox" name="greeting" value="hello & goodbye">' - )) + widget = CheckboxInput(check_test=lambda value: value.startswith("hello")) + self.check_html( + widget, "greeting", "", html=('<input type="checkbox" name="greeting">') + ) + self.check_html( + widget, + "greeting", + "hello", + html=('<input checked type="checkbox" name="greeting" value="hello">'), + ) + self.check_html( + widget, + "greeting", + "hello there", + html=( + '<input checked type="checkbox" name="greeting" value="hello there">' + ), + ) + self.check_html( + widget, + "greeting", + "hello & goodbye", + html=( + '<input checked type="checkbox" name="greeting" value="hello & goodbye">' + ), + ) def test_render_check_exception(self): """ Calling check_test() shouldn't swallow exceptions (#17888). """ widget = CheckboxInput( - check_test=lambda value: value.startswith('hello'), + check_test=lambda value: value.startswith("hello"), ) with self.assertRaises(AttributeError): - widget.render('greeting', True) + widget.render("greeting", True) def test_value_from_datadict(self): """ @@ -80,17 +107,19 @@ class CheckboxInputTest(WidgetTest): the data dictionary (because HTML form submission doesn't send any result for unchecked checkboxes). """ - self.assertFalse(self.widget.value_from_datadict({}, {}, 'testing')) + self.assertFalse(self.widget.value_from_datadict({}, {}, "testing")) def test_value_from_datadict_string_int(self): - value = self.widget.value_from_datadict({'testing': '0'}, {}, 'testing') + value = self.widget.value_from_datadict({"testing": "0"}, {}, "testing") self.assertIs(value, True) def test_value_omitted_from_data(self): - self.assertIs(self.widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False) - self.assertIs(self.widget.value_omitted_from_data({}, {}, 'field'), False) + self.assertIs( + self.widget.value_omitted_from_data({"field": "value"}, {}, "field"), False + ) + self.assertIs(self.widget.value_omitted_from_data({}, {}, "field"), False) def test_get_context_does_not_mutate_attrs(self): - attrs = {'checked': False} - self.widget.get_context('name', True, attrs) - self.assertIs(attrs['checked'], False) + attrs = {"checked": False} + self.widget.get_context("name", True, attrs) + self.assertIs(attrs["checked"], False) |
