def test_clear_input_checked_returns_false_only_if_not_required(self): """ ClearableFileInput.value_from_datadict never returns False if the field is required. """ widget = ClearableFileInput() widget.is_required = True field = SimpleUploadedFile("something.txt", b"content") value = widget.value_from_datadict(data={"myfile-clear": True}, files={"myfile": field}, name="myfile") self.assertEqual(value, field)
def test_clear_input_renders_only_if_not_required(self): """ A ClearableFileInput with is_required=False does not render a clear checkbox. """ widget = ClearableFileInput() widget.is_required = True self.check_html(widget, 'myfile', FakeFieldFile(), html=( """ Currently: <a href="something">something</a> <br> Change: <input type="file" name="myfile"> """ ))
def test_clear_input_checked_returns_false_only_if_not_required(self): """ ClearableFileInput.value_from_datadict never returns False if the field is required. """ widget = ClearableFileInput() widget.is_required = True field = SimpleUploadedFile('something.txt', b'content') value = widget.value_from_datadict( data={'myfile-clear': True}, files={'myfile': field}, name='myfile', ) self.assertEqual(value, field)
def test_clear_input_renders_only_if_not_required(self): """ A ClearableFileInput with is_required=True does not render a clear checkbox. """ widget = ClearableFileInput() widget.is_required = True self.check_html( widget, "myfile", FakeFieldFile(), html=(""" Currently: <a href="something">something</a> <br> Change: <input type="file" name="myfile"> """), )