示例#1
0
 def _(self):
     sr = StartResponse()
     x = app(new_env('GET', '/api/v1/books.json'), sr)
     ok(x) == [b'{"action":"index"}']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "18")]
     #
     sr = StartResponse()
     x = app(new_env('GET', '/api/v1/books/123.json'), sr)
     ok(x) == [b'{"action":"show","id":123}']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "26")]
     #
     sr = StartResponse()
     x = app(new_env('POST', '/api/v1/books/123/comments'), sr)
     ok(x) == [b'{"action":"create","book_id":123}']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "33")]
     #
     sr = StartResponse()
     x = app(new_env('PUT', '/api/v1/books/123/comments/abcd'), sr)
     ok(x) == [b'{"action":"update","book_id":123,"code":"abcd"}']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "47")]
     #
     sr = StartResponse()
     x = app(new_env('PUT', '/api/v1/orders/123.json'), sr)
     ok(x) == [b'{"action":"update","id":123}']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "28")]
示例#2
0
 def _(self):
     sr = StartResponse()
     x = app(new_env('HEAD', '/api/v1/books.json'), sr)
     ok(x) == [b'']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "18")]
     #
     sr = StartResponse()
     x = app(new_env('HEAD', '/api/v1/books/123.json'), sr)
     ok(x) == [b'']
     ok(sr.status) == "200 OK"
     ok(sr.headers) == [("Content-Type", "application/json"),
                        ("Content-Length", "26")]
示例#3
0
 def _(self):
     sr = StartResponse()
     x = app(new_env("POST", "/api/v1/books/123.json"), sr)
     ok(x) == [b'<h2>405 Method Not Allowed</h2>']
     ok(sr.status) == "405 Method Not Allowed"
     ok(sr.headers) == [("Content-Type", "text/html;charset=utf-8"),
                        ("Content-Length", "31")]
示例#4
0
 def _(self):
     sr = StartResponse()
     x = app(new_env("GET", "/api/v1/books/abc.json"), sr)
     ok(x) == [b'<h2>404 Not Found</h2>']
     ok(sr.status) == "404 Not Found"
     ok(sr.headers) == [("Content-Type", "text/html;charset=utf-8"),
                        ("Content-Length", "22")]
示例#5
0
 def _(self):
     sr = StartResponse()
     for meth in ("GET", "HEAD"):
         x = app(new_env(meth, "/api/v1/orders"), sr)
         ok(x) == [b'redirect to /api/v1/orders/']
         ok(sr.status) == "301 Moved Permanently"
         ok(sr.headers) == [("Content-Type",
                             "text/plain;charset=utf-8"),
                            ("Content-Length", "27"),
                            ("Location", "/api/v1/orders/")]
     #
     for meth in ("GET", "HEAD"):
         sr = StartResponse()
         x = app(new_env(meth, "/api/v1/orders/123/"), sr)
         ok(x) == [b'redirect to /api/v1/orders/123']
         ok(sr.status) == "301 Moved Permanently"
         ok(sr.headers) == [("Content-Type",
                             "text/plain;charset=utf-8"),
                            ("Content-Length", "30"),
                            ("Location", "/api/v1/orders/123")]
示例#6
0
 def provide_sr(self):
     return StartResponse()