0001-dpark-accept-error-message-containing-latin1-38130.patch
passerelle/contrib/dpark/models.py | ||
---|---|---|
20 | 20 |
from django.conf import settings |
21 | 21 |
from django.db import models |
22 | 22 |
from django.utils import timezone |
23 |
from django.utils.encoding import force_text |
|
23 | 24 |
from django.utils.translation import ugettext_lazy as _ |
24 | 25 |
from django.core.cache import cache |
25 | 26 | |
... | ... | |
202 | 203 |
try: |
203 | 204 |
reply = getattr(proxy_service, operation)(*args, **kwargs) |
204 | 205 |
except (WebFault, ) as exc: |
205 |
raise APIError('ServiceError: %s' % exc)
|
|
206 |
raise APIError('ServiceError: %s' % force_text(exc.message, 'latin1', errors='ignore'))
|
|
206 | 207 |
except (Exception,) as exc: |
207 | 208 |
raise APIError('Error: %s' % exc) |
208 | 209 |
reply_code = getattr(reply, 'CodeRetour', None) or getattr(reply, 'Code_Retour', None) |
tests/test_dpark.py | ||
---|---|---|
78 | 78 |
super(ReplyDataClass, self).__init__(**kwargs) |
79 | 79 | |
80 | 80 | |
81 |
class WebFaultHavingLatin1(WebFault): |
|
82 |
pass |
|
83 | ||
84 | ||
81 | 85 |
class MockedService(object): |
82 | 86 | |
83 | 87 |
def __init__(self, success, error_class, replydata): |
... | ... | |
90 | 94 |
raise self.error_class(mock.Mock(faulstring='Error %s raised' % self.error_class.__name__), None) |
91 | 95 |
elif self.error_class is TransportError: |
92 | 96 |
raise self.error_class('connection error occured', None) |
97 |
elif self.error_class is WebFaultHavingLatin1: |
|
98 |
raise WebFault(message=u'éêè') |
|
93 | 99 |
else: |
94 | 100 |
raise Exception('random error') |
95 | 101 | |
... | ... | |
121 | 127 |
client.return_value = get_client(error_class=Exception) |
122 | 128 |
resp = app.get('/dpark/test/ping/') |
123 | 129 |
assert 'Error: random error' in resp.json['err_desc'] |
130 |
client.return_value = get_client(error_class=WebFaultHavingLatin1) |
|
131 |
resp = app.get('/dpark/test/ping/') |
|
132 |
assert u'ServiceError: éêè' in resp.json['err_desc'] |
|
124 | 133 | |
125 | 134 | |
126 | 135 |
def test_ping(dpark, app): |
127 |
- |