-
Notifications
You must be signed in to change notification settings - Fork 31
/
tests.py
92 lines (63 loc) · 3.32 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 tearDown(self):
ClientConfig.objects.all().delete()
super().tearDown()
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()
def test_uri(self):
self.assertEqual(ClientConfig(id=1).uri, '/client-configs/1/')
self.assertEqual(ClientConfig(id=400).uri, '/client-configs/400/')
def test_siblings(self):
org = OrganizationFactory()
config1 = ClientConfig(name='first', resource=org, config=dict(tabs=[dict(foo='bar', default=True)]))
config1.save()
self.assertEqual(config1.siblings.count(), 0)
config2 = ClientConfig(name='second', resource=org, config=dict(tabs=[dict(foo='bar', default=True)]))
config2.save()
self.assertEqual(config1.siblings.count(), 1)
self.assertEqual(config1.siblings.first().id, config2.id)
self.assertEqual(config2.siblings.count(), 1)
self.assertEqual(config2.siblings.first().id, config1.id)