コード例 #1
0
ファイル: test_callee.py プロジェクト: yatskevich/crossbar
    def test_slightlymorecomplex_web(self):
        """
        Giving headers, params, a body.
        """
        config = ComponentConfig(realm="realm1",
                                 extra={
                                     "baseurl": "https://foo.com/",
                                     "procedure": "io.crossbar.testrest"
                                 })

        m = MockWebTransport(self)
        m._addResponse(220, "whee!")

        c = RESTCallee(config=config, webTransport=m)
        MockTransport(c)

        res = yield c.call(u"io.crossbar.testrest",
                           method="POST",
                           url="baz.html",
                           params={"spam": "ham"},
                           body="see params",
                           headers={b"X-Something": [b"baz"]})

        self.assertEqual(m.maderequest["args"],
                         (b"POST", b"https://foo.com/baz.html"))
        self.assertEqual(
            m.maderequest["kwargs"], {
                "data": b"see params",
                "headers": Headers({b"X-Something": [b"baz"]}),
                "params": {
                    "spam": "ham"
                }
            })
        self.assertEqual(res, {
            "content": "whee!",
            "code": 220,
            "headers": {
                "foo": ["bar"]
            }
        })