This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
/
test_models.py
132 lines (104 loc) · 5.47 KB
/
test_models.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
class BaseTestNas(object):
def test_string_representation(self):
nas = self.nas_model(name='entry nasname')
self.assertEqual(str(nas), nas.name)
class BaseTestRadiusAccounting(object):
def test_string_representation(self):
radiusaccounting = self.radius_accounting_model(unique_id='entry acctuniqueid')
self.assertEqual(str(radiusaccounting), radiusaccounting.unique_id)
class BaseTestRadiusCheck(object):
def test_string_representation(self):
radiuscheck = self.radius_check_model(username='entry username')
self.assertEqual(str(radiuscheck), radiuscheck.username)
class BaseTestRadiusReply(object):
def test_string_representation(self):
radiusreply = self.radius_reply_model(username='entry username')
self.assertEqual(str(radiusreply), radiusreply.username)
class BaseTestRadiusGroupReply(object):
def test_string_representation(self):
radiusgroupreply = self.radius_groupreply_model(groupname='entry groupname')
self.assertEqual(str(radiusgroupreply), radiusgroupreply.groupname)
class BaseTestRadiusGroupCheck(object):
def test_string_representation(self):
radiusgroupcheck = self.radius_groupcheck_model(groupname='entry groupname')
self.assertEqual(str(radiusgroupcheck), radiusgroupcheck.groupname)
class BaseTestRadiusUserGroup(object):
def test_string_representation(self):
radiususergroup = self.radius_usergroup_model(username='entry username')
self.assertEqual(str(radiususergroup), radiususergroup.username)
class BaseTestRadiusPostAuth(object):
def test_string_representation(self):
radiuspostauthentication = self.radius_postauth_model(username='entry username')
self.assertEqual(str(radiuspostauthentication), radiuspostauthentication.username)
class BaseTestRadiusGroup(object):
def test_string_representation(self):
radiusgroup = self.radius_group_model(groupname='entry groupname')
self.assertEqual(str(radiusgroup), radiusgroup.groupname)
class BaseTestRadiusBatch(object):
def test_string_representation(self):
radiusbatch = self.radius_batch_model(name='test')
self.assertEqual(str(radiusbatch), 'test')
def test_delete_method(self):
radiusbatch = self.radius_batch_model.objects.create(strategy='prefix',
prefix='test',
name='test')
radiusbatch.prefix_add('test', 5)
User = get_user_model()
self.assertEqual(User.objects.all().count(), 5)
radiusbatch.delete()
self.assertEqual(self.radius_batch_model.objects.all().count(), 0)
self.assertEqual(User.objects.all().count(), 0)
def test_clean_method(self):
radiusbatch = self.radius_batch_model.objects.create()
with self.assertRaises(ValidationError):
radiusbatch.full_clean()
radiusbatch = self.radius_batch_model(strategy='csv', prefix='test',
name='testing')
with self.assertRaises(ValidationError):
radiusbatch.full_clean()
class BaseTestRadiusProfile(object):
def test_string_representation(self):
radiusprofile = self.radius_profile_model(name='test')
self.assertEqual(str(radiusprofile), 'test')
def test_save_method(self):
RadiusProfile = self.radius_profile_model
radiusprofile = RadiusProfile(name='test',
default=True,
daily_session_limit=10)
radiusprofile.save()
self.assertEqual(RadiusProfile.objects.all().count(), 3)
self.assertEqual(RadiusProfile.objects.filter(default=True).count(), 1)
radiusprofile = RadiusProfile(name='test1',
default=True,
daily_session_limit=20)
radiusprofile.save()
self.assertEqual(RadiusProfile.objects.all().count(), 4)
self.assertEqual(RadiusProfile.objects.filter(default=True).count(), 1)
class BaseTestRadiusUserProfile(object):
def test_string_representation(self):
user = get_user_model().objects.create(username="test")
profile = self.radius_profile_model(name="test")
profile.save()
radiususerprofile = self.radius_userprofile_model(user=user,
profile=profile)
self.assertEqual(str(radiususerprofile), 'test-test')
def test_save_method(self):
RadiusProfile = self.radius_profile_model
RadiusCheck = self.radius_check_model
RadiusUserProfile = self.radius_userprofile_model
radiusprofile = RadiusProfile(name='test',
default=True,
daily_session_limit=10)
radiusprofile.save()
get_user_model().objects.create(username="test")
self.assertEqual(RadiusUserProfile.objects.all().count(), 1)
self.assertEqual(RadiusCheck.objects.all().count(), 1)
radiususerprofile = RadiusUserProfile.objects.first()
radiusprofile.daily_session_limit = 20
radiusprofile.daily_bandwidth_limit = 10
radiusprofile.save()
radiususerprofile.profile = radiusprofile
radiususerprofile.save()
self.assertEqual(RadiusCheck.objects.all().count(), 2)