mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
forgot to commit tests
This commit is contained in:
parent
12612e1f34
commit
d4ae13cde0
165
tests/001-test-parser.py
Normal file
165
tests/001-test-parser.py
Normal file
@ -0,0 +1,165 @@
|
||||
import t
|
||||
|
||||
@t.request("001.http")
|
||||
def test_001(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
|
||||
t.eq(p.method, "PUT")
|
||||
t.eq(p.version, (1,0))
|
||||
t.eq(p.path, "/stuff/here")
|
||||
t.eq(p.query_string, "foo=bar")
|
||||
t.eq(sorted(p.headers), [
|
||||
('Content-Length', '14'),
|
||||
('Content-Type', 'application/json'),
|
||||
('Server', 'http://127.0.0.1:5984')
|
||||
])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, '{"nom": "nom"}')
|
||||
|
||||
@t.request("002.http")
|
||||
def test_002(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/test")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(sorted(p.headers), [
|
||||
("Accept", "*/*"),
|
||||
("Host", "0.0.0.0=5000"),
|
||||
("User-Agent", "curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1")
|
||||
])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
@t.request("003.http")
|
||||
def test_003(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/favicon.ico")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(sorted(p.headers), [
|
||||
("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
|
||||
("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"),
|
||||
("Accept-Encoding", "gzip,deflate"),
|
||||
("Accept-Language", "en-us,en;q=0.5"),
|
||||
("Connection", "keep-alive"),
|
||||
("Host", "0.0.0.0=5000"),
|
||||
("Keep-Alive", "300"),
|
||||
("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0"),
|
||||
])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
@t.request("004.http")
|
||||
def test_004(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/dumbfuck")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(p.headers, [("Aaaaaaaaaaaaa", "++++++++++")])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
|
||||
@t.request("005.http")
|
||||
def test_005(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/forums/1/topics/2375")
|
||||
t.eq(p.query_string, "page=1")
|
||||
|
||||
|
||||
t.eq(p.fragment, "posts-17408")
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
@t.request("006.http")
|
||||
def test_006(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/get_no_headers_no_body/world")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(p.fragment, "")
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
@t.request("007.http")
|
||||
def test_007(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/get_one_header_no_body")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(p.fragment, "")
|
||||
t.eq(p.headers, [('Accept', '*/*')])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "")
|
||||
|
||||
@t.request("008.http")
|
||||
def test_008(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "GET")
|
||||
t.eq(p.version, (1, 0))
|
||||
t.eq(p.path, "/get_funky_content_length_body_hello")
|
||||
t.eq(p.query_string, "")
|
||||
t.eq(p.fragment, "")
|
||||
t.eq(p.headers, [('Content-Length', '5')])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "HELLO")
|
||||
|
||||
@t.request("009.http")
|
||||
def test_009(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "POST")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/post_identity_body_world")
|
||||
t.eq(p.query_string, "q=search")
|
||||
t.eq(p.fragment, "hey")
|
||||
t.eq(sorted(p.headers), [
|
||||
('Accept', '*/*'),
|
||||
('Content-Length', '5'),
|
||||
('Transfer-Encoding', 'identity')
|
||||
])
|
||||
body, tr = p.filter_body(buf[i:])
|
||||
t.eq(body, "World")
|
||||
|
||||
@t.request("010.http")
|
||||
def test_010(buf, p):
|
||||
headers = []
|
||||
i = p.filter_headers(headers, buf)
|
||||
t.ne(i, -1)
|
||||
t.eq(p.method, "POST")
|
||||
t.eq(p.version, (1, 1))
|
||||
t.eq(p.path, "/post_chunked_all_your_base")
|
||||
t.eq(p.headers, [('Transfer-Encoding', 'chunked')])
|
||||
t.eq(p.is_chunked, True)
|
||||
body = ""
|
||||
buf = buf[i:]
|
||||
print buf
|
||||
while not p.body_eof():
|
||||
chunk, buf = p.filter_body(buf)
|
||||
body += chunk
|
||||
t.eq(body, "all your base are belong to us")
|
||||
6
tests/requests/001.http
Normal file
6
tests/requests/001.http
Normal file
@ -0,0 +1,6 @@
|
||||
PUT /stuff/here?foo=bar HTTP/1.0
|
||||
Server: http://127.0.0.1:5984
|
||||
Content-Type: application/json
|
||||
Content-Length: 14
|
||||
|
||||
{"nom": "nom"}
|
||||
5
tests/requests/002.http
Normal file
5
tests/requests/002.http
Normal file
@ -0,0 +1,5 @@
|
||||
GET /test HTTP/1.1
|
||||
User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1
|
||||
Host: 0.0.0.0=5000
|
||||
Accept: */*
|
||||
|
||||
10
tests/requests/003.http
Normal file
10
tests/requests/003.http
Normal file
@ -0,0 +1,10 @@
|
||||
GET /favicon.ico HTTP/1.1
|
||||
Host: 0.0.0.0=5000
|
||||
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0
|
||||
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
|
||||
Accept-Language: en-us,en;q=0.5
|
||||
Accept-Encoding: gzip,deflate
|
||||
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
|
||||
Keep-Alive: 300
|
||||
Connection: keep-alive
|
||||
|
||||
3
tests/requests/004.http
Normal file
3
tests/requests/004.http
Normal file
@ -0,0 +1,3 @@
|
||||
GET /dumbfuck HTTP/1.1
|
||||
aaaaaaaaaaaaa:++++++++++
|
||||
|
||||
2
tests/requests/005.http
Normal file
2
tests/requests/005.http
Normal file
@ -0,0 +1,2 @@
|
||||
GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1
|
||||
|
||||
2
tests/requests/006.http
Normal file
2
tests/requests/006.http
Normal file
@ -0,0 +1,2 @@
|
||||
GET /get_no_headers_no_body/world HTTP/1.1
|
||||
|
||||
3
tests/requests/007.http
Normal file
3
tests/requests/007.http
Normal file
@ -0,0 +1,3 @@
|
||||
GET /get_one_header_no_body HTTP/1.1
|
||||
Accept: */*
|
||||
|
||||
4
tests/requests/008.http
Normal file
4
tests/requests/008.http
Normal file
@ -0,0 +1,4 @@
|
||||
GET /get_funky_content_length_body_hello HTTP/1.0
|
||||
conTENT-Length: 5
|
||||
|
||||
HELLO
|
||||
6
tests/requests/009.http
Normal file
6
tests/requests/009.http
Normal file
@ -0,0 +1,6 @@
|
||||
POST /post_identity_body_world?q=search#hey HTTP/1.1
|
||||
Accept: */*
|
||||
Transfer-Encoding: identity
|
||||
Content-Length: 5
|
||||
|
||||
World
|
||||
6
tests/requests/010.http
Normal file
6
tests/requests/010.http
Normal file
@ -0,0 +1,6 @@
|
||||
POST /post_chunked_all_your_base HTTP/1.1
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
1e
|
||||
all your base are belong to us
|
||||
0
|
||||
8
tests/requests/011.http
Normal file
8
tests/requests/011.http
Normal file
@ -0,0 +1,8 @@
|
||||
POST /two_chunks_mult_zero_end HTTP/1.1
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
5
|
||||
hello
|
||||
6
|
||||
world
|
||||
000
|
||||
10
tests/requests/012.http
Normal file
10
tests/requests/012.http
Normal file
@ -0,0 +1,10 @@
|
||||
POST /chunked_w_trailing_headers HTTP/1.1
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
5
|
||||
hello
|
||||
6
|
||||
world
|
||||
0
|
||||
Vary: *
|
||||
Content-Type: text/plain
|
||||
8
tests/requests/013.http
Normal file
8
tests/requests/013.http
Normal file
@ -0,0 +1,8 @@
|
||||
POST /chunked_w_bullshit_after_length HTTP/1.1
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
5; some; parameters=stuff
|
||||
hello
|
||||
6; blahblah; blah
|
||||
world
|
||||
0
|
||||
2
tests/requests/014.http
Normal file
2
tests/requests/014.http
Normal file
@ -0,0 +1,2 @@
|
||||
GET /with_"stupid"_quotes?foo="bar" HTTP/1.1
|
||||
|
||||
5
tests/requests/015.http
Normal file
5
tests/requests/015.http
Normal file
@ -0,0 +1,5 @@
|
||||
GET /test HTTP/1.0
|
||||
Host: 0.0.0.0:5000
|
||||
User-Agent: ApacheBench/2.3
|
||||
Accept: */*
|
||||
|
||||
33
tests/requests/016.http
Normal file
33
tests/requests/016.http
Normal file
@ -0,0 +1,33 @@
|
||||
GET / HTTP/1.1
|
||||
X-SSL-Bullshit: -----BEGIN CERTIFICATE-----
|
||||
MIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx
|
||||
ETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT
|
||||
AkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu
|
||||
dWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV
|
||||
SzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzAJBgNV
|
||||
BAcTmrsogriqMWLAk1DMRcwFQYDVQQDEw5taWNoYWVsIHBhcmQYJKoZIhvcNAQEB
|
||||
BQADggEPADCCAQoCggEBANPEQBgl1IaKdSS1TbhF3hEXSl72G9J+WC/1R64fAcEF
|
||||
W51rEyFYiIeZGx/BVzwXbeBoNUK41OK65sxGuflMo5gLflbwJtHBRIEKAfVVp3YR
|
||||
gW7cMA/s/XKgL1GEC7rQw8lIZT8RApukCGqOVHSi/F1SiFlPDxuDfmdiNzL31+sL
|
||||
0iwHDdNkGjy5pyBSB8Y79dsSJtCW/iaLB0/n8Sj7HgvvZJ7x0fr+RQjYOUUfrePP
|
||||
u2M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QyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk
|
||||
hTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK
|
||||
wTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu
|
||||
Yhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3
|
||||
RA==
|
||||
-----END CERTIFICATE-----
|
||||
15
tests/responses/001.http
Normal file
15
tests/responses/001.http
Normal file
@ -0,0 +1,15 @@
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
Location: http://www.google.com/
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Date: Sun, 26 Apr 2009 11:11:49 GMT
|
||||
Expires: Tue, 26 May 2009 11:11:49 GMT
|
||||
Cache-Control: public, max-age=2592000
|
||||
Server: gws
|
||||
Content-Length: 219
|
||||
|
||||
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
|
||||
<TITLE>301 Moved</TITLE></HEAD><BODY>
|
||||
<H1>301 Moved</H1>
|
||||
The document has moved
|
||||
<A HREF="http://www.google.com/">here</A>.
|
||||
</BODY></HTML>
|
||||
16
tests/responses/002.http
Normal file
16
tests/responses/002.http
Normal file
@ -0,0 +1,16 @@
|
||||
HTTP/1.1 200 OK
|
||||
Date: Tue, 04 Aug 2009 07:59:32 GMT
|
||||
Server: Apache
|
||||
X-Powered-By: Servlet/2.5 JSP/2.1
|
||||
Content-Type: text/xml; charset=utf-8
|
||||
Connection: close
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<SOAP-ENV:Body>
|
||||
<SOAP-ENV:Fault>
|
||||
<faultcode>SOAP-ENV:Client</faultcode>
|
||||
<faultstring>Client Error</faultstring>
|
||||
</SOAP-ENV:Fault>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
2
tests/responses/003.http
Normal file
2
tests/responses/003.http
Normal file
@ -0,0 +1,2 @@
|
||||
HTTP/1.1 404 Not Found
|
||||
|
||||
2
tests/responses/004.http
Normal file
2
tests/responses/004.http
Normal file
@ -0,0 +1,2 @@
|
||||
HTTP/1.1 301
|
||||
|
||||
11
tests/responses/005.http
Normal file
11
tests/responses/005.http
Normal file
@ -0,0 +1,11 @@
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/plain
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
25
|
||||
This is the data in the first chunk
|
||||
|
||||
1C
|
||||
and this is the second one
|
||||
|
||||
0
|
||||
5
tests/responses/006.http
Normal file
5
tests/responses/006.http
Normal file
@ -0,0 +1,5 @@
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Connection: close
|
||||
|
||||
these headers are from http://news.ycombinator.com/
|
||||
7
tests/responses/007.http
Normal file
7
tests/responses/007.http
Normal file
@ -0,0 +1,7 @@
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 11
|
||||
Proxy-Connection: close
|
||||
Date: Thu, 31 Dec 2009 20:55:48 +0000
|
||||
|
||||
hello world
|
||||
70
tests/t.py
Normal file
70
tests/t.py
Normal file
@ -0,0 +1,70 @@
|
||||
# Copyright 2009 Paul J. Davis <paul.joseph.davis@gmail.com>
|
||||
#
|
||||
# This file is part of the pywebmachine package released
|
||||
# under the MIT license.
|
||||
import inspect
|
||||
import os
|
||||
import re
|
||||
import unittest
|
||||
|
||||
from gunicorn.http import HttpParser
|
||||
|
||||
dirname = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def data_source(fname, eol):
|
||||
with open(fname) as handle:
|
||||
lines = []
|
||||
for line in handle:
|
||||
next = line.rstrip("\r\n") + eol
|
||||
if next == "\r\n":
|
||||
eol = ""
|
||||
lines.append(next)
|
||||
return "".join(lines)
|
||||
|
||||
class request(object):
|
||||
def __init__(self, name, eol="\r\n"):
|
||||
self.fname = os.path.join(dirname, "requests", name)
|
||||
self.eol = eol
|
||||
|
||||
def __call__(self, func):
|
||||
def run():
|
||||
src = data_source(self.fname, self.eol)
|
||||
func(src, HttpParser())
|
||||
run.func_name = func.func_name
|
||||
return run
|
||||
|
||||
def eq(a, b):
|
||||
assert a == b, "%r != %r" % (a, b)
|
||||
|
||||
def ne(a, b):
|
||||
assert a != b, "%r == %r" % (a, b)
|
||||
|
||||
def lt(a, b):
|
||||
assert a < b, "%r >= %r" % (a, b)
|
||||
|
||||
def gt(a, b):
|
||||
assert a > b, "%r <= %r" % (a, b)
|
||||
|
||||
def isin(a, b):
|
||||
assert a in b, "%r is not in %r" % (a, b)
|
||||
|
||||
def isnotin(a, b):
|
||||
assert a not in b, "%r is in %r" % (a, b)
|
||||
|
||||
def has(a, b):
|
||||
assert hasattr(a, b), "%r has no attribute %r" % (a, b)
|
||||
|
||||
def hasnot(a, b):
|
||||
assert not hasattr(a, b), "%r has an attribute %r" % (a, b)
|
||||
|
||||
def raises(exctype, func, *args, **kwargs):
|
||||
try:
|
||||
func(*args, **kwargs)
|
||||
except exctype, inst:
|
||||
pass
|
||||
else:
|
||||
func_name = getattr(func, "func_name", "<builtin_function>")
|
||||
raise AssertionError("Function %s did not raise %s" % (
|
||||
func_name, exctype.__name__))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user