-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_outcalls.py
More file actions
230 lines (175 loc) · 7.89 KB
/
test_outcalls.py
File metadata and controls
230 lines (175 loc) · 7.89 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later
from hamcrest import (
all_of,
assert_that,
empty,
has_entries,
has_entry,
has_item,
has_items,
is_not,
not_,
)
from . import confd
from ..helpers import errors as e, fixtures, scenarios as s
from ..helpers.config import MAIN_TENANT, SUB_TENANT
def test_get_errors():
fake_outcall = confd.outcalls(999999).get
yield s.check_resource_not_found, fake_outcall, 'Outcall'
def test_delete_errors():
fake_outcall = confd.outcalls(999999).delete
yield s.check_resource_not_found, fake_outcall, 'Outcall'
def test_post_errors():
url = confd.outcalls.post
for check in error_checks(url):
yield check
@fixtures.outcall()
def test_put_errors(outcall):
url = confd.outcalls(outcall['id']).put
for check in error_checks(url):
yield check
def error_checks(url):
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', 123
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', s.random_string(
40
)
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', []
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', {}
yield s.check_bogus_field_returns_error, url, 'label', 123
yield s.check_bogus_field_returns_error, url, 'label', None
yield s.check_bogus_field_returns_error, url, 'label', True
yield s.check_bogus_field_returns_error, url, 'label', {}
yield s.check_bogus_field_returns_error, url, 'label', []
yield s.check_bogus_field_returns_error, url, 'internal_caller_id', 1234
yield s.check_bogus_field_returns_error, url, 'internal_caller_id', 'invalid'
yield s.check_bogus_field_returns_error, url, 'internal_caller_id', None
yield s.check_bogus_field_returns_error, url, 'internal_caller_id', []
yield s.check_bogus_field_returns_error, url, 'internal_caller_id', {}
yield s.check_bogus_field_returns_error, url, 'ring_time', 'invalid'
yield s.check_bogus_field_returns_error, url, 'ring_time', []
yield s.check_bogus_field_returns_error, url, 'ring_time', {}
yield s.check_bogus_field_returns_error, url, 'description', 1234
yield s.check_bogus_field_returns_error, url, 'description', []
yield s.check_bogus_field_returns_error, url, 'description', {}
yield s.check_bogus_field_returns_error, url, 'enabled', 'invalid'
yield s.check_bogus_field_returns_error, url, 'enabled', None
yield s.check_bogus_field_returns_error, url, 'enabled', []
yield s.check_bogus_field_returns_error, url, 'enabled', {}
@fixtures.outcall(label='search', description='search')
@fixtures.outcall(description='hidden')
def test_search(outcall, hidden):
url = confd.outcalls
searches = {'label': 'search', 'description': 'search'}
for field, term in searches.items():
yield check_search, url, outcall, hidden, field, term
def check_search(url, outcall, hidden, field, term):
response = url.get(search=term)
assert_that(response.items, has_item(has_entry(field, outcall[field])))
assert_that(response.items, is_not(has_item(has_entry(field, hidden[field]))))
response = url.get(**{field: outcall[field]})
assert_that(response.items, has_item(has_entry('id', outcall['id'])))
assert_that(response.items, is_not(has_item(has_entry('id', hidden['id']))))
@fixtures.outcall(wazo_tenant=MAIN_TENANT)
@fixtures.outcall(wazo_tenant=SUB_TENANT)
def test_list_multi_tenant(main, sub):
response = confd.outcalls.get(wazo_tenant=MAIN_TENANT)
assert_that(response.items, all_of(has_item(main)), not_(has_item(sub)))
response = confd.outcalls.get(wazo_tenant=SUB_TENANT)
assert_that(response.items, all_of(has_item(sub), not_(has_item(main))))
response = confd.outcalls.get(wazo_tenant=MAIN_TENANT, recurse=True)
assert_that(response.items, has_items(main, sub))
@fixtures.outcall(description='sort1')
@fixtures.outcall(description='sort2')
def test_sorting_offset_limit(outcall1, outcall2):
url = confd.outcalls.get
yield s.check_sorting, url, outcall1, outcall2, 'description', 'sort'
yield s.check_offset, url, outcall1, outcall2, 'description', 'sort'
yield s.check_limit, url, outcall1, outcall2, 'description', 'sort'
@fixtures.outcall()
def test_get(outcall):
response = confd.outcalls(outcall['id']).get()
assert_that(
response.item,
has_entries(
id=outcall['id'],
tenant_uuid=MAIN_TENANT,
preprocess_subroutine=outcall['preprocess_subroutine'],
description=outcall['description'],
internal_caller_id=outcall['internal_caller_id'],
name=outcall['name'],
label=outcall['label'],
ring_time=outcall['ring_time'],
trunks=empty(),
),
)
@fixtures.outcall(wazo_tenant=MAIN_TENANT)
@fixtures.outcall(wazo_tenant=SUB_TENANT)
def test_get_multi_tenant(main, sub):
response = confd.outcalls(main['id']).get(wazo_tenant=SUB_TENANT)
response.assert_match(404, e.not_found(resource='Outcall'))
response = confd.outcalls(sub['id']).get(wazo_tenant=MAIN_TENANT)
assert_that(response.item, has_entries(**sub))
def test_create_minimal_parameters():
response = confd.outcalls.post(name='MyOutcall')
response.assert_created('outcalls')
assert_that(response.item, has_entries(id=not_(empty()), tenant_uuid=MAIN_TENANT))
confd.outcalls(response.item['id']).delete().assert_deleted()
def test_create_all_parameters():
parameters = {
'label': 'My Outcall',
'internal_caller_id': True,
'preprocess_subroutine': 'subroutine',
'ring_time': 10,
'description': 'outcall description',
'enabled': False,
}
response = confd.outcalls.post(**parameters)
response.assert_created('outcalls')
assert_that(response.item, has_entries(tenant_uuid=MAIN_TENANT, **parameters))
confd.outcalls(response.item['id']).delete().assert_deleted()
@fixtures.outcall()
def test_edit_minimal_parameters(outcall):
response = confd.outcalls(outcall['id']).put()
response.assert_updated()
@fixtures.outcall()
def test_edit_all_parameters(outcall):
parameters = {
'label': 'MyOutcall',
'internal_caller_id': True,
'preprocess_subroutine': 'subroutine',
'ring_time': 10,
'description': 'outcall description',
'enabled': False,
}
response = confd.outcalls(outcall['id']).put(**parameters)
response.assert_updated()
response = confd.outcalls(outcall['id']).get()
assert_that(response.item, has_entries(parameters))
@fixtures.outcall(wazo_tenant=MAIN_TENANT)
@fixtures.outcall(wazo_tenant=SUB_TENANT)
def test_edit_multi_tenant(main, sub):
response = confd.outcalls(main['id']).put(wazo_tenant=SUB_TENANT)
response.assert_match(404, e.not_found(resource='Outcall'))
response = confd.outcalls(sub['id']).put(wazo_tenant=MAIN_TENANT)
response.assert_updated()
@fixtures.outcall()
def test_delete(outcall):
response = confd.outcalls(outcall['id']).delete()
response.assert_deleted()
response = confd.outcalls(outcall['id']).get()
response.assert_match(404, e.not_found(resource='Outcall'))
@fixtures.outcall(wazo_tenant=MAIN_TENANT)
@fixtures.outcall(wazo_tenant=SUB_TENANT)
def test_delete_multi_tenant(main, sub):
response = confd.outcalls(main['id']).delete(wazo_tenant=SUB_TENANT)
response.assert_match(404, e.not_found(resource='Outcall'))
response = confd.outcalls(sub['id']).delete(wazo_tenant=MAIN_TENANT)
response.assert_deleted()
@fixtures.outcall()
def test_bus_events(outcall):
url = confd.outcalls(outcall['id'])
headers = {'tenant_uuid': outcall['tenant_uuid']}
yield s.check_event, 'outcall_created', headers, confd.outcalls.post, {'name': 'a'}
yield s.check_event, 'outcall_edited', headers, url.put
yield s.check_event, 'outcall_deleted', headers, url.delete