def test_json_view_normal_response(): """Normal responses get passed through.""" expected = http.HttpResponseForbidden() f = lambda r: expected response = decorators.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.""" f = lambda r: {'x': 1} response = decorators.json_view(f)(mock.Mock()) assert isinstance(response, http.HttpResponse) eq_(response.content, '{"x": 1}') eq_(response['Content-Type'], 'application/json')
def test_json_view(): """Turns a Python object into a response.""" f = lambda r: {"x": 1} response = decorators.json_view(f)(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(): """Turns a Python object into a response.""" def func(request): return {'x': 1} response = decorators.json_view(func)(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 = decorators.json_view(f, status_code=202)(mock.Mock()) eq_(response.status_code, 202)
def test_json_view_status(): def func(request): return {'x': 1} response = decorators.json_view(func, status_code=202)(mock.Mock()) eq_(response.status_code, 202)