0003-django4-replaced-force_text-with-equivalent-force_st.patch
tests/test_mail_manager.py | ||
---|---|---|
20 | 20 |
import requests |
21 | 21 |
from django.contrib.contenttypes.models import ContentType |
22 | 22 |
from django.core.files.base import ContentFile |
23 |
from django.utils.encoding import force_text
|
|
23 |
from django.utils.encoding import force_str
|
|
24 | 24 |
from webtest import Upload |
25 | 25 | |
26 | 26 |
from welco.sources.mail.models import Mail |
... | ... | |
134 | 134 | |
135 | 135 |
@httmock.urlmatch(netloc='maarch.example.net', path='/rest/res/resource/status', method='PUT') |
136 | 136 |
def response_ok(url, request): |
137 |
assert json.loads(force_text(request.body)) == {'status': 'FOO', 'resId': ['42']}
|
|
137 |
assert json.loads(force_str(request.body)) == {'status': 'FOO', 'resId': ['42']}
|
|
138 | 138 |
headers = {'content-type': 'application/json'} |
139 | 139 |
content = {"maarch_say": "ok"} |
140 | 140 |
return httmock.response(200, content, headers) |
tests/test_source_maarch.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
import pytest |
20 | 20 |
from django.contrib.auth.models import User |
21 |
from django.utils.encoding import force_text
|
|
21 |
from django.utils.encoding import force_str
|
|
22 | 22 |
from httmock import HTTMock, urlmatch |
23 | 23 | |
24 | 24 | |
... | ... | |
49 | 49 | |
50 | 50 |
class MaarchMock(BaseMock): |
51 | 51 |
def list_endpoint(self, url, request): |
52 |
self.requests.append(('list_endpoint', url, request, json.loads(force_text(request.body))))
|
|
52 |
self.requests.append(('list_endpoint', url, request, json.loads(force_str(request.body))))
|
|
53 | 53 |
return { |
54 | 54 |
'content': json.dumps(self.next_response()), |
55 | 55 |
'headers': { |
... | ... | |
61 | 61 |
list_endpoint.path = '^/rest/res/list$' |
62 | 62 | |
63 | 63 |
def update_external_infos(self, url, request): |
64 |
self.requests.append(('update_external_infos', url, request, json.loads(force_text(request.body))))
|
|
64 |
self.requests.append(('update_external_infos', url, request, json.loads(force_str(request.body))))
|
|
65 | 65 |
return json.dumps({}) |
66 | 66 | |
67 | 67 |
update_external_infos.path = '^/rest/res/externalInfos$' |
68 | 68 | |
69 | 69 |
def update_status(self, url, request): |
70 |
self.requests.append(('update_status', url, request, json.loads(force_text(request.body))))
|
|
70 |
self.requests.append(('update_status', url, request, json.loads(force_str(request.body))))
|
|
71 | 71 |
return { |
72 | 72 |
'content': json.dumps(self.next_response()), |
73 | 73 |
'headers': { |
... | ... | |
79 | 79 |
update_status.path = '^/rest/res/resource/status$' |
80 | 80 | |
81 | 81 |
def post_courrier(self, url, request): |
82 |
self.requests.append(('post_courrier', url, request, json.loads(force_text(request.body))))
|
|
82 |
self.requests.append(('post_courrier', url, request, json.loads(force_str(request.body))))
|
|
83 | 83 | |
84 | 84 |
post_courrier.path = '^/rest/res$' |
85 | 85 | |
... | ... | |
194 | 194 |
'resources': [ |
195 | 195 |
{ |
196 | 196 |
'res_id': 1, |
197 |
'fileBase64Content': force_text(base64.b64encode(PDF_MOCK)),
|
|
197 |
'fileBase64Content': force_str(base64.b64encode(PDF_MOCK)),
|
|
198 | 198 |
} |
199 | 199 |
], |
200 | 200 |
} |
tests/test_source_phone.py | ||
---|---|---|
20 | 20 |
import pytest |
21 | 21 |
from django.test import override_settings |
22 | 22 |
from django.urls import reverse |
23 |
from django.utils.encoding import force_text
|
|
23 |
from django.utils.encoding import force_str
|
|
24 | 24 |
from django.utils.timezone import now, timedelta |
25 | 25 | |
26 | 26 |
from welco.sources.phone import models |
... | ... | |
227 | 227 |
client.login(username='toto', password='toto') |
228 | 228 |
response = client.get(reverse('phone-zone')) |
229 | 229 |
assert response.status_code == 200 |
230 |
assert 'You do not have a phoneline configured' in force_text(response.content)
|
|
230 |
assert 'You do not have a phoneline configured' in force_str(response.content)
|
|
231 | 231 | |
232 | 232 |
models.PhoneLine.take(callee='102', user=user) |
233 | 233 | |
234 | 234 |
response = client.get(reverse('phone-zone')) |
235 | 235 |
assert response.status_code == 200 |
236 |
assert 'You do not have a phoneline configured' not in force_text(response.content)
|
|
237 |
assert '<li>102' in force_text(response.content)
|
|
238 |
assert 'data-callee="102"' in force_text(response.content)
|
|
236 |
assert 'You do not have a phoneline configured' not in force_str(response.content)
|
|
237 |
assert '<li>102' in force_str(response.content)
|
|
238 |
assert 'data-callee="102"' in force_str(response.content)
|
|
239 | 239 |
currents = re.search( |
240 | 240 |
'<div id="source-mainarea" ' 'data-current-calls="/api/phone/current-calls/">' '(.*?)</div>', |
241 |
force_text(response.content),
|
|
241 |
force_str(response.content),
|
|
242 | 242 |
flags=re.DOTALL, |
243 | 243 |
) |
244 | 244 |
assert currents.group(1).strip() == '' |
... | ... | |
249 | 249 |
assert response.status_code == 200 |
250 | 250 |
response = client.get(reverse('phone-zone')) |
251 | 251 |
assert response.status_code == 200 |
252 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in force_text(response.content)
|
|
252 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in force_str(response.content)
|
|
253 | 253 | |
254 | 254 |
# simulate a mellon user |
255 | 255 |
session = client.session |
... | ... | |
257 | 257 |
session.save() |
258 | 258 |
response = client.get(reverse('phone-zone')) |
259 | 259 |
assert response.status_code == 200 |
260 |
assert 'agent007' not in force_text(response.content)
|
|
261 |
assert 'data-callee="agent007"' not in force_text(response.content)
|
|
262 |
assert '<li>102' in force_text(response.content)
|
|
263 |
assert 'data-callee="102"' in force_text(response.content)
|
|
260 |
assert 'agent007' not in force_str(response.content)
|
|
261 |
assert 'data-callee="agent007"' not in force_str(response.content)
|
|
262 |
assert '<li>102' in force_str(response.content)
|
|
263 |
assert 'data-callee="102"' in force_str(response.content)
|
|
264 | 264 | |
265 | 265 |
with override_settings(PHONE_AUTOTAKE_MELLON_USERNAME=True): |
266 | 266 |
response = client.get(reverse('phone-zone')) |
267 | 267 |
assert response.status_code == 200 |
268 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in force_text(response.content)
|
|
269 |
assert 'agent007' in force_text(response.content)
|
|
270 |
assert 'data-callee="agent007"' in force_text(response.content)
|
|
271 |
assert '<li>102' in force_text(response.content)
|
|
272 |
assert 'data-callee="102"' in force_text(response.content)
|
|
268 |
assert '<h1>Current Call: <strong>003369999999</strong></h1>' in force_str(response.content)
|
|
269 |
assert 'agent007' in force_str(response.content)
|
|
270 |
assert 'data-callee="agent007"' in force_str(response.content)
|
|
271 |
assert '<li>102' in force_str(response.content)
|
|
272 |
assert 'data-callee="102"' in force_str(response.content)
|
|
273 | 273 | |
274 | 274 | |
275 | 275 |
def test_call_expiration(user, client): |
welco/monkeypatch.py | ||
---|---|---|
18 | 18 |
from django.forms.utils import flatatt |
19 | 19 |
from django.template.loader import render_to_string |
20 | 20 |
from django.urls import reverse |
21 |
from django.utils.encoding import force_text
|
|
21 |
from django.utils.encoding import force_str
|
|
22 | 22 |
from django.utils.html import conditional_escape |
23 | 23 |
from django.utils.safestring import mark_safe |
24 | 24 |
from django.utils.translation import get_language |
... | ... | |
41 | 41 | |
42 | 42 |
# Force to text to evaluate possible lazy objects |
43 | 43 |
external_plugin_resources = [ |
44 |
[force_text(a), force_text(b), force_text(c)] for a, b, c in self.external_plugin_resources
|
|
44 |
[force_str(a), force_str(b), force_str(c)] for a, b, c in self.external_plugin_resources
|
|
45 | 45 |
] |
46 | 46 | |
47 | 47 |
return mark_safe( |
... | ... | |
49 | 49 |
'ckeditor/widget.html', |
50 | 50 |
{ |
51 | 51 |
'final_attrs': flatatt(final_attrs), |
52 |
'value': conditional_escape(force_text(value)),
|
|
52 |
'value': conditional_escape(force_str(value)),
|
|
53 | 53 |
'id': final_attrs['id'], |
54 | 54 |
'config': ckeditor.widgets.json_encode(self.config), |
55 | 55 |
'external_plugin_resources': ckeditor.widgets.json_encode(external_plugin_resources), |
welco/sources/phone/views.py | ||
---|---|---|
23 | 23 |
from django.contrib.contenttypes.models import ContentType |
24 | 24 |
from django.http import HttpResponse, HttpResponseBadRequest |
25 | 25 |
from django.template import RequestContext |
26 |
from django.utils.encoding import force_text
|
|
26 |
from django.utils.encoding import force_str
|
|
27 | 27 |
from django.utils.timezone import now |
28 | 28 |
from django.views.decorators.csrf import csrf_exempt |
29 | 29 |
from django.views.generic import TemplateView |
... | ... | |
84 | 84 |
""" |
85 | 85 |
logger = logging.getLogger(__name__) |
86 | 86 |
try: |
87 |
payload = json.loads(force_text(request.body))
|
|
87 |
payload = json.loads(force_str(request.body))
|
|
88 | 88 |
assert isinstance(payload, dict), 'payload is not a JSON object' |
89 | 89 |
assert set(payload.keys()) <= { |
90 | 90 |
'event', |
... | ... | |
102 | 102 |
assert isinstance(payload['data'], dict), 'data must be a JSON object' |
103 | 103 |
except (TypeError, ValueError, AssertionError) as e: |
104 | 104 |
return HttpResponseBadRequest( |
105 |
json.dumps({'err': 1, 'msg': force_text(e)}), content_type='application/json'
|
|
105 |
json.dumps({'err': 1, 'msg': force_str(e)}), content_type='application/json'
|
|
106 | 106 |
) |
107 | 107 |
# janitoring: stop active calls to the callee |
108 | 108 |
if settings.PHONE_ONE_CALL_PER_CALLEE: |
... | ... | |
202 | 202 |
""" |
203 | 203 |
logger = logging.getLogger(__name__) |
204 | 204 |
try: |
205 |
payload = json.loads(force_text(request.body))
|
|
205 |
payload = json.loads(force_str(request.body))
|
|
206 | 206 |
assert isinstance(payload, dict), 'payload is not a JSON object' |
207 | 207 |
assert list(payload.keys()) == ['callee'], 'payload must have only one key: callee' |
208 | 208 |
except (TypeError, ValueError, AssertionError) as e: |
209 | 209 |
return HttpResponseBadRequest( |
210 |
json.dumps({'err': 1, 'msg': force_text(e)}), content_type='application/json'
|
|
210 |
json.dumps({'err': 1, 'msg': force_str(e)}), content_type='application/json'
|
|
211 | 211 |
) |
212 | 212 |
PhoneLine.take(payload['callee'], request.user) |
213 | 213 |
logger.info('user %s took line %s', request.user, payload['callee']) |
... | ... | |
223 | 223 |
""" |
224 | 224 |
logger = logging.getLogger(__name__) |
225 | 225 |
try: |
226 |
payload = json.loads(force_text(request.body))
|
|
226 |
payload = json.loads(force_str(request.body))
|
|
227 | 227 |
assert isinstance(payload, dict), 'payload is not a JSON object' |
228 | 228 |
assert list(payload.keys()) == ['callee'], 'payload must have only one key: callee' |
229 | 229 |
except (TypeError, ValueError, AssertionError) as e: |
230 | 230 |
return HttpResponseBadRequest( |
231 |
json.dumps({'err': 1, 'msg': force_text(e)}), content_type='application/json'
|
|
231 |
json.dumps({'err': 1, 'msg': force_str(e)}), content_type='application/json'
|
|
232 | 232 |
) |
233 | 233 |
PhoneLine.release(payload['callee'], request.user) |
234 | 234 |
logger.info('user %s released line %s', request.user, payload['callee']) |
welco/views.py | ||
---|---|---|
27 | 27 |
from django.shortcuts import resolve_url |
28 | 28 |
from django.template import RequestContext |
29 | 29 |
from django.urls import reverse |
30 |
from django.utils.encoding import force_text
|
|
30 |
from django.utils.encoding import force_str
|
|
31 | 31 |
from django.utils.http import quote |
32 | 32 |
from django.utils.translation import ugettext_lazy as _ |
33 | 33 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
222 | 222 |
if user_groups.intersection(channel_groups): |
223 | 223 |
menu.append( |
224 | 224 |
{ |
225 |
'label': force_text(labels.get(channel)),
|
|
225 |
'label': force_str(labels.get(channel)),
|
|
226 | 226 |
'slug': channel, |
227 | 227 |
'url': request.build_absolute_uri(reverse('home-%s' % channel)), |
228 | 228 |
} |
... | ... | |
230 | 230 |
if check_kb_user_perms(request.user, access=True): |
231 | 231 |
menu.append( |
232 | 232 |
{ |
233 |
'label': force_text(_('Knowledge Base')),
|
|
233 |
'label': force_str(_('Knowledge Base')),
|
|
234 | 234 |
'slug': 'book', |
235 | 235 |
'url': request.build_absolute_uri(reverse('kb-home')), |
236 | 236 |
} |
237 |
- |