Rewrite unit test to make it working on all versions of django

This commit is contained in:
Alexey Subbotin 2017-04-12 13:04:03 +02:00
parent a9f34dab93
commit 33b2b42e6f

View File

@ -457,14 +457,18 @@ def test_handles_invalid_json_bodies(client):
} }
def test_handles_django_request_error(client, settings): def test_handles_django_request_error(client, monkeypatch):
settings.DATA_UPLOAD_MAX_MEMORY_SIZE = 1000 def mocked_read(*args):
valid_json = json.dumps(dict(test='x' * 1000)) raise IOError("foo-bar")
monkeypatch.setattr("django.http.request.HttpRequest.read", mocked_read)
valid_json = json.dumps(dict(foo='bar'))
response = client.post(url_string(), valid_json, 'application/json') response = client.post(url_string(), valid_json, 'application/json')
assert response.status_code == 400 assert response.status_code == 400
assert response_json(response) == { assert response_json(response) == {
'errors': [{'message': 'Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.'}] 'errors': [{'message': 'foo-bar'}]
} }