예제 #1
0
    def test_register_protocol(self):
        wsme.protocol.register_protocol(DummyProtocol)
        assert wsme.protocol.registered_protocols["dummy"] == DummyProtocol

        r = WSRoot()
        assert len(r.protocols) == 0

        r.addprotocol("dummy")
        assert len(r.protocols) == 1
        assert r.protocols[0].__class__ == DummyProtocol

        r = WSRoot(["dummy"])
        assert len(r.protocols) == 1
        assert r.protocols[0].__class__ == DummyProtocol
예제 #2
0
    def test_register_protocol(self):
        wsme.protocol.register_protocol(DummyProtocol)
        assert wsme.protocol.registered_protocols['dummy'] == DummyProtocol

        r = WSRoot()
        assert len(r.protocols) == 0

        r.addprotocol('dummy')
        assert len(r.protocols) == 1
        assert r.protocols[0].__class__ == DummyProtocol

        r = WSRoot(['dummy'])
        assert len(r.protocols) == 1
        assert r.protocols[0].__class__ == DummyProtocol
예제 #3
0
파일: test_root.py 프로젝트: Kjir/wsme
    def test_protocol_selection_get_method(self):
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return True

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'GET'
        req.headers['Accept'] = 'test/fake'
        p = root._select_protocol(req)
        assert p.name == "test"
예제 #4
0
    def test_protocol_selection_get_method(self):
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return True

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'GET'
        req.headers['Accept'] = 'test/fake'
        p = root._select_protocol(req)
        assert p.name == "test"
예제 #5
0
    def test_protocol_selection_error(self):
        import wsme.protocol

        class P(wsme.protocol.Protocol):
            def accept(self, r):
                raise Exception('test')

        root = WSRoot()
        root.addprotocol(P())

        from webob import Request
        req = Request.blank('/test?check=a&check=b&name=Bob')
        res = root._handle_request(req)
        assert res.status_int == 500
        assert res.content_type == 'text/plain'
        assert res.text == u('Error while selecting protocol: test'), req.text
예제 #6
0
파일: test_root.py 프로젝트: Kjir/wsme
    def test_protocol_selection_accept_mismatch(self):
        """Verify that we get a 406 error on wrong Accept header."""
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return False

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'GET'
        res = root._handle_request(req)
        assert res.status_int == 406
        assert res.content_type == 'text/plain'
        assert res.text.startswith(
            'None of the following protocols can handle this request'
        ), req.text
예제 #7
0
    def test_protocol_selection_content_type_mismatch(self):
        """Verify that we get a 415 error on wrong Content-Type header."""
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return False

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'POST'
        req.headers['Content-Type'] = "test/unsupported"
        res = root._handle_request(req)
        assert res.status_int == 415
        assert res.content_type == 'text/plain'
        assert res.text.startswith(
            'Unacceptable Content-Type: test/unsupported not in'), req.text
예제 #8
0
    def test_protocol_selection_accept_mismatch(self):
        """Verify that we get a 406 error on wrong Accept header."""
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return False

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'GET'
        res = root._handle_request(req)
        assert res.status_int == 406
        assert res.content_type == 'text/plain'
        assert res.text.startswith(
            'None of the following protocols can handle this request'
        ), req.text
예제 #9
0
파일: test_root.py 프로젝트: Kjir/wsme
    def test_protocol_selection_content_type_mismatch(self):
        """Verify that we get a 415 error on wrong Content-Type header."""
        class P(wsme.protocol.Protocol):
            name = "test"

            def accept(self, r):
                return False

        root = WSRoot()
        root.addprotocol(wsme.rest.protocol.RestProtocol())
        root.addprotocol(P())

        req = Request.blank('/test?check=a&check=b&name=Bob')
        req.method = 'POST'
        req.headers['Content-Type'] = "test/unsupported"
        res = root._handle_request(req)
        assert res.status_int == 415
        assert res.content_type == 'text/plain'
        assert res.text.startswith(
            'Unacceptable Content-Type: test/unsupported not in'
        ), req.text