示例#1
0
    def test_basic_web(self):
        """
        Plain request, no params.
        """
        config = ComponentConfig(realm="realm1",
                                 extra={"subscriptions": [
                                     {"url": "https://foo.com/msg",
                                      "topic": "io.crossbar.forward1"}
                                 ]})

        m = MockWebTransport(self)
        m._addResponse(200, "whee")

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

        res = yield c.publish(u"io.crossbar.forward1", "hi",
                              options=PublishOptions(acknowledge=True))

        self.assertNotEqual(res.id, None)
        self.assertEqual(m.maderequest["args"], (b"POST", b"https://foo.com/msg"))
        self.assertEqual(m.maderequest["kwargs"], {
            "data": b'{"args":["hi"],"kwargs":{}}',
            "headers": Headers({b"Content-Type": [b"application/json"]})
        })
示例#2
0
    def test_basic_web(self):
        """
        Plain request, no params.
        """
        config = ComponentConfig(realm="realm1",
                                 extra={
                                     "baseurl": "https://foo.com/",
                                     "procedure": "io.crossbar.testrest"
                                 })

        m = MockWebTransport(self)
        m._addResponse(200, "whee")

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

        res = yield c.call(u"io.crossbar.testrest",
                           method="GET",
                           url="baz.html")

        self.assertEqual(m.maderequest["args"],
                         ("GET", "https://foo.com/baz.html"))
        self.assertEqual(m.maderequest["kwargs"], {
            "data": "",
            "headers": Headers({}),
            "params": {}
        })
        self.assertEqual(res, {
            "content": "whee",
            "code": 200,
            "headers": {
                "foo": ["bar"]
            }
        })
示例#3
0
    def test_basic_web(self):
        """
        Plain request, no params.
        """
        config = ComponentConfig(realm="realm1",
                                 extra={"subscriptions": [
                                     {"url": "https://foo.com/msg",
                                      "topic": "io.crossbar.forward1"}
                                 ]})

        m = MockWebTransport(self)
        m._addResponse(200, "whee")

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

        res = yield c.publish(u"io.crossbar.forward1", "hi",
                              options=PublishOptions(acknowledge=True))

        self.assertNotEqual(res.id, None)
        self.assertEqual(m.maderequest["args"], ("POST", "https://foo.com/msg"))
        self.assertEqual(m.maderequest["kwargs"], {
            "data": '{"args":["hi"],"kwargs":{}}',
            "headers": Headers({"Content-Type": ["application/json"]})
        })
示例#4
0
    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={"X-Something": ["baz"]})

        self.assertEqual(m.maderequest["args"], ("POST", "https://foo.com/baz.html"))
        self.assertEqual(m.maderequest["kwargs"], {
            "data": "see params",
            "headers": Headers({"X-Something": ["baz"]}),
            "params": {"spam": "ham"}
        })
        self.assertEqual(res,
                         {"content": "whee!",
                          "code": 220,
                          "headers": {"foo": ["bar"]}})
示例#5
0
    def test_basic_web(self):
        """
        Plain request, no params.
        """
        config = ComponentConfig(realm="realm1",
                                 extra={"baseurl": "https://foo.com/",
                                        "procedure": "io.crossbar.testrest"})

        m = MockWebTransport(self)
        m._addResponse(200, "whee")

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

        res = yield c.call(u"io.crossbar.testrest", method="GET", url="baz.html")

        self.assertEqual(m.maderequest["args"], ("GET", "https://foo.com/baz.html"))
        self.assertEqual(m.maderequest["kwargs"], {
            "data": "",
            "headers": Headers({}),
            "params": {}
        })
        self.assertEqual(res,
                         {"content": "whee",
                          "code": 200,
                          "headers": {"foo": ["bar"]}})
示例#6
0
    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={"X-Something": ["baz"]})

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