Projet

Général

Profil

0001-phonecalls-do-not-consider-existing-calls-on-call-st.patch

Thomas Noël, 06 octobre 2022 18:55

Télécharger (3,45 ko)

Voir les différences:

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(-)
passerelle/apps/phonecalls/models.py
58 58
        },
59 59
    )
60 60
    def call_start(self, request, callee, caller, redirect=None, newtab=None, **kwargs):
61
        existing_call = Call.objects.filter(
62
            resource=self, callee=callee, caller=caller, end_timestamp=None
63
        ).last()
64
        if existing_call:
65
            existing_call.details = kwargs
66
            existing_call.save()
67
            response = {'data': existing_call.json()}
68
        else:
69
            new_call = Call(resource=self, callee=callee, caller=caller, details=kwargs)
70
            new_call.save()
71
            response = {'data': new_call.json()}
61
        new_call = Call(resource=self, callee=callee, caller=caller, details=kwargs)
62
        new_call.save()
63
        response = {'data': new_call.json()}
72 64

  
73 65
        redirect_url = self.redirect_url
74 66
        if redirect_url:
tests/test_phonecalls.py
63 63
    assert call.caller == '0612345678'
64 64
    assert call.end_timestamp is None
65 65
    assert call.details == {}
66
    json_start = resp.json['data']['start']
67
    start = call.start_timestamp
68

  
69
    # same call, do nothing
70
    resp = app.get(
71
        start_endpoint, status=200, params={'apikey': '123', 'callee': '42', 'caller': '0612345678'}
72
    )
73
    assert resp.json['err'] == 0
74
    assert resp.json['data']['callee'] == '42'
75
    assert resp.json['data']['caller'] == '0612345678'
76
    assert resp.json['data']['start'] == json_start
77
    assert resp.json['data']['end'] is None
78
    assert resp.json['data']['is_current'] is True
79
    assert Call.objects.count() == 1
80
    call = Call.objects.first()
81
    assert call.callee == '42'
82
    assert call.caller == '0612345678'
83
    assert call.end_timestamp is None
84
    assert call.start_timestamp == start
85
    assert call.details == {}
86
    resp = app.get(
87
        start_endpoint,
88
        status=200,
89
        params={'apikey': '123', 'callee': '42', 'caller': '0612345678', 'foo': 'bar'},
90
    )  # add details
91
    assert resp.json['err'] == 0
92
    assert resp.json['data']['callee'] == '42'
93
    assert resp.json['data']['caller'] == '0612345678'
94
    assert resp.json['data']['start'] == json_start
95
    assert resp.json['data']['end'] is None
96
    assert resp.json['data']['is_current'] is True
97
    assert resp.json['data']['details'] == {'foo': 'bar'}
98
    assert Call.objects.count() == 1
99
    call = Call.objects.first()
100
    assert call.callee == '42'
101
    assert call.caller == '0612345678'
102
    assert call.end_timestamp is None
103
    assert call.start_timestamp == start
104
    assert call.details == {'foo': 'bar'}
105 66

  
106 67
    resp = app.get(calls_endpoint, status=200, params={'apikey': '123'})
107 68
    assert resp.json['err'] == 0
108
-