|
1
|
|
|
import unittest |
|
2
|
|
|
from django.core.urlresolvers import reverse |
|
3
|
|
|
from django.test import Client |
|
4
|
|
|
from .models import Acc, AccCdr, MissedCall |
|
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_acc(**kwargs): |
|
32
|
|
|
defaults = {} |
|
33
|
|
|
defaults["method"] = "method" |
|
34
|
|
|
defaults["from_tag"] = "from_tag" |
|
35
|
|
|
defaults["to_tag"] = "to_tag" |
|
36
|
|
|
defaults["callid"] = "callid" |
|
37
|
|
|
defaults["sip_code"] = "sip_code" |
|
38
|
|
|
defaults["sip_reason"] = "sip_reason" |
|
39
|
|
|
defaults["time"] = "time" |
|
40
|
|
|
defaults["time_attr"] = "time_attr" |
|
41
|
|
|
defaults["time_exten"] = "time_exten" |
|
42
|
|
|
defaults.update(**kwargs) |
|
43
|
|
|
return Acc.objects.create(**defaults) |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def create_acccdr(**kwargs): |
|
47
|
|
|
defaults = {} |
|
48
|
|
|
defaults["start_time"] = "start_time" |
|
49
|
|
|
defaults["end_time"] = "end_time" |
|
50
|
|
|
defaults["duration"] = "duration" |
|
51
|
|
|
defaults.update(**kwargs) |
|
52
|
|
|
return AccCdr.objects.create(**defaults) |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
def create_missedcall(**kwargs): |
|
56
|
|
|
defaults = {} |
|
57
|
|
|
defaults["method"] = "method" |
|
58
|
|
|
defaults["from_tag"] = "from_tag" |
|
59
|
|
|
defaults["to_tag"] = "to_tag" |
|
60
|
|
|
defaults["callid"] = "callid" |
|
61
|
|
|
defaults["sip_code"] = "sip_code" |
|
62
|
|
|
defaults["sip_reason"] = "sip_reason" |
|
63
|
|
|
defaults["time"] = "time" |
|
64
|
|
|
defaults.update(**kwargs) |
|
65
|
|
|
return MissedCall.objects.create(**defaults) |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
class AccViewTest(unittest.TestCase): |
|
|
|
|
|
|
69
|
|
|
''' |
|
70
|
|
|
Tests for Acc |
|
71
|
|
|
''' |
|
72
|
|
|
def setUp(self): |
|
73
|
|
|
self.client = Client() |
|
74
|
|
|
|
|
75
|
|
|
def test_list_acc(self): |
|
76
|
|
|
url = reverse('accounting_acc_list') |
|
77
|
|
|
response = self.client.get(url) |
|
78
|
|
|
self.assertEqual(response.status_code, 200) |
|
79
|
|
|
|
|
80
|
|
|
def test_create_acc(self): |
|
81
|
|
|
url = reverse('accounting_acc_create') |
|
82
|
|
|
data = { |
|
83
|
|
|
"method": "method", |
|
84
|
|
|
"from_tag": "from_tag", |
|
85
|
|
|
"to_tag": "to_tag", |
|
86
|
|
|
"callid": "callid", |
|
87
|
|
|
"sip_code": "sip_code", |
|
88
|
|
|
"sip_reason": "sip_reason", |
|
89
|
|
|
"time": "time", |
|
90
|
|
|
"time_attr": "time_attr", |
|
91
|
|
|
"time_exten": "time_exten", |
|
92
|
|
|
} |
|
93
|
|
|
response = self.client.post(url, data=data) |
|
94
|
|
|
self.assertEqual(response.status_code, 302) |
|
95
|
|
|
|
|
96
|
|
|
def test_detail_acc(self): |
|
97
|
|
|
acc = create_acc() |
|
98
|
|
|
url = reverse('accounting_acc_detail', args=[acc.pk,]) |
|
99
|
|
|
response = self.client.get(url) |
|
100
|
|
|
self.assertEqual(response.status_code, 200) |
|
101
|
|
|
|
|
102
|
|
|
def test_update_acc(self): |
|
103
|
|
|
acc = create_acc() |
|
104
|
|
|
data = { |
|
105
|
|
|
"method": "method", |
|
106
|
|
|
"from_tag": "from_tag", |
|
107
|
|
|
"to_tag": "to_tag", |
|
108
|
|
|
"callid": "callid", |
|
109
|
|
|
"sip_code": "sip_code", |
|
110
|
|
|
"sip_reason": "sip_reason", |
|
111
|
|
|
"time": "time", |
|
112
|
|
|
"time_attr": "time_attr", |
|
113
|
|
|
"time_exten": "time_exten", |
|
114
|
|
|
} |
|
115
|
|
|
url = reverse('accounting_acc_update', args=[acc.pk,]) |
|
116
|
|
|
response = self.client.post(url, data) |
|
117
|
|
|
self.assertEqual(response.status_code, 302) |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
View Code Duplication |
class AccCdrViewTest(unittest.TestCase): |
|
|
|
|
|
|
121
|
|
|
''' |
|
122
|
|
|
Tests for AccCdr |
|
123
|
|
|
''' |
|
124
|
|
|
def setUp(self): |
|
125
|
|
|
self.client = Client() |
|
126
|
|
|
|
|
127
|
|
|
def test_list_acccdr(self): |
|
128
|
|
|
url = reverse('accounting_acccdr_list') |
|
129
|
|
|
response = self.client.get(url) |
|
130
|
|
|
self.assertEqual(response.status_code, 200) |
|
131
|
|
|
|
|
132
|
|
|
def test_create_acccdr(self): |
|
133
|
|
|
url = reverse('accounting_acccdr_create') |
|
134
|
|
|
data = { |
|
135
|
|
|
"start_time": "start_time", |
|
136
|
|
|
"end_time": "end_time", |
|
137
|
|
|
"duration": "duration", |
|
138
|
|
|
} |
|
139
|
|
|
response = self.client.post(url, data=data) |
|
140
|
|
|
self.assertEqual(response.status_code, 302) |
|
141
|
|
|
|
|
142
|
|
|
def test_detail_acccdr(self): |
|
143
|
|
|
acccdr = create_acccdr() |
|
144
|
|
|
url = reverse('accounting_acccdr_detail', args=[acccdr.pk,]) |
|
145
|
|
|
response = self.client.get(url) |
|
146
|
|
|
self.assertEqual(response.status_code, 200) |
|
147
|
|
|
|
|
148
|
|
|
def test_update_acccdr(self): |
|
149
|
|
|
acccdr = create_acccdr() |
|
150
|
|
|
data = { |
|
151
|
|
|
"start_time": "start_time", |
|
152
|
|
|
"end_time": "end_time", |
|
153
|
|
|
"duration": "duration", |
|
154
|
|
|
} |
|
155
|
|
|
url = reverse('accounting_acccdr_update', args=[acccdr.pk,]) |
|
156
|
|
|
response = self.client.post(url, data) |
|
157
|
|
|
self.assertEqual(response.status_code, 302) |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
class MissedCallViewTest(unittest.TestCase): |
|
|
|
|
|
|
161
|
|
|
''' |
|
162
|
|
|
Tests for MissedCall |
|
163
|
|
|
''' |
|
164
|
|
|
def setUp(self): |
|
165
|
|
|
self.client = Client() |
|
166
|
|
|
|
|
167
|
|
|
def test_list_missedcall(self): |
|
168
|
|
|
url = reverse('accounting_missedcall_list') |
|
169
|
|
|
response = self.client.get(url) |
|
170
|
|
|
self.assertEqual(response.status_code, 200) |
|
171
|
|
|
|
|
172
|
|
|
def test_create_missedcall(self): |
|
173
|
|
|
url = reverse('accounting_missedcall_create') |
|
174
|
|
|
data = { |
|
175
|
|
|
"method": "method", |
|
176
|
|
|
"from_tag": "from_tag", |
|
177
|
|
|
"to_tag": "to_tag", |
|
178
|
|
|
"callid": "callid", |
|
179
|
|
|
"sip_code": "sip_code", |
|
180
|
|
|
"sip_reason": "sip_reason", |
|
181
|
|
|
"time": "time", |
|
182
|
|
|
} |
|
183
|
|
|
response = self.client.post(url, data=data) |
|
184
|
|
|
self.assertEqual(response.status_code, 302) |
|
185
|
|
|
|
|
186
|
|
|
def test_detail_missedcall(self): |
|
187
|
|
|
missedcall = create_missedcall() |
|
188
|
|
|
url = reverse('accounting_missedcall_detail', args=[missedcall.pk,]) |
|
189
|
|
|
response = self.client.get(url) |
|
190
|
|
|
self.assertEqual(response.status_code, 200) |
|
191
|
|
|
|
|
192
|
|
|
def test_update_missedcall(self): |
|
193
|
|
|
missedcall = create_missedcall() |
|
194
|
|
|
data = { |
|
195
|
|
|
"method": "method", |
|
196
|
|
|
"from_tag": "from_tag", |
|
197
|
|
|
"to_tag": "to_tag", |
|
198
|
|
|
"callid": "callid", |
|
199
|
|
|
"sip_code": "sip_code", |
|
200
|
|
|
"sip_reason": "sip_reason", |
|
201
|
|
|
"time": "time", |
|
202
|
|
|
} |
|
203
|
|
|
url = reverse('accounting_missedcall_update', args=[missedcall.pk,]) |
|
204
|
|
|
response = self.client.post(url, data) |
|
205
|
|
|
self.assertEqual(response.status_code, 302) |
|
206
|
|
|
|