Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caucase
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
caucase
Commits
8af0b532
Commit
8af0b532
authored
Nov 04, 2017
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: Add low-level WSGI tests.
parent
1a10a495
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
caucase/test.py
caucase/test.py
+118
-0
No files found.
caucase/test.py
View file @
8af0b532
...
...
@@ -1582,5 +1582,123 @@ class CaucaseTest(unittest.TestCase):
finally
:
http
.
getBytePass
=
getBytePass_orig
def
testWSGIBase
(
self
):
"""
Low-level WSGI tests.
Not caucase-specific, but testing code which is part of caucase.
"""
def
run
(
request_line_list
,
app
=
noopApp
):
wfile
=
StringIO
()
http
.
CaucaseWSGIRequestHandler
(
FakeStreamRequest
(
StringIO
(
'
\
r
\
n
'
.
join
(
request_line_list
+
[
''
])),
NoCloseFileProxy
(
wfile
),
),
(
'0.0.0.0'
,
0
),
FakeAppServer
(
app
),
)
return
wfile
.
getvalue
().
splitlines
()
def
getStatus
(
response_line_list
):
version
,
code
,
reason
=
response_line_list
[
0
].
split
(
' '
,
2
)
return
int
(
code
)
def
getBody
(
response_line_list
):
return
'
\
r
\
n
'
.
join
(
response_line_list
[
response_line_list
.
index
(
''
)
+
1
:])
self
.
assertEqual
(
getStatus
(
run
([
'GET /'
+
'a'
*
65537
])),
414
,
)
expect_continue_request
=
[
'PUT / HTTP/1.1'
,
'Expect: 100-continue'
,
'Content-Length: 4'
,
'Content-Type: text/plain'
,
''
,
'Test'
,
]
# No read: 200 OK
self
.
assertEqual
(
getStatus
(
run
(
expect_continue_request
)),
200
,
)
# Read: 100 Continue (as first response, assume 200 OK happens later)
self
.
assertEqual
(
getStatus
(
run
(
expect_continue_request
,
readApp
)),
100
,
)
# HTTP/1.0: 200 OK
self
.
assertEqual
(
getStatus
(
run
(
[
'PUT / HTTP/1.0'
,
]
+
expect_continue_request
[
1
:],
readApp
,
)),
200
,
)
chunked_request
=
[
'PUT / HTTP/1.1'
,
'Transfer-Encoding: chunked'
,
''
,
'f;some=extension'
,
'123456789abcd
\
r
\
n
'
,
'3'
,
'ef0'
,
'0'
,
'X-Chunked-Trailer: blah'
]
self
.
assertEqual
(
getBody
(
run
(
chunked_request
,
readApp
)),
'123456789abcd
\
r
\
n
ef0'
,
)
class
FakeStreamRequest
(
object
):
"""
For testing StreamRequestHandler subclasses
(like http.CaucaseWSGIRequestHandler).
"""
def
__init__
(
self
,
rfile
,
wfile
):
"""
rfile & wfile: Both halves of emulated socket.
"""
self
.
_rfile
=
rfile
self
.
_wfile
=
wfile
def
makefile
(
self
,
mode
,
_
):
"""
Fake splitting the socket.
"""
return
self
.
_rfile
if
'r'
in
mode
else
self
.
_wfile
class
NoCloseFileProxy
(
object
):
def
__init__
(
self
,
real_file
):
self
.
_real_file
=
real_file
def
__getattr__
(
self
,
name
):
return
getattr
(
self
.
_real_file
,
name
)
def
close
(
self
):
pass
class
FakeAppServer
(
object
):
def
__init__
(
self
,
app
):
self
.
_app
=
app
self
.
base_environ
=
{}
def
get_app
(
self
):
return
self
.
_app
def
noopApp
(
environ
,
start_response
):
start_response
(
'200 OK'
,
[])
return
[]
def
readApp
(
environ
,
start_response
):
start_response
(
'200 OK'
,
[])
return
[
environ
[
'wsgi.input'
].
read
()]
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment