Skip to content

Commit

Permalink
test: Ensure that during model field creation, attribute help_text is…
Browse files Browse the repository at this point in the history
… defined and not empty

ref:  #248 #345 #346
  • Loading branch information
jon-nfc committed Nov 7, 2024
1 parent 48ba947 commit 746b6f0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions app/app/tests/abstract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,75 @@ def test_attribute_type_ordering(self):



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,
Expand Down
2 changes: 1 addition & 1 deletion docs/projects/centurion_erp/development/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down

0 comments on commit 746b6f0

Please sign in to comment.