def test_spa_fallback_middleware_no_404(mocker): get_response = mocker.Mock() get_response.return_value = mocker.Mock(status_code=200) request = mocker.Mock(path="/") m = middleware.SPAFallbackMiddleware(get_response) assert m(request) == get_response.return_value
def test_spa_middleware_should_fallback_true(mocker): get_response = mocker.Mock() get_response.return_value = mocker.Mock(status_code=404) request = mocker.Mock(path="/") mocker.patch.object(middleware, "should_fallback_to_spa", return_value=True) serve_spa = mocker.patch.object(middleware, "serve_spa") m = middleware.SPAFallbackMiddleware(get_response) assert m(request) == serve_spa.return_value serve_spa.assert_called_once_with(request)
def test_spa_middleware_calls_should_fallback_false(mocker): get_response = mocker.Mock() get_response.return_value = mocker.Mock(status_code=404) should_falback = mocker.patch.object(middleware, "should_fallback_to_spa", return_value=False) request = mocker.Mock(path="/") m = middleware.SPAFallbackMiddleware(get_response) assert m(request) == get_response.return_value should_falback.assert_called_once_with(request.path)
def test_spa_middleware_handles_api_redirect(mocker): get_response = mocker.Mock(return_value=mocker.Mock(status_code=404)) redirect_url = "/test" mocker.patch.object(middleware, "serve_spa", side_effect=middleware.ApiRedirect(redirect_url)) api_view = mocker.Mock() match = mocker.Mock(args=["hello"], kwargs={"foo": "bar"}, func=api_view) mocker.patch.object(middleware.urls, "resolve", return_value=match) request = mocker.Mock(path="/") m = middleware.SPAFallbackMiddleware(get_response) response = m(request) api_view.assert_called_once_with(request, "hello", foo="bar") assert response == api_view.return_value