test: Ensure that during model field creation, attribute help_text is defined and not empty
ref: #248 #345 #346
This commit is contained in:
@ -61,6 +61,75 @@ class BaseModel:
|
||||
|
||||
|
||||
|
||||
def test_model_fields_parameter_has_help_text(self):
|
||||
"""Test Field called with Parameter
|
||||
|
||||
During field creation, it should have been called with paramater `help_text`
|
||||
"""
|
||||
|
||||
fields_have_test_value: bool = True
|
||||
|
||||
for field in self.model._meta.fields:
|
||||
|
||||
print(f'Checking field {field.attname} has attribute "help_text"')
|
||||
|
||||
if not hasattr(field, 'help_text'):
|
||||
|
||||
print(f' Failure on field {field.attname}')
|
||||
|
||||
fields_have_test_value = False
|
||||
|
||||
|
||||
assert fields_have_test_value
|
||||
|
||||
|
||||
def test_model_fields_parameter_type_help_text(self):
|
||||
"""Test Field called with Parameter
|
||||
|
||||
During field creation, paramater `help_text` must be of type str
|
||||
"""
|
||||
|
||||
fields_have_test_value: bool = True
|
||||
|
||||
for field in self.model._meta.fields:
|
||||
|
||||
print(f'Checking field {field.attname} is of type str')
|
||||
|
||||
if not type(field.help_text) is str:
|
||||
|
||||
print(f' Failure on field {field.attname}')
|
||||
|
||||
fields_have_test_value = False
|
||||
|
||||
|
||||
assert fields_have_test_value
|
||||
|
||||
|
||||
def test_model_fields_parameter_not_empty_help_text(self):
|
||||
"""Test Field called with Parameter
|
||||
|
||||
During field creation, paramater `help_text` must not be `None` or empty ('')
|
||||
"""
|
||||
|
||||
fields_have_test_value: bool = True
|
||||
|
||||
for field in self.model._meta.fields:
|
||||
|
||||
print(f'Checking field {field.attname} is not empty')
|
||||
|
||||
if (
|
||||
field.help_text is not None
|
||||
or field.help_text != ''
|
||||
):
|
||||
|
||||
print(f' Failure on field {field.attname}')
|
||||
|
||||
fields_have_test_value = False
|
||||
|
||||
|
||||
assert fields_have_test_value
|
||||
|
||||
|
||||
class TenancyModel(
|
||||
BaseModel,
|
||||
TenancyObjectTestCases,
|
||||
|
@ -38,7 +38,7 @@ All models must meet the following requirements:
|
||||
!!! danger "Requirement"
|
||||
Multi-field validation, or validation that requires access to multiple fields must be done within the [form class](./forms.md#requirements).
|
||||
|
||||
- contains a `Meta` sub-class with following parameters:
|
||||
- contains a `Meta` sub-class with following attributes:
|
||||
|
||||
- `verbose_name_plural`
|
||||
|
||||
|
Reference in New Issue
Block a user