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
/
Copy pathtests.py
40 lines (32 loc) · 1.5 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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'})