15 |
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
17 |
17 |
import json
|
|
18 |
import re
|
18 |
19 |
|
19 |
20 |
import pytest
|
20 |
21 |
|
... | ... | |
224 |
225 |
users=user, callee='102').count() == 0
|
225 |
226 |
|
226 |
227 |
|
|
228 |
def test_phone_zone(user, client):
|
|
229 |
client.login(username='toto', password='toto')
|
|
230 |
response = client.get(reverse('phone-zone'))
|
|
231 |
assert response.status_code == 200
|
|
232 |
assert 'You do not have a phoneline configured' in response.content
|
|
233 |
|
|
234 |
models.PhoneLine.take(callee='102', user=user)
|
|
235 |
|
|
236 |
response = client.get(reverse('phone-zone'))
|
|
237 |
assert response.status_code == 200
|
|
238 |
assert 'You do not have a phoneline configured' not in response.content
|
|
239 |
assert '<li>102' in response.content
|
|
240 |
assert 'data-callee="102"' in response.content
|
|
241 |
currents = re.search('<div id="source-mainarea" '
|
|
242 |
'data-current-calls="/api/phone/current-calls/">'
|
|
243 |
'(.*?)</div>', response.content, flags=re.DOTALL)
|
|
244 |
assert currents.group(1).strip() == ''
|
|
245 |
|
|
246 |
# create a call
|
|
247 |
payload = {'event': 'start', 'caller': '003369999999', 'callee': '102'}
|
|
248 |
response = client.post(reverse('phone-call-event'), json.dumps(payload),
|
|
249 |
content_type='application/json')
|
|
250 |
assert response.status_code == 200
|
|
251 |
response = client.get(reverse('phone-zone'))
|
|
252 |
assert response.status_code == 200
|
|
253 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content
|
|
254 |
|
|
255 |
# simulate a mellon user
|
|
256 |
session = client.session
|
|
257 |
session['mellon_session'] = {'username': ['agent007']}
|
|
258 |
session.save()
|
|
259 |
response = client.get(reverse('phone-zone'))
|
|
260 |
assert response.status_code == 200
|
|
261 |
assert 'agent007' not in response.content
|
|
262 |
assert 'data-callee="agent007"' not in response.content
|
|
263 |
assert '<li>102' in response.content
|
|
264 |
assert 'data-callee="102"' in response.content
|
|
265 |
|
|
266 |
with override_settings(PHONE_AUTOTAKE_MELLON_USERNAME=True):
|
|
267 |
response = client.get(reverse('phone-zone'))
|
|
268 |
assert response.status_code == 200
|
|
269 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content
|
|
270 |
assert 'agent007' in response.content
|
|
271 |
assert 'data-callee="agent007"' in response.content
|
|
272 |
assert '<li>102' in response.content
|
|
273 |
assert 'data-callee="102"' in response.content
|
|
274 |
|
|
275 |
|
227 |
276 |
def test_call_expiration(user, client):
|
228 |
277 |
assert models.PhoneCall.objects.count() == 0
|
229 |
278 |
# create a call
|