@pytest.mark.django_db
def test_handles_django_request_error(client, monkeypatch):

    def mocked_read(*args):
        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')
    assert (response.status_code == 400)
    assert (response['Content-Type'].split(';')[0] == 'application/json')
    expected_dict = {'errors': [{'message': 'foo-bar'}]}
    assert (response.json() == expected_dict)
@pytest.mark.django_db
def test_handles_django_request_error(client, monkeypatch):

    def mocked_read(*args):
        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')
    assert (response.status_code == 400)
    assert (response['Content-Type'].split(';')[0] == 'application/json')
    expected_dict = {'errors': [{'message': 'foo-bar'}]}
    assert (response.json() == expected_dict)