Skip to content
Snippets Groups Projects
Commit b74e186e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '148-validation-of-nd-number' into 'master'

validation of nd number added

Closes #148

See merge request NCER-PD/scheduling-system!93
parents fd76692e 15756ed9
No related branches found
No related tags found
1 merge request!93validation of nd number added
Checking pipeline status
# coding=utf-8
from django.core.validators import RegexValidator
from django.db import models
from constants import BOOL_CHOICES, SEX_CHOICES, SUBJECT_TYPE_CHOICES, COUNTRY_OTHER_ID
......@@ -124,7 +125,9 @@ class Subject(models.Model):
)
nd_number = models.CharField(max_length=25,
blank=True,
verbose_name='ND number'
verbose_name='ND number',
validators=[
RegexValidator('^(ND[0-9]{4}|)$', message="ND number should look as follows: NDxxxx")]
)
mpower_id = models.CharField(max_length=20,
blank=True,
......
......@@ -40,7 +40,7 @@ class SubjectAddFormTests(LoggedInWithWorkerTestCase):
def test_invalid_2(self):
form_data = self.sample_data
form_data['nd_number'] = "123"
form_data['nd_number'] = "ND0123"
form = SubjectAddForm(data=form_data, user=self.user)
form.is_valid()
......
......@@ -17,7 +17,7 @@ class SubjectEditFormTests(LoggedInWithWorkerTestCase):
'default_location': location.id,
'country': COUNTRY_AFGHANISTAN_ID,
'screening_number': '123',
'nd_number': 'nd_123'
'nd_number': 'ND0123'
}
def tearDown(self):
......@@ -36,13 +36,13 @@ class SubjectEditFormTests(LoggedInWithWorkerTestCase):
add_form = SubjectAddForm(data=self.sample_data, user=self.user)
add_form.save()
self.sample_data['nd_number'] = "nd_124"
self.sample_data['nd_number'] = "ND0124"
self.sample_data['screening_number'] = "124"
add_form = SubjectAddForm(data=self.sample_data, user=self.user)
subject = add_form.save()
self.sample_data['id'] = subject.id
self.sample_data['nd_number'] = "nd_123"
self.sample_data['nd_number'] = "ND0123"
edit_form = SubjectEditForm(self.sample_data)
save_status = edit_form.is_valid()
......@@ -54,14 +54,14 @@ class SubjectEditFormTests(LoggedInWithWorkerTestCase):
subject = add_form.save()
self.sample_data['mpower_id'] = "mpower_002"
self.sample_data['nd_number'] = "nd_002"
self.sample_data['nd_number'] = "ND0002"
self.sample_data['screening_number'] = "002"
add_form = SubjectAddForm(data=self.sample_data, user=self.user)
add_form.save()
self.sample_data['id'] = subject.id
self.sample_data['mpower_id'] = "mpower_002"
self.sample_data['nd_number'] = "nd_001"
self.sample_data['nd_number'] = "ND0001"
self.sample_data['screening_number'] = "001"
edit_form = SubjectEditForm(self.sample_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment