python3: replace unicode references (#39092)

This commit is contained in:
Frédéric Péters 2020-01-19 19:11:28 +01:00
parent 46113c03dd
commit 8112d57b0a
3 changed files with 15 additions and 11 deletions

View File

@ -21,6 +21,7 @@ import pytest
from django.core.urlresolvers import reverse
from django.test import override_settings
from django.utils import six
from django.utils.timezone import now, timedelta
from welco.sources.phone import models
@ -166,13 +167,13 @@ def test_current_calls(user, client):
assert len(data['all-lines']) == 10
for call in data['calls']:
assert set(call.keys()) <= set(['caller', 'callee', 'start', 'data'])
assert isinstance(call['caller'], unicode)
assert isinstance(call['callee'], unicode)
assert isinstance(call['start'], unicode)
assert isinstance(call['caller'], six.string_types)
assert isinstance(call['callee'], six.string_types)
assert isinstance(call['start'], six.string_types)
if 'data' in call:
assert isinstance(call['data'], dict)
assert len([call for call in data['lines'] if isinstance(call, unicode)]) == 5
assert len([call for call in data['all-lines'] if isinstance(call, unicode)]) == 10
assert len([call for call in data['lines'] if isinstance(call, six.string_types)]) == 5
assert len([call for call in data['all-lines'] if isinstance(call, six.string_types)]) == 10
# unregister user to all remaining lines
for number in range(0, 5):

View File

@ -17,6 +17,7 @@
import base64
from dateutil.parser import parse as parse_datetime
from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse
import requests
@ -88,7 +89,7 @@ class MaarchCourrier(object):
data = {key: self.__dict__[key] for key in self.__dict__ if key not in excluded_keys}
if data:
for key, value in data.items():
if isinstance(value, basestring):
if isinstance(value, six.string_types):
d.append({'column': key, 'value': value, 'type': 'string'})
elif isinstance(value, int):
d.append({'column': key, 'value': str(value), 'type': 'int'})

View File

@ -24,6 +24,8 @@ from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponse
from django.utils import six
from django.utils.encoding import force_text
from django.utils.timezone import now
from django.views.generic import TemplateView
@ -90,13 +92,13 @@ def call_event(request):
assert set(['event', 'caller', 'callee']) <= set(payload.keys()), \
'payload keys must be "event", "caller", "callee" and optionnaly "data"'
assert payload['event'] in ('start', 'stop'), 'event must be "start" or "stop"'
assert isinstance(payload['caller'], unicode), 'caller must be a string'
assert isinstance(payload['callee'], unicode), 'callee must be a string'
assert isinstance(payload['caller'], six.string_types), 'caller must be a string'
assert isinstance(payload['callee'], six.string_types), 'callee must be a string'
if 'data' in payload:
assert isinstance(payload['data'], dict), 'data must be a JSON object'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
unicode(e)}),
force_text(e)}),
content_type='application/json')
# janitoring: stop active calls to the callee
if settings.PHONE_ONE_CALL_PER_CALLEE:
@ -201,7 +203,7 @@ def take_line(request):
assert payload.keys() == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
unicode(e)}),
force_text(e)}),
content_type='application/json')
PhoneLine.take(payload['callee'], request.user)
logger.info(u'user %s took line %s', request.user, payload['callee'])
@ -222,7 +224,7 @@ def release_line(request):
assert payload.keys() == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
unicode(e)}),
force_text(e)}),
content_type='application/json')
PhoneLine.release(payload['callee'], request.user)
logger.info(u'user %s released line %s', request.user, payload['callee'])