Skip to content

Commit

Permalink
test: Added skipped test for checking model mandatory values.
Browse files Browse the repository at this point in the history
see test __doc__ for skip reason

ref: #15 #248 #392
  • Loading branch information
jon-nfc committed Nov 27, 2024
1 parent e9298d7 commit 8cca6e3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/app/tests/abstract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import unittest

from django.db.models import fields

from access.models import TenancyObject
from access.tests.abstract.tenancy_object import TenancyObject as TenancyObjectTestCases
Expand Down Expand Up @@ -60,6 +61,48 @@ def test_attribute_type_ordering(self):
assert type(self.model._meta.original_attrs['ordering']) is list


@pytest.mark.skip( reason = 'see test __doc__' )

def test_model_fields_parameter_mandatory_has_no_default(self):
"""Test Field called with Parameter
## Test skipped
fields dont have enough info to determine if mandatory, so this item can't be
tested.
Some fields can be set as `null=false` with `blank=false` however `default=<value>`
ensures it's populated with a desired default.
If a field is set as null=false, there must not be a default parameter
"""

fields_have_test_value: bool = True

fields_to_skip_checking: list = [
'created',
'is_global',
'modified'
]

for field in self.model._meta.fields:

if field.attname not in fields_to_skip_checking:

print(f'Checking field {field.attname} to see if mandatory')

if not getattr(field, 'null', True) and not getattr(field, 'blank', True):

if getattr(field, 'default', fields.NOT_PROVIDED) != fields.NOT_PROVIDED:

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

fields_have_test_value = False


assert fields_have_test_value



def test_model_fields_parameter_has_help_text(self):
"""Test Field called with Parameter
Expand Down

0 comments on commit 8cca6e3

Please sign in to comment.