From 3cd87c004b39065d2470631e0ff37b845464d0ef Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Mon, 24 Sep 2018 14:53:28 -0300 Subject: [PATCH] Cria teste para campos BooleanField MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Campos BooleanField não devem ser definidos sem o atributo default igual a True ou False. A documentação do Django recomenda que, caso queria que esse campo possa ter uma terceira configuração, deve-se usar NullBooleanField. O teste adicionado neste commit verifica todos os models do projeto sapl e gera um erro nos campos BooleanField que não possuem campo default --- sapl/test_general.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sapl/test_general.py b/sapl/test_general.py index da2e17ae6..c50f21743 100644 --- a/sapl/test_general.py +++ b/sapl/test_general.py @@ -1,10 +1,12 @@ -import pytest from django.apps import apps from django.db.models import CharField, TextField +from django.db.models.fields import BooleanField from model_mommy import mommy +import pytest from .settings import SAPL_APPS + pytestmark = pytest.mark.django_db sapl_appconfs = [apps.get_app_config(n[5:]) for n in SAPL_APPS] @@ -34,3 +36,21 @@ def test_str_sanity(): msg = '%s.%s.__str__ is broken.' % ( model.__module__, model.__name__) raise AssertionError(msg, exc) + + +def test_booleanfield_configure(): + # this simply a sanity check + # __str__ semantics is not considered and should be tested separetely + for app in sapl_appconfs: + for model in app.get_models(): + for field in model._meta.get_fields(): + if not isinstance(field, BooleanField): + continue + assert isinstance(field.default, bool), """ + atributo 'default' não definido em: + Campo: %s + Model: %s + app: %s + """ % (field.name, + model._meta.object_name, + app.name)