def test_dispatch_passes_http_response(dispatch): dispatch.return_value = HttpResponse() view = BaseTestDataRestView() result = view.dispatch( create_request(), app='rest_test_data', model='simple' ) assert_equal(result, dispatch.return_value)
def test_dispatch_jsons_other(dispatch): dispatch.return_value = {'test': 'data'} view = BaseTestDataRestView() result = view.dispatch( create_request(), app='rest_test_data', model='simple' ) assert_is_instance(result, HttpResponse) assert_equal(result['Content-Type'], 'application/json') assert_equal(result.content, b'{"test": "data"}')
def test_dispatch_wraps_string_result(dispatch): dispatch.return_value = 'result!' view = BaseTestDataRestView() result = view.dispatch( create_request(), app='rest_test_data', model='simple' ) assert_is_instance(result, HttpResponse) assert_equal(result['Content-Type'], 'application/json') assert_equal(result.content, b'result!')
def test_dispatch_get_object(dispatch, get_object): dispatch.return_value = '' view = BaseTestDataRestView() result = view.dispatch( create_request(), app='rest_test_data', model='simple', pk='1' ) get_object.assert_called_once_with(1, model=Simple) assert_is_instance(result, HttpResponse) assert_equal(dispatch.call_count, 1)
def test_dispatch_get_object_failure(get_object): get_object.side_effect = Exception view = BaseTestDataRestView() result = view.dispatch(None, app='rest_test_data', model='simple', pk='1') get_object.assert_called_once_with(1, model=Simple) assert_is_instance(result, HttpResponseNotFound)
def test_dispatch_model_found(dispatch): dispatch.return_value = '' view = BaseTestDataRestView() view.dispatch(create_request(), app='rest_test_data', model='simple') assert_equal(view.model, Simple) assert_equal(dispatch.call_count, 1)
def test_dispatch_model_not_found(): view = BaseTestDataRestView() result = view.dispatch(None, app='something', model='notfoundmodel') assert_is_instance(result, HttpResponseNotFound)