0001-phone-don-t-use-SSO-username-as-a-line-by-default-16.patch
tests/test_source_phone.py | ||
---|---|---|
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 |
currents = re.search('<div id="source-mainarea" ' |
|
241 |
'data-current-calls="/api/phone/current-calls/">' |
|
242 |
'(.*?)</div>', response.content, flags=re.DOTALL) |
|
243 |
assert currents.group(1).strip() == '' |
|
244 | ||
245 |
# create a call |
|
246 |
payload = {'event': 'start', 'caller': '003369999999', 'callee': '102'} |
|
247 |
response = client.post(reverse('phone-call-event'), json.dumps(payload), |
|
248 |
content_type='application/json') |
|
249 |
assert response.status_code == 200 |
|
250 |
response = client.get(reverse('phone-zone')) |
|
251 |
assert response.status_code == 200 |
|
252 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content |
|
253 | ||
254 |
with override_settings(PHONE_AUTOTAKE_MELLON_USERNAME=True): |
|
255 |
response = client.get(reverse('phone-zone')) |
|
256 |
assert response.status_code == 200 |
|
257 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content |
|
258 | ||
227 | 259 |
def test_call_expiration(user, client): |
228 | 260 |
assert models.PhoneCall.objects.count() == 0 |
229 | 261 |
# create a call |
welco/settings.py | ||
---|---|---|
201 | 201 |
# phone system |
202 | 202 |
ONE_CALL_PER_CALLEE = True |
203 | 203 |
MAX_CALL_DURATION = 0 # in minutes, 0 stands for infinity |
204 |
# If user is from SSO (ie django-mellon session), consider username |
|
205 |
# as a phone line number and take it automatically. |
|
206 |
PHONE_AUTOTAKE_MELLON_USERNAME = False |
|
204 | 207 | |
205 | 208 |
# enable/disable specific features |
206 | 209 |
# ex: FLAVOURS = ['alfortville'] |
welco/sources/phone/views.py | ||
---|---|---|
52 | 52 |
template_name = 'welco/phone_home.html' |
53 | 53 | |
54 | 54 |
def get_context_data(self, **kwargs): |
55 |
username = self.request.session.get('mellon_session', {}).get('username') |
|
56 |
if username: |
|
57 |
# user is from SSO, username is a phone line (callee), create a link to it |
|
58 |
username = username[0].split('@', 1)[0][:80] # remove realm |
|
55 |
if settings.PHONE_AUTOTAKE_MELLON_USERNAME: |
|
56 |
username = self.request.session.get('mellon_session', {}).get('username') |
|
59 | 57 |
if username: |
60 |
PhoneLine.take(callee=username, user=self.request.user) |
|
58 |
# user is from SSO, username is a phone line (callee), create a link to it |
|
59 |
username = username[0].split('@', 1)[0][:80] # remove realm |
|
60 |
if username: |
|
61 |
PhoneLine.take(callee=username, user=self.request.user) |
|
61 | 62 |
context = super(PhoneZone, self).get_context_data(**kwargs) |
62 | 63 |
context['source_type'] = ContentType.objects.get_for_model(PhoneCall) |
63 | 64 |
context['phonelines'] = PhoneLine.objects.filter(users__id=self.request.user.id) |
64 |
- |