This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Todd Dembrey
committed
Feb 8, 2018
1 parent
924930d
commit fee558b
Showing
2 changed files
with
43 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from .fields import AddressField | ||
|
||
|
||
class TestRequiredFields(TestCase): | ||
def build_validation_data(self, fields=list(), required=list()): | ||
fields = set(fields + required) | ||
return {'COUNTRY': { | ||
'fields': [{field: {'label': field}} for field in fields], | ||
'required': required, | ||
}} | ||
|
||
def test_non_required(self): | ||
field = AddressField() | ||
field.data = self.build_validation_data(fields=['postalcode']) | ||
field.clean({'country': 'COUNTRY'}) | ||
|
||
def test_non_required_blank_data(self): | ||
field = AddressField() | ||
field.data = self.build_validation_data(fields=['postalcode']) | ||
field.clean({'country': 'COUNTRY', 'postalcode': ''}) | ||
|
||
def test_one_field_required(self): | ||
field = AddressField() | ||
field.data = self.build_validation_data(required=['postalcode']) | ||
with self.assertRaises(ValidationError): | ||
field.clean({'country': 'COUNTRY'}) | ||
|
||
def test_one_field_required_blank_data(self): | ||
field = AddressField() | ||
field.data = self.build_validation_data(required=['postalcode']) | ||
with self.assertRaises(ValidationError): | ||
field.clean({'country': 'COUNTRY', 'postalcode': ''}) | ||
|
||
def test_one_field_required_supplied_data(self): | ||
field = AddressField() | ||
field.data = self.build_validation_data(required=['postalcode']) | ||
field.clean({'country': 'COUNTRY', 'postalcode': 'BS1 2AB'}) |