예제 #1
0
    def test_does_not_show_flash_message_if_xhr(self, pyramid_request):
        pyramid_request.is_xhr = True
        form_ = mock.Mock(spec_set=["render"])

        form.to_xhr_response(pyramid_request, mock.sentinel.non_xhr_result, form_)

        assert pyramid_request.session.peek_flash("success") == []
예제 #2
0
    def test_returns_form_if_xhr(self, pyramid_request):
        """
        If ``request`` is an XHR request it should return the rendered ``form``.

        It should return ``form`` rendered to a ``<form>`` element HTML snippet.

        """
        pyramid_request.is_xhr = True
        form_ = mock.Mock(spec_set=["render"])

        result = form.to_xhr_response(pyramid_request,
                                      mock.sentinel.non_xhr_result, form_)

        assert result == form_.render.return_value
예제 #3
0
파일: form_test.py 프로젝트: hypothesis/h
    def test_returns_form_if_xhr(self, pyramid_request):
        """
        If ``request`` is an XHR request it should return the rendered ``form``.

        It should return ``form`` rendered to a ``<form>`` element HTML snippet.

        """
        pyramid_request.is_xhr = True
        form_ = mock.Mock(spec_set=["render"])

        result = form.to_xhr_response(
            pyramid_request, mock.sentinel.non_xhr_result, form_
        )

        assert result == form_.render.return_value
예제 #4
0
    def test_returns_given_result_if_not_xhr(self, pyramid_request):
        """
        If ``request`` isn't an XHR request it returns ``non_xhr_result``.

        The calling view callable passes in the result that it would have
        returned normally if this were not an XHR request as the
        ``non_xhr_result`` argument. If the given ``request`` is not an XHR
        request then ``non_xhr_result`` should just be returned unmodified.

        """
        pyramid_request.is_xhr = False

        result = form.to_xhr_response(
            pyramid_request, mock.sentinel.non_xhr_result, mock.sentinel.form
        )

        assert result == mock.sentinel.non_xhr_result