Skip to content

Commit

Permalink
Ajustes na estrutura de tests pacientes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigmars committed Apr 30, 2024
1 parent 9c260bd commit 8b5370e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
41 changes: 36 additions & 5 deletions pacientes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django import forms
from .utils import AGENDAMENTO_FIXO_CHOICES, GENERO_CHOICES
from .models import Paciente
import re

from django.core.validators import (
MinLengthValidator,
MaxLengthValidator,
Expand Down Expand Up @@ -371,10 +373,29 @@ def clean(self):

super().clean()

valid_alpha = "[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ\\-_\\s]+$"

valid_alpha_numeric = "[A-Za-z0-9_À-ÿ.-_\\s]+$"

nome = self.cleaned_data.get("nome")

data_de_nascimento = self.cleaned_data.get("data_de_nascimento")

cartao_sus = self.cleaned_data.get("cartao_sus")

agendamento_fixo = self.cleaned_data.get("agendamento_fixo")

telefone = self.cleaned_data.get("telefone")

rua = self.cleaned_data.get("rua")

numero = self.cleaned_data.get("numero")

complemento = self.cleaned_data.get("complemento")

ponto_referencia = self.cleaned_data.get("ponto_referencia")

# NOME
if not nome:
raise forms.ValidationError(
{"nome": "Campo obrigatório, deve conter de 5 a 60 caracteres"}
Expand All @@ -385,19 +406,29 @@ def clean(self):
{"nome": "Campo deve conter de 5 a 60 caracteres"}
)

if not nome:
if re.match(valid_alpha, nome) is None:
raise forms.ValidationError(
{"nome": "Campo inválido, informe apenas texto"}
)

# raise forms.ValidationError("deve conter de 4 a 60 caracteres")

# DATA_DE_NASCIMENTO
if not data_de_nascimento:
raise forms.ValidationError("Campo obrigatório")
raise forms.ValidationError({"data_de_nascimento": "Campo obrigatório"})

ano = int(datetime.now().year - (data_de_nascimento.year))

if ano == -1 or ano > 100:
raise forms.ValidationError("Informe uma data válida")
raise forms.ValidationError(
{"data_de_nascimento": "Informe uma data válida"}
)

# CARTAO_SUS
if not cartao_sus:
raise forms.ValidationError({"cartao_sus": "Campo obrigatório"})

if not cartao_sus:
raise forms.ValidationError({"cartao_sus": "Campo obrigatório"})

# CARTAO_SUS

return self.cleaned_data
24 changes: 20 additions & 4 deletions pacientes/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
from unicodedata import numeric
from django.test import TestCase
from ..forms import PacienteForm
import re


class PacienteModelTests(TestCase):
class PacienteFormTestCase(TestCase):

validAlpha = "[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ\\-_\\s]+$"
def setUp(self):

validAlphaNumeric = "[A-Za-z0-9_À-ÿ.-_\\s]+$"
self.alpha_pattern = "[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ\\-_\\s]+$"

self.alpha_numeric_pattern = "[A-Za-z0-9_À-ÿ.-_\\s]+$"

self.numeric_pattern = "[^0-9]"

self.phone_number_pattern = "([0-9]{2})?([0-9]{2})([0-9]{4,5})([0-9]{4})"

self.phone_number = "+55(62) +._=98833-91509"

def test_acerto_para_formato_numerico_campo_telefone(self):

self.assertTrue(
re.sub(self.numeric_pattern, "", self.phone_number).isnumeric(),
"Formato inválido para telefone",
)

def test_falha_no_formato_campo_nome(self):

nome = "Tatiane Eliane. Aparício"

self.assertIs(re.match(self.validAlpha, nome), None)
self.assertIsNone(re.match(self.alpha_pattern, nome))
Empty file added pacientes/tests/test_models.py
Empty file.
Empty file added pacientes/tests/test_views.py
Empty file.

0 comments on commit 8b5370e

Please sign in to comment.