Projet

Général

Profil

0001-phonecalls-pass-callee-to-redirect_url-48850.patch

Benjamin Dauvergne, 26 novembre 2020 15:27

Télécharger (3,16 ko)

Voir les différences:

Subject: [PATCH] phonecalls: pass callee to redirect_url (#48850)

 passerelle/apps/phonecalls/models.py |  7 ++++---
 tests/test_phonecalls.py             | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
passerelle/apps/phonecalls/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import json
18

  
19 17
from django.contrib.postgres.fields import JSONField
20 18
from django.db import models
19
from django.utils.http import urlencode
21 20
from django.utils.timezone import now, timedelta, make_naive
22 21
from django.utils.translation import ugettext_lazy as _
23
from django.http import HttpResponseRedirect, HttpResponse
22
from django.http import HttpResponseRedirect
24 23
from django.shortcuts import render
25 24

  
26 25
from passerelle.base.models import BaseResource
......
71 70
            response = {'data': new_call.json()}
72 71

  
73 72
        redirect_url = self.redirect_url
73
        if redirect_url:
74
            redirect_url += ('&' if '?' in redirect_url else '?') + urlencode({'callee': callee})
74 75

  
75 76
        # redirect to agent's portal
76 77
        if redirect and redirect_url:
tests/test_phonecalls.py
220 220
    start_endpoint = utils.generic_endpoint_url('phonecalls', 'call-start', slug=phonecalls.slug)
221 221
    resp = app.get(start_endpoint, status=302, params={
222 222
        'apikey': '123', 'callee': '42', 'caller': '0612345678', 'redirect': '1'})
223
    assert resp.location == 'https://portail-agent.publik/'
223
    assert resp.location == 'https://portail-agent.publik/?callee=42'
224 224
    assert Call.objects.filter(callee='42', caller='0612345678').count() == 1
225 225

  
226 226

  
......
233 233
    resp = app.get(start_endpoint, status=200, params={
234 234
        'apikey': '123', 'callee': '42', 'caller': '0612345678', 'newtab': '1'})
235 235
    assert resp.content_type == 'text/html'
236
    assert 'window.open("https://portail\\u002Dagent.publik/")' in resp.text
236
    assert 'window.open("https://portail\\u002Dagent.publik/?callee\\u003D42")' in resp.text
237 237
    assert Call.objects.filter(callee='42', caller='0612345678').count() == 1
238

  
239

  
240
def test_phonecalls_add_callee(app, phonecalls):
241
    phonecalls.redirect_url = 'https://portail-agent.publik/'
242
    phonecalls.save()
243

  
244
    start_endpoint = utils.generic_endpoint_url('phonecalls', 'call-start', slug=phonecalls.slug)
245
    resp = app.get(start_endpoint, status=302, params={
246
        'apikey': '123', 'callee': '42', 'caller': '0612345678', 'redirect': '1'})
247
    assert resp.location == 'https://portail-agent.publik/?callee=42'
238
-