From 1d8bcee7065fc850f8147a19e31d1cf4bc5310f2 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Thu, 6 Oct 2022 18:40:30 +0200 Subject: [PATCH] phonecalls: do not consider existing calls on call start (#69972) --- passerelle/apps/phonecalls/models.py | 14 +++------- tests/test_phonecalls.py | 39 ---------------------------- 2 files changed, 3 insertions(+), 50 deletions(-) diff --git a/passerelle/apps/phonecalls/models.py b/passerelle/apps/phonecalls/models.py index 8a8bc7eb..b966f9a3 100644 --- a/passerelle/apps/phonecalls/models.py +++ b/passerelle/apps/phonecalls/models.py @@ -58,17 +58,9 @@ class PhoneCalls(BaseResource): }, ) def call_start(self, request, callee, caller, redirect=None, newtab=None, **kwargs): - existing_call = Call.objects.filter( - resource=self, callee=callee, caller=caller, end_timestamp=None - ).last() - if existing_call: - existing_call.details = kwargs - existing_call.save() - response = {'data': existing_call.json()} - else: - new_call = Call(resource=self, callee=callee, caller=caller, details=kwargs) - new_call.save() - response = {'data': new_call.json()} + new_call = Call(resource=self, callee=callee, caller=caller, details=kwargs) + new_call.save() + response = {'data': new_call.json()} redirect_url = self.redirect_url if redirect_url: diff --git a/tests/test_phonecalls.py b/tests/test_phonecalls.py index 3e842384..e6bc1231 100644 --- a/tests/test_phonecalls.py +++ b/tests/test_phonecalls.py @@ -63,45 +63,6 @@ def test_phonecalls_start_stop(app, phonecalls): assert call.caller == '0612345678' assert call.end_timestamp is None assert call.details == {} - json_start = resp.json['data']['start'] - start = call.start_timestamp - - # same call, do nothing - resp = app.get( - start_endpoint, status=200, params={'apikey': '123', 'callee': '42', 'caller': '0612345678'} - ) - assert resp.json['err'] == 0 - assert resp.json['data']['callee'] == '42' - assert resp.json['data']['caller'] == '0612345678' - assert resp.json['data']['start'] == json_start - assert resp.json['data']['end'] is None - assert resp.json['data']['is_current'] is True - assert Call.objects.count() == 1 - call = Call.objects.first() - assert call.callee == '42' - assert call.caller == '0612345678' - assert call.end_timestamp is None - assert call.start_timestamp == start - assert call.details == {} - resp = app.get( - start_endpoint, - status=200, - params={'apikey': '123', 'callee': '42', 'caller': '0612345678', 'foo': 'bar'}, - ) # add details - assert resp.json['err'] == 0 - assert resp.json['data']['callee'] == '42' - assert resp.json['data']['caller'] == '0612345678' - assert resp.json['data']['start'] == json_start - assert resp.json['data']['end'] is None - assert resp.json['data']['is_current'] is True - assert resp.json['data']['details'] == {'foo': 'bar'} - assert Call.objects.count() == 1 - call = Call.objects.first() - assert call.callee == '42' - assert call.caller == '0612345678' - assert call.end_timestamp is None - assert call.start_timestamp == start - assert call.details == {'foo': 'bar'} resp = app.get(calls_endpoint, status=200, params={'apikey': '123'}) assert resp.json['err'] == 0