示例#1
0
    def test_it_does_not_modify_context_if_accept_not_set(
            self, pyramid_request, testview):
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert context == fake_context
示例#2
0
    def test_it_does_not_modify_context_if_accept_not_set(
        self, pyramid_request, testview
    ):
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert context == fake_context
示例#3
0
    def test_it_does_not_modify_context_if_any_accept_values_ok(
            self, pyramid_request, testview):
        # At least one of these is valid
        pyramid_request.accept = MIMEAccept("application/json, foo/bar")
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert context == fake_context
示例#4
0
    def test_it_replaces_context_with_406_if_accept_set_and_invalid(
            self, pyramid_request, testview):
        # None of these is valid
        pyramid_request.accept = create_accept_header(
            "application/something+json, foo/bar")
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert isinstance(context, HTTPNotAcceptable)
示例#5
0
    def test_it_replaces_context_with_415_if_accept_set_and_invalid(
        self, pyramid_request, testview
    ):
        # None of these is valid
        pyramid_request.accept = MIMEAccept("application/something+json, foo/bar")
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert isinstance(context, HTTPUnsupportedMediaType)
示例#6
0
    def test_it_does_not_modify_context_if_any_accept_values_ok(
        self, pyramid_request, testview
    ):
        # At least one of these is valid
        pyramid_request.accept = MIMEAccept("application/json, foo/bar")
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert context == fake_context
示例#7
0
    def test_it_replaces_context_with_415_if_accept_set_and_invalid(
            self, pyramid_request, testview):
        # None of these is valid
        pyramid_request.accept = MIMEAccept(
            "application/something+json, foo/bar")
        fake_context = mock.Mock()
        validate_media_types(testview)(fake_context, pyramid_request)

        context, _ = testview.call_args[0]
        assert isinstance(context, HTTPUnsupportedMediaType)
示例#8
0
    def test_it_calls_wrapped_view_function(self, pyramid_request, testview):
        validate_media_types(testview)(None, pyramid_request)

        assert testview.called
示例#9
0
    def test_it_calls_wrapped_view_function(self, pyramid_request, testview):
        validate_media_types(testview)(None, pyramid_request)

        assert testview.called