Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #8
0
    def test_it_calls_wrapped_view_function(self, pyramid_request, testview):
        validate_media_types(testview)(None, pyramid_request)

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

        assert testview.called