0001-api-add-err-key-in-json-reponses-69664.patch
lingo/api/utils.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
from django.utils.translation import gettext_lazy as _ |
18 |
from rest_framework.response import Response |
|
18 |
from rest_framework.response import Response as DRFResponse
|
|
19 | 19 |
from rest_framework.views import exception_handler as DRF_exception_handler |
20 | 20 | |
21 | 21 | |
22 |
class Response(DRFResponse): |
|
23 |
def __init__(self, data=None, *args, **kwargs): |
|
24 |
if data and 'err' not in data: |
|
25 |
data['err'] = 0 |
|
26 |
super().__init__(data, *args, **kwargs) |
|
27 | ||
28 | ||
22 | 29 |
class APIError(Exception): |
23 | 30 |
http_status = 200 |
24 | 31 |
tests/api/test_agenda.py | ||
---|---|---|
14 | 14 |
group2 = CheckTypeGroup.objects.create(label='Foo bar 2') |
15 | 15 | |
16 | 16 |
resp = app.get('/api/agenda/%s/check-types/' % agenda.slug) |
17 |
assert resp.json == {'data': []} |
|
17 |
assert resp.json == {'data': [], 'err': 0}
|
|
18 | 18 | |
19 | 19 |
agenda.check_type_group = group2 |
20 | 20 |
agenda.save() |
21 | 21 |
resp = app.get('/api/agenda/%s/check-types/' % agenda.slug) |
22 |
assert resp.json == {'data': []} |
|
22 |
assert resp.json == {'data': [], 'err': 0}
|
|
23 | 23 | |
24 | 24 |
agenda.check_type_group = group |
25 | 25 |
agenda.save() |
... | ... | |
28 | 28 |
'data': [ |
29 | 29 |
{'id': 'bar-reason', 'kind': 'presence', 'text': 'Bar reason'}, |
30 | 30 |
{'id': 'foo-reason', 'kind': 'absence', 'text': 'Foo reason'}, |
31 |
] |
|
31 |
], |
|
32 |
'err': 0, |
|
32 | 33 |
} |
33 | 34 | |
34 | 35 |
# unknown |
35 |
- |