1
|
|
|
import unittest |
2
|
|
|
from django.core.urlresolvers import reverse |
3
|
|
|
from django.test import Client |
4
|
|
|
from .models import UacReg, Trusted |
5
|
|
|
from django.contrib.auth.models import User |
6
|
|
|
from django.contrib.auth.models import Group |
7
|
|
|
from django.contrib.contenttypes.models import ContentType |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def create_django_contrib_auth_models_user(**kwargs): |
11
|
|
|
defaults = {} |
12
|
|
|
defaults["username"] = "username" |
13
|
|
|
defaults["email"] = "[email protected]" |
14
|
|
|
defaults.update(**kwargs) |
15
|
|
|
return User.objects.create(**defaults) |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
def create_django_contrib_auth_models_group(**kwargs): |
19
|
|
|
defaults = {} |
20
|
|
|
defaults["name"] = "group" |
21
|
|
|
defaults.update(**kwargs) |
22
|
|
|
return Group.objects.create(**defaults) |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def create_django_contrib_contenttypes_models_contenttype(**kwargs): |
26
|
|
|
defaults = {} |
27
|
|
|
defaults.update(**kwargs) |
28
|
|
|
return ContentType.objects.create(**defaults) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def create_uacreg(**kwargs): |
32
|
|
|
defaults = {} |
33
|
|
|
defaults["l_uuid"] = "l_uuid" |
34
|
|
|
defaults["l_username"] = "l_username" |
35
|
|
|
defaults["l_domain"] = "l_domain" |
36
|
|
|
defaults["r_username"] = "r_username" |
37
|
|
|
defaults["r_domain"] = "r_domain" |
38
|
|
|
defaults["realm"] = "realm" |
39
|
|
|
defaults["auth_username"] = "auth_username" |
40
|
|
|
defaults["auth_password"] = "auth_password" |
41
|
|
|
defaults["auth_ha1"] = "auth_ha1" |
42
|
|
|
defaults["auth_proxy"] = "auth_proxy" |
43
|
|
|
defaults["expires"] = "expires" |
44
|
|
|
defaults["flags"] = "flags" |
45
|
|
|
defaults["reg_delay"] = "reg_delay" |
46
|
|
|
defaults.update(**kwargs) |
47
|
|
|
return UacReg.objects.create(**defaults) |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def create_trusted(**kwargs): |
51
|
|
|
defaults = {} |
52
|
|
|
defaults["src_ip"] = "src_ip" |
53
|
|
|
defaults["proto"] = "proto" |
54
|
|
|
defaults["from_pattern"] = "from_pattern" |
55
|
|
|
defaults["ruri_pattern"] = "ruri_pattern" |
56
|
|
|
defaults["tag"] = "tag" |
57
|
|
|
defaults["priority"] = "priority" |
58
|
|
|
defaults.update(**kwargs) |
59
|
|
|
return Trusted.objects.create(**defaults) |
60
|
|
|
|
61
|
|
|
|
62
|
|
View Code Duplication |
class UacRegViewTest(unittest.TestCase): |
|
|
|
|
63
|
|
|
''' |
64
|
|
|
Tests for UacReg |
65
|
|
|
''' |
66
|
|
|
def setUp(self): |
67
|
|
|
self.client = Client() |
68
|
|
|
|
69
|
|
|
def test_list_uacreg(self): |
70
|
|
|
url = reverse('endpoint_uacreg_list') |
71
|
|
|
response = self.client.get(url) |
72
|
|
|
self.assertEqual(response.status_code, 200) |
73
|
|
|
|
74
|
|
|
def test_create_uacreg(self): |
75
|
|
|
url = reverse('endpoint_uacreg_create') |
76
|
|
|
data = { |
77
|
|
|
"l_uuid": "l_uuid", |
78
|
|
|
"l_username": "l_username", |
79
|
|
|
"l_domain": "l_domain", |
80
|
|
|
"r_username": "r_username", |
81
|
|
|
"r_domain": "r_domain", |
82
|
|
|
"realm": "realm", |
83
|
|
|
"auth_username": "auth_username", |
84
|
|
|
"auth_password": "auth_password", |
85
|
|
|
"auth_ha1": "auth_ha1", |
86
|
|
|
"auth_proxy": "auth_proxy", |
87
|
|
|
"expires": "expires", |
88
|
|
|
"flags": "flags", |
89
|
|
|
"reg_delay": "reg_delay", |
90
|
|
|
} |
91
|
|
|
response = self.client.post(url, data=data) |
92
|
|
|
self.assertEqual(response.status_code, 302) |
93
|
|
|
|
94
|
|
|
def test_detail_uacreg(self): |
95
|
|
|
uacreg = create_uacreg() |
96
|
|
|
url = reverse('endpoint_uacreg_detail', args=[uacreg.pk,]) |
97
|
|
|
response = self.client.get(url) |
98
|
|
|
self.assertEqual(response.status_code, 200) |
99
|
|
|
|
100
|
|
|
def test_update_uacreg(self): |
101
|
|
|
uacreg = create_uacreg() |
102
|
|
|
data = { |
103
|
|
|
"l_uuid": "l_uuid", |
104
|
|
|
"l_username": "l_username", |
105
|
|
|
"l_domain": "l_domain", |
106
|
|
|
"r_username": "r_username", |
107
|
|
|
"r_domain": "r_domain", |
108
|
|
|
"realm": "realm", |
109
|
|
|
"auth_username": "auth_username", |
110
|
|
|
"auth_password": "auth_password", |
111
|
|
|
"auth_ha1": "auth_ha1", |
112
|
|
|
"auth_proxy": "auth_proxy", |
113
|
|
|
"expires": "expires", |
114
|
|
|
"flags": "flags", |
115
|
|
|
"reg_delay": "reg_delay", |
116
|
|
|
} |
117
|
|
|
url = reverse('endpoint_uacreg_update', args=[uacreg.pk,]) |
118
|
|
|
response = self.client.post(url, data) |
119
|
|
|
self.assertEqual(response.status_code, 302) |
120
|
|
|
|
121
|
|
|
|
122
|
|
View Code Duplication |
class TrustedViewTest(unittest.TestCase): |
|
|
|
|
123
|
|
|
''' |
124
|
|
|
Tests for Trusted |
125
|
|
|
''' |
126
|
|
|
def setUp(self): |
127
|
|
|
self.client = Client() |
128
|
|
|
|
129
|
|
|
def test_list_trusted(self): |
130
|
|
|
url = reverse('endpoint_trusted_list') |
131
|
|
|
response = self.client.get(url) |
132
|
|
|
self.assertEqual(response.status_code, 200) |
133
|
|
|
|
134
|
|
|
def test_create_trusted(self): |
135
|
|
|
url = reverse('endpoint_trusted_create') |
136
|
|
|
data = { |
137
|
|
|
"src_ip": "src_ip", |
138
|
|
|
"proto": "proto", |
139
|
|
|
"from_pattern": "from_pattern", |
140
|
|
|
"ruri_pattern": "ruri_pattern", |
141
|
|
|
"tag": "tag", |
142
|
|
|
"priority": "priority", |
143
|
|
|
} |
144
|
|
|
response = self.client.post(url, data=data) |
145
|
|
|
self.assertEqual(response.status_code, 302) |
146
|
|
|
|
147
|
|
|
def test_detail_trusted(self): |
148
|
|
|
trusted = create_trusted() |
149
|
|
|
url = reverse('endpoint_trusted_detail', args=[trusted.pk,]) |
150
|
|
|
response = self.client.get(url) |
151
|
|
|
self.assertEqual(response.status_code, 200) |
152
|
|
|
|
153
|
|
|
def test_update_trusted(self): |
154
|
|
|
trusted = create_trusted() |
155
|
|
|
data = { |
156
|
|
|
"src_ip": "src_ip", |
157
|
|
|
"proto": "proto", |
158
|
|
|
"from_pattern": "from_pattern", |
159
|
|
|
"ruri_pattern": "ruri_pattern", |
160
|
|
|
"tag": "tag", |
161
|
|
|
"priority": "priority", |
162
|
|
|
} |
163
|
|
|
url = reverse('endpoint_trusted_update', args=[trusted.pk,]) |
164
|
|
|
response = self.client.post(url, data) |
165
|
|
|
self.assertEqual(response.status_code, 302) |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|