0001-api-give-specific-message-on-json-calls-missing-cont.patch
tests/test_api.py | ||
---|---|---|
565 | 565 |
assert data_class.get(resp.json['data']['id']).user_id == str(local_user.id) |
566 | 566 |
assert data_class.get(resp.json['data']['id']).tracking_code is None |
567 | 567 | |
568 |
resp = get_app(pub).post(url(), json.dumps({'data': {}}), status=400) # missing Content-Type: application/json header |
|
569 |
assert resp.json['err_desc'] == 'expected JSON but missing appropriate content-type' |
|
570 | ||
568 | 571 |
formdef.disabled = True |
569 | 572 |
formdef.store() |
570 | 573 |
resp = get_app(pub).post_json(url(), {'data': {}}, status=403) |
wcs/qommon/http_request.py | ||
---|---|---|
125 | 125 |
length = int(self.environ.get('CONTENT_LENGTH') or '0') |
126 | 126 |
payload = self.django_request.read(length) |
127 | 127 |
try: |
128 |
self.json = json_loads(payload) |
|
128 |
self._json = json_loads(payload)
|
|
129 | 129 |
except ValueError, e: |
130 | 130 |
raise RequestError('invalid json payload (%s)' % str(e)) |
131 | 131 |
# Make sure request.form doesn't contain unicode strings, converting |
... | ... | |
135 | 135 |
for k, v in self.form.items()) |
136 | 136 |
self.parsed = True |
137 | 137 | |
138 |
@property |
|
139 |
def json(self): |
|
140 |
if not hasattr(self, '_json'): |
|
141 |
raise RequestError('expected JSON but missing appropriate content-type') |
|
142 |
return self._json |
|
143 | ||
138 | 144 |
def is_json(self): |
139 | 145 |
if self.is_json_marker: |
140 | 146 |
return True |
141 |
- |