Esempio n. 1
0
    def testAssertStatus(self):
        STATUS = 500

        def status(environ, start_response):
            return Response("", status_int=STATUS)(environ, start_response)

        tc = testing.TestClient(pipeline=status)
        tc.get("/", status=STATUS)
Esempio n. 2
0
    def testDictToQs(self):
        def echo(environ, start_response):
            r = Request(environ)
            return Response(r.query_string)(environ, start_response)

        tc = testing.TestClient(pipeline=echo)
        TM = u"\u2122"
        d = MultiDict()
        d.add("a", 1)
        d.add("a", 2)
        d.add("a", 3)
        d.add("b", u"Nike %s" % TM)
        tc.get("/", query_string=d)
Esempio n. 3
0
    def testFiles(self):
        def echo(environ, start_response):
            r = Request(environ)
            return Response(r.body)(environ, start_response)

        tc = testing.TestClient(pipeline=echo)
        res = tc.post("/", files=dict(file1=("this.mp3", "i am music")))
        self.assertIn("this.mp3", res.body)

        with self.assertRaises(KeyError):
            tc.post("/",
                    post=dict(file1="xxx"),
                    files=dict(file1=("this.mp3", "i am music")))

        with self.assertRaises(ValueError):
            res = tc.post("/", files=dict(file1=("this.mp3")))
Esempio n. 4
0
    def testAutoRedirect(self):
        MSG = "you're here"

        def redir(environ, start_response):
            req = Request(environ)

            if req.path != "/x":
                return Response(status_int=302, headers={"Location":
                                                         "/x"})(environ,
                                                                start_response)
            else:
                return Response(MSG, status_int=200)(environ, start_response)

        tc = testing.TestClient(pipeline=redir, redirect=True)
        r = tc.get("/")
        self.assert_(MSG in r.body)
Esempio n. 5
0
    def testOtherMethods(self):
        def echo(environ, start_response):
            r = Request(environ)
            return Response(r.method)(environ, start_response)

        tc = testing.TestClient(pipeline=echo)
        r = tc.put("/")
        for m, f in dict(GET=tc.get,
                         PUT=tc.put,
                         POST=tc.post,
                         DELETE=tc.delete,
                         OPTIONS=tc.options).items():
            r = f("/")
            self.assert_(m in r.body, (r.body, m))

        r = tc.head("/")
        self.assert_(r.status_int == 200, r)