def test_json_view_normal_response(): """Normal responses get passed through.""" expected = http.HttpResponseForbidden() f = lambda r: expected response = json_view(f)(mock.Mock()) assert expected is response eq_(response['Content-Type'], 'text/html; charset=utf-8')
def test_json_view(): """Turns a Python object into a response.""" response = json_view(lambda r: {'x': 1})(mock.Mock()) assert isinstance(response, http.HttpResponse) eq_(response.content, '{"x": 1}') eq_(response['Content-Type'], 'application/json') eq_(response.status_code, 200)
def test_json_view_status(): f = lambda r: {'x': 1} response = json_view(f, status_code=202)(mock.Mock()) eq_(response.status_code, 202)