Beispiel #1
0
def ws_testdata(tctx):
    tctx.server.address = ("example.com", 80)
    tctx.server.state = ConnectionState.OPEN
    flow = HTTPFlow(tctx.client, tctx.server)
    flow.request = Request.make("GET",
                                "http://example.com/",
                                headers={
                                    "Connection": "upgrade",
                                    "Upgrade": "websocket",
                                    "Sec-WebSocket-Version": "13",
                                })
    flow.response = Response.make(101,
                                  headers={
                                      "Connection": "upgrade",
                                      "Upgrade": "websocket",
                                  })
    return tctx, Playbook(websocket.WebsocketLayer(tctx, flow))
    def test_make(self):
        r = Response.make()
        assert r.status_code == 200
        assert r.content == b""

        r = Response.make(418, "teatime")
        assert r.status_code == 418
        assert r.content == b"teatime"
        assert r.headers["content-length"] == "7"

        Response.make(content=b"foo")
        Response.make(content="foo")
        with pytest.raises(TypeError):
            Response.make(content=42)

        r = Response.make(headers=[(b"foo", b"bar")])
        assert r.headers["foo"] == "bar"

        r = Response.make(headers=({"foo": "baz"}))
        assert r.headers["foo"] == "baz"

        with pytest.raises(TypeError):
            Response.make(headers=42)
Beispiel #3
0
    def test_make(self):
        r = Response.make()
        assert r.status_code == 200
        assert r.content == b""

        r = Response.make(418, "teatime")
        assert r.status_code == 418
        assert r.content == b"teatime"
        assert r.headers["content-length"] == "7"

        Response.make(content=b"foo")
        Response.make(content="foo")
        with pytest.raises(TypeError):
            Response.make(content=42)

        r = Response.make(headers=[(b"foo", b"bar")])
        assert r.headers["foo"] == "bar"

        r = Response.make(headers=({"foo": "baz"}))
        assert r.headers["foo"] == "baz"

        with pytest.raises(TypeError):
            Response.make(headers=42)
Beispiel #4
0
 def response_attribute_changer(self, response_meta_data: ResponseMetaData, response: Response):
     response.text = json.dumps(response_meta_data.body)