Skip to content

Commit

Permalink
Merge pull request #19 from fga-gpp-mds/devel
Browse files Browse the repository at this point in the history
TS03-Validate
  • Loading branch information
Ronyell authored Oct 7, 2017
2 parents 071677c + 244bc4d commit 0f1d98e
Show file tree
Hide file tree
Showing 16 changed files with 798 additions and 206 deletions.
26 changes: 14 additions & 12 deletions medical_prescription/user/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# CRM MESSAGES VALIDATION MESSAGES.
CRM_SIZE = 'CRM must have 5 characters.'
CRM_STATE_SIZE = 'CRM must have 2 characters.'
CRM_FORMAT = 'CRM must contain /only numbers.'
CRM_FORMAT = 'CRM must contain only numbers.'
CRM_EXIST = 'CRM already exists'

# UF FIELDS.
Expand Down Expand Up @@ -51,19 +51,20 @@

# NAME VALIDATION MESSAGES
NAME_CHARACTERS = 'Name must not contain special characteres'
NAME_FORMAT = 'Name must contain o nly letters'
NAME_FORMAT = 'Name must contain only letters'
NAME_SIZE = 'Name must be between 5 and 50 characteres'

# EMAIL FIELDS
EMAIL = "E-mail"
EMAIL_FIELD_LENGTH = 50
EMAIL_MIN_LENGTH = 5
EMAIL_MIN_LENGTH = 6
EMAIL_MAX_LENGTH = 50

# EMAIL VALIDATION MESSAGES.
EMAIL_FORMAT = "E-mail must be a valid e-mail. Example: [email protected]"
EMAIL_SIZE = "E-mail must be between 5 and 50 characters"
EMAIL_EXISTS = "Email already exists"
EMAIL_EXISTS = "E-mail already exists"
EMAIL_NONE = "Must have an E-mail"

# EMAIL MESSAGES
EMAIL_SUBJECT = 'Recuperação de sua senha'
Expand All @@ -75,17 +76,19 @@
# DATE_OF_BIRTH FIELDS.
DATE_OF_BIRTH = "Date of birth"
DATE_OF_BIRTH_MIN = 18
DATE_OF_BIRTH_MIN_PATIENT = 0

# DATE_OF_BIRTH VALIDATION MESSAGES.
DATE_OF_BIRTH_FORMAT = "Date of birth must be in format: dd/mm/yyyy"
DATE_OF_BIRTH_MIN_ERROR = "User must be 18 years"

DATE_OF_BIRTH_MIN_PATIENT_ERROR = "User cannot be born in the future"
# PHONE_NUMBER FIELDS.
PHONE_NUMBER = "Phone number"
PHONE_NUMBER_FIELD_LENGTH = 11
PHONE_NUMBER_FIELD_LENGTH_MAX = 11
PHONE_NUMBER_FIELD_LENGTH_MIN = 10

# PHONE_NUMBER VALIDATION MESSAGES.
PHONE_NUMBER_SIZE = 'Phone number must contain a maximum of 11 characters'
PHONE_NUMBER_SIZE = 'Phone number must be between 10 and 11 characters'
PHONE_NUMBER_FORMAT = 'Phone number must contain only numbers'

# SEX FIELDS.
Expand All @@ -108,10 +111,8 @@
# PASSWORD VALIDATION MESSAGES.
PASSWORD_SIZE = 'Password must be between 6 and 12 characters.'
PASSWORD_MATCH = 'Passwords do not match'

# PASSWORD VALIDATION MESSAGES
PASSWORD_SIZE = 'Password must be between 6 and 12 characteres.'
PASSWORD_MATCH = 'Passwords do not match'
PASSWORD_ERROR_ALNUM = 'Characteres must be alphanumeric'
PASSWORD_FORMAT = 'Password must contain only alphanumeric characteres'

# ID DOCUMENT FIELD.
ID_DOCUMENT = 'Id Document'
Expand All @@ -120,4 +121,5 @@
ID_DOCUMENT_MAX_LENGTH = 32

# ID DOCUMENT FIELD VALIDATION MESSAGES.
ID_DOCUMENT_SIZE = 'You id document must be between 10 and 32 characteres'
ID_DOCUMENT_SIZE = 'Your id document must be between 10 and 32 characteres'
ID_DOCUMENT_FORMAT = 'Id document must be only numbers'
200 changes: 131 additions & 69 deletions medical_prescription/user/forms.py

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion medical_prescription/user/models/healthprofessional.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@


class HealthProfessional(User):
crm = models.CharField(max_length=constants.CRM_LENGTH, unique=True)
class Meta:
unique_together = (('crm', 'crm_state'),)

crm = models.CharField(max_length=constants.CRM_LENGTH)
crm_state = models.CharField(choices=constants.UF_CHOICE, max_length=constants.CRM_STATE_LENGTH, default='DF')

objects = UserManager()
2 changes: 1 addition & 1 deletion medical_prescription/user/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class User(AbstractBaseUser, PermissionsMixin):
name = models.CharField(blank=False, max_length=constants.NAME_MAX_LENGHT, default="")
date_of_birth = models.DateField(blank=False, default=date.today)
phone = models.CharField(max_length=constants.PHONE_NUMBER_FIELD_LENGTH, blank=True, default='00000000000')
phone = models.CharField(max_length=constants.PHONE_NUMBER_FIELD_LENGTH_MAX, blank=True, default='00000000000')
email = models.EmailField(unique=True)
sex = models.CharField(choices=constants.SEX_CHOICE, max_length=10, default=constants.SEX_M)

Expand Down
10 changes: 1 addition & 9 deletions medical_prescription/user/templates/register_patient.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ <h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">RG</h4>

</div>

<div class="col-sm-3">
{% for error in form.id_document_state.errors %}
<div class="alert alert-danger" role="alert">{{error}}</div>
{% endfor %}

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Estado</h4>
{{ form.id_document_state }}
</div>
</div>

<div class="g-text-center--xs">
Expand All @@ -109,4 +101,4 @@ <h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Estado</h4>
</div>
<!-- End Form -->

{% endblock %}
{% endblock %}
39 changes: 39 additions & 0 deletions medical_prescription/user/test/test_confirm_password_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.test import TestCase

from user.models import User
from django.test.client import RequestFactory, Client
from user.views import ConfirmPasswordView


class TestConfirmPasswordView(TestCase):

def setUp(self):

# Creating user in database.
self.user = User()
self.user.email = "[email protected]"
self.user.password = "teste"
self.user.save()

self.factory = RequestFactory()
self.my_view = ConfirmPasswordView()
self.client = Client()

# Testind method 'get'.
def test_get(self):
request = self.factory.get('user/reset_confirm/')
response = self.my_view.get(request)

self.assertEqual(response.status_code, 200)

# Testing method 'post'.
def test_post(self):
response = self.client.post('/user/reset_confirm/', {'password_confirmation': 'teste', 'password': 'teste404'})

self.assertEqual(response.status_code, 404)

# Testing method 'post'.
def test_post_(self):
response = self.client.post('/user/reset_confirm/', {'password_confirmation': 'teste', 'password': 'teste'})

self.assertEqual(response.status_code, 404)
Loading

0 comments on commit 0f1d98e

Please sign in to comment.