stages/prompt: fix non-required fields not allowing blank values, add more tests
closes #2544 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
5a07d4ec66
commit
4154b62565
|
@ -119,10 +119,12 @@ class Prompt(SerializerModel):
|
|||
}
|
||||
if self.type == FieldTypes.TEXT:
|
||||
kwargs["trim_whitespace"] = False
|
||||
kwargs["allow_blank"] = not self.required
|
||||
if self.type == FieldTypes.TEXT_READ_ONLY:
|
||||
field_class = ReadOnlyField
|
||||
if self.type == FieldTypes.EMAIL:
|
||||
field_class = EmailField
|
||||
kwargs["allow_blank"] = not self.required
|
||||
if self.type == FieldTypes.NUMBER:
|
||||
field_class = IntegerField
|
||||
if self.type == FieldTypes.CHECKBOX:
|
||||
|
|
|
@ -292,7 +292,7 @@ class TestPromptStage(FlowTestCase):
|
|||
prompt.save()
|
||||
|
||||
|
||||
def field_type_tester_factory(field_type: FieldTypes):
|
||||
def field_type_tester_factory(field_type: FieldTypes, required: bool):
|
||||
"""Test field for field_type"""
|
||||
|
||||
def tester(self: TestPromptStage):
|
||||
|
@ -304,11 +304,16 @@ def field_type_tester_factory(field_type: FieldTypes):
|
|||
placeholder_expression=False,
|
||||
sub_text="test",
|
||||
order=123,
|
||||
required=required,
|
||||
)
|
||||
self.assertIsNotNone(prompt.field("foo"))
|
||||
|
||||
return tester
|
||||
|
||||
|
||||
for _required in (True, False):
|
||||
for _type in FieldTypes:
|
||||
setattr(TestPromptStage, f"test_field_type_{_type}", field_type_tester_factory(_type))
|
||||
test_name = f"test_field_type_{_type}"
|
||||
if _required:
|
||||
test_name += "_required"
|
||||
setattr(TestPromptStage, test_name, field_type_tester_factory(_type, _required))
|
||||
|
|
Reference in a new issue