From 746b6f0b16986dddaec5b30ae6b3596b703c4bc5 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 13 Oct 2024 21:01:59 +0930 Subject: [PATCH] test: Ensure that during model field creation, attribute help_text is defined and not empty ref: #248 #345 #346 --- app/app/tests/abstract/models.py | 69 +++++++++++++++++++ .../centurion_erp/development/models.md | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/app/tests/abstract/models.py b/app/app/tests/abstract/models.py index 4cb1ba379..a69fb1237 100644 --- a/app/app/tests/abstract/models.py +++ b/app/app/tests/abstract/models.py @@ -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, diff --git a/docs/projects/centurion_erp/development/models.md b/docs/projects/centurion_erp/development/models.md index a142cde1d..d3cb29e18 100644 --- a/docs/projects/centurion_erp/development/models.md +++ b/docs/projects/centurion_erp/development/models.md @@ -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`