Skip to content

Commit

Permalink
test(access): Team custom tests to ensure that during model field cre…
Browse files Browse the repository at this point in the history
…ation, attribute verbose_name is defined and not empty

as team extends group, filtering of group fields is required so they are not checked when testing

ref:  #248 #345 #346
  • Loading branch information
jon-nfc committed Nov 7, 2024
1 parent c699d18 commit 69083ae
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion app/access/tests/unit/team/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,74 @@ def test_attribute_is_type_objects(self):

@pytest.mark.skip(reason="uses Django group manager")
def test_model_class_tenancy_manager_function_get_queryset_called(self):
pass
pass


def test_model_fields_parameter_not_empty_help_text(self):
"""Test Field called with Parameter
This is a custom test of a test derived of the samae name. It's required
as the team model extends the Group model.
During field creation, paramater `help_text` must not be `None` or empty ('')
"""

group_mode_fields_to_ignore: list = [
'id',
'name',
'group_ptr_id'
]

fields_have_test_value: bool = True

for field in self.model._meta.fields:

if field.attname in group_mode_fields_to_ignore:

continue

print(f'Checking field {field.attname} is not empty')

if (
field.help_text is None
or 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_verbose_name(self):
"""Test Field called with Parameter
This is a custom test of a test derived of the samae name. It's required
as the team model extends the Group model.
During field creation, paramater `verbose_name` must be of type str
"""

group_mode_fields_to_ignore: list = [
'name',
]

fields_have_test_value: bool = True

for field in self.model._meta.fields:

if field.attname in group_mode_fields_to_ignore:

continue

print(f'Checking field {field.attname} is of type str')

if not type(field.verbose_name) is str:

print(f' Failure on field {field.attname}')

fields_have_test_value = False


assert fields_have_test_value

0 comments on commit 69083ae

Please sign in to comment.