-
Notifications
You must be signed in to change notification settings - Fork 29
/
tests.py
68 lines (46 loc) · 2.45 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from django.core.exceptions import ValidationError
from core.client_configs.models import ClientConfig
from core.common.tests import OCLTestCase
from core.orgs.tests.factories import OrganizationFactory
class ClientConfigTest(OCLTestCase):
def test_is_home(self):
self.assertTrue(ClientConfig().is_home)
self.assertTrue(ClientConfig(type='home').is_home)
self.assertFalse(ClientConfig(type='blah').is_home)
def test_home_config_validation(self):
client_config = ClientConfig(config=dict())
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(
ex.exception.message_dict,
dict(
config=['This field cannot be blank.'],
resource_type=['This field cannot be null.'],
resource_id=['This field cannot be null.'],
tabs=['At least one tab config is mandatory.'],
)
)
org = OrganizationFactory()
client_config.resource = org
client_config.config = dict(foo='bar')
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(ex.exception.message_dict, dict(tabs=['At least one tab config is mandatory.']))
client_config.config = dict(tabs='foobar')
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(ex.exception.message_dict, dict(tabs=['Tabs config must be a list.']))
client_config.config = dict(tabs=['foobar'])
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(ex.exception.message_dict, dict(tabs=['Invalid Tabs config.']))
client_config.config = dict(tabs=[dict(foo='bar')])
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(ex.exception.message_dict, dict(tabs=['Exactly one of the Tabs must be default.']))
client_config.config = dict(tabs=[dict(foo='bar', default=True), dict(foo='bar', default=True)])
with self.assertRaises(ValidationError) as ex:
client_config.full_clean()
self.assertEqual(ex.exception.message_dict, dict(tabs=['Exactly one of the Tabs must be default.']))
client_config.config = dict(tabs=[dict(foo='bar', default=True), dict(foo='bar', default=False)])
client_config.full_clean()