pbx and tlmcom: back to a simple caller/callee system (#9597 rewrite)
This commit is contained in:
parent
63a4344073
commit
46f669fd28
|
@ -67,7 +67,7 @@ class CallStart(SingleObjectMixin, View):
|
|||
data = dict(request.GET.iteritems())
|
||||
for key in ['caller', 'callee', 'id']:
|
||||
data.pop(key, None)
|
||||
self.get_object().notify_welco(self.event, caller, callee, data, username=username)
|
||||
self.get_object().notify_welco(self.event, caller, username or callee, data)
|
||||
return HttpResponse('ok')
|
||||
|
||||
|
||||
|
|
|
@ -25,12 +25,11 @@ class PBXMixin(BaseResource):
|
|||
|
||||
category = _('Telephony')
|
||||
|
||||
def notify_welco(self, event, caller, callee, data=None, username=None):
|
||||
def notify_welco(self, event, caller, callee, data=None):
|
||||
assert event in ('start', 'stop')
|
||||
assert isinstance(caller, basestring)
|
||||
assert isinstance(callee, basestring)
|
||||
assert not data or isinstance(data, dict)
|
||||
assert not username or isinstance(username, basestring)
|
||||
logger = logging.getLogger(__name__)
|
||||
caller = unicode(caller)
|
||||
callee = unicode(callee)
|
||||
|
@ -43,17 +42,10 @@ class PBXMixin(BaseResource):
|
|||
}
|
||||
if data:
|
||||
payload['data'] = data
|
||||
if username:
|
||||
username = unicode(username)
|
||||
payload['username'] = username
|
||||
requests.post(self.welco_url, data=json.dumps(payload),
|
||||
headers={'content-type': 'application/json'})
|
||||
if username:
|
||||
logger.info(u'notified welco of event %s from %s to %s with username %s',
|
||||
event, caller, callee, username)
|
||||
else:
|
||||
logger.info(u'notified welco of event %s from %s to %s',
|
||||
event, caller, callee)
|
||||
logger.info(u'notified welco of event %s from %s to %s',
|
||||
event, caller, callee)
|
||||
|
||||
@classmethod
|
||||
def get_icon_class(cls):
|
||||
|
|
|
@ -63,10 +63,9 @@ def test_call_start_with_id(requests_post, client):
|
|||
assert requests_post.call_args == mock.call(URL, data=mock.ANY, headers={'content-type': 'application/json'})
|
||||
payload = json.loads(requests_post.call_args[1]['data'])
|
||||
assert isinstance(payload, dict)
|
||||
assert set(payload.keys()) == set(['username', 'caller', 'callee', 'event'])
|
||||
assert set(payload.keys()) == set(['caller', 'callee', 'event'])
|
||||
assert payload['event'] == 'start'
|
||||
assert payload['username'] == 'zozo'
|
||||
assert payload['callee'] == '102'
|
||||
assert payload['callee'] == 'zozo'
|
||||
assert payload['caller'] == '0033699999999'
|
||||
|
||||
@mock.patch('requests.post')
|
||||
|
@ -83,8 +82,7 @@ def test_call_stop_with_id(requests_post, client):
|
|||
assert requests_post.call_args == mock.call(URL, data=mock.ANY, headers={'content-type': 'application/json'})
|
||||
payload = json.loads(requests_post.call_args[1]['data'])
|
||||
assert isinstance(payload, dict)
|
||||
assert set(payload.keys()) == set(['username', 'caller', 'callee', 'event'])
|
||||
assert set(payload.keys()) == set(['caller', 'callee', 'event'])
|
||||
assert payload['event'] == 'stop'
|
||||
assert payload['username'] == 'zozo'
|
||||
assert payload['callee'] == '102'
|
||||
assert payload['callee'] == 'zozo'
|
||||
assert payload['caller'] == '0033699999999'
|
||||
|
|
Loading…
Reference in New Issue