-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from bobslee/validation-required-simple
Implementation of "simple" validation required.
- Loading branch information
Showing
7 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"firstName": "", | ||
"email": "[email protected]", | ||
"birthdate": "", | ||
"appointmentDateTime": "", | ||
"lastName": "", | ||
"phoneNumber": "", | ||
"cardinalDirection": "", | ||
"favouriteSeason": "", | ||
"favouriteFood": [], | ||
"monthDayYear": "00/00/0000", | ||
"monthYear": "00/00/0000", | ||
"dayMonthYear": "00/00/0000", | ||
"dayMonth": "00/00/0000", | ||
"day": "00/00/0000", | ||
"month": "00/00/0000", | ||
"year": "00/00/0000", | ||
"survey": null, | ||
"signature": "", | ||
"dataGrid": [ | ||
{ | ||
"textField": "", | ||
"checkbox": false | ||
}, | ||
{ | ||
"textField": "Some #1 text here", | ||
"checkbox": false | ||
}, | ||
{ | ||
"textField": "", | ||
"checkbox": false | ||
}, | ||
{ | ||
"textField": "Some #2 text here", | ||
"checkbox": false | ||
} | ||
], | ||
"uploadBase64": [], | ||
"uploadUrl": [], | ||
"submit": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright Nova Code (http://www.novacode.nl) | ||
# See LICENSE file for full licensing details. | ||
|
||
from tests.utils import readfile | ||
from test_component import ComponentTestCase | ||
|
||
from formiodata.form import Form | ||
|
||
|
||
class ValidationErrorSimpleTestCase(ComponentTestCase): | ||
|
||
def setUp(self): | ||
super(ValidationErrorSimpleTestCase, self).setUp() | ||
self.form_validation_errors_json = readfile('data', 'test_example_form_validation_errors.json') | ||
self.form_validation_errors = Form(self.form_validation_errors_json, self.builder) | ||
self.form_validation_errors_i18n_nl = Form(self.form_validation_errors_json, self.builder_i18n_nl) | ||
|
||
def test_required_components_in_builder(self): | ||
firstName = self.builder.input_components['firstName'] | ||
self.assertTrue(firstName.required) | ||
|
||
lastName = self.builder.input_components['lastName'] | ||
self.assertTrue(lastName.required) | ||
|
||
email = self.builder.input_components['email'] | ||
self.assertFalse(email.required) | ||
|
||
def test_required_components_form_validation_errors(self): | ||
errors = self.form_validation_errors.validation_errors() | ||
|
||
self.assertEqual( | ||
errors['firstName']['required'], | ||
'First Name is required' | ||
) | ||
self.assertEqual( | ||
errors['lastName']['required'], | ||
'Last Name is required' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][0]['textField']['required'], | ||
'Text Field is required' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][1], | ||
{} | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][2]['textField']['required'], | ||
'Text Field is required' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][3], | ||
{} | ||
) | ||
|
||
def test_required_components_form_validation_errors_i18n_nl(self): | ||
errors = self.form_validation_errors_i18n_nl.validation_errors() | ||
|
||
self.assertEqual( | ||
errors['firstName']['required'], | ||
'Voornaam is verplicht' | ||
) | ||
self.assertEqual( | ||
errors['lastName']['required'], | ||
'Achternaam is verplicht' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][0]['textField']['required'], | ||
'Tekstveld is verplicht' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][1], | ||
{} | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][2]['textField']['required'], | ||
'Tekstveld is verplicht' | ||
) | ||
self.assertEqual( | ||
errors['dataGrid'][3], | ||
{} | ||
) | ||
|
||
def test_not_required_components_form(self): | ||
errors = self.form_validation_errors_i18n_nl.validation_errors() | ||
self.assertNotIn('email', errors) |