Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8d5c5603
Commit
8d5c5603
authored
Jul 22, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flake8
parent
a1f87de3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
41 deletions
+48
-41
src/ZPublisher/tests/test_WSGIPublisher.py
src/ZPublisher/tests/test_WSGIPublisher.py
+48
-41
No files found.
src/ZPublisher/tests/test_WSGIPublisher.py
View file @
8d5c5603
...
@@ -48,7 +48,7 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -48,7 +48,7 @@ class WSGIResponseTests(unittest.TestCase):
response
.
finalize
()
response
.
finalize
()
self
.
assertEqual
(
response
.
getHeader
(
'Content-Length'
),
'7'
)
self
.
assertEqual
(
response
.
getHeader
(
'Content-Length'
),
'7'
)
def
test_finalize_skips_
setting_
content_length_if_missing_w_streaming
(
self
):
def
test_finalize_skips_content_length_if_missing_w_streaming
(
self
):
response
=
self
.
_makeOne
()
response
=
self
.
_makeOne
()
response
.
_streaming
=
True
response
.
_streaming
=
True
response
.
body
=
'TESTING'
response
.
body
=
'TESTING'
...
@@ -85,7 +85,7 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -85,7 +85,7 @@ class WSGIResponseTests(unittest.TestCase):
from
ZPublisher.Iterators
import
IUnboundStreamIterator
from
ZPublisher.Iterators
import
IUnboundStreamIterator
from
zope.interface
import
implements
from
zope.interface
import
implements
class
test_streamiterator
:
class
TestStreamIterator
(
object
)
:
implements
(
IUnboundStreamIterator
)
implements
(
IUnboundStreamIterator
)
data
=
"hello"
data
=
"hello"
done
=
0
done
=
0
...
@@ -98,7 +98,7 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -98,7 +98,7 @@ class WSGIResponseTests(unittest.TestCase):
response
=
self
.
_makeOne
()
response
=
self
.
_makeOne
()
response
.
setStatus
(
200
)
response
.
setStatus
(
200
)
body
=
test_streami
terator
()
body
=
TestStreamI
terator
()
response
.
setBody
(
body
)
response
.
setBody
(
body
)
response
.
finalize
()
response
.
finalize
()
self
.
assertTrue
(
body
is
response
.
body
)
self
.
assertTrue
(
body
is
response
.
body
)
...
@@ -108,7 +108,7 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -108,7 +108,7 @@ class WSGIResponseTests(unittest.TestCase):
from
ZPublisher.Iterators
import
IStreamIterator
from
ZPublisher.Iterators
import
IStreamIterator
from
zope.interface
import
implements
from
zope.interface
import
implements
class
test_streamiterator
:
class
TestStreamIterator
(
object
)
:
implements
(
IStreamIterator
)
implements
(
IStreamIterator
)
data
=
"hello"
data
=
"hello"
done
=
0
done
=
0
...
@@ -124,13 +124,13 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -124,13 +124,13 @@ class WSGIResponseTests(unittest.TestCase):
response
=
self
.
_makeOne
()
response
=
self
.
_makeOne
()
response
.
setStatus
(
200
)
response
.
setStatus
(
200
)
body
=
test_streami
terator
()
body
=
TestStreamI
terator
()
response
.
setBody
(
body
)
response
.
setBody
(
body
)
response
.
finalize
()
response
.
finalize
()
self
.
assertTrue
(
body
is
response
.
body
)
self
.
assertTrue
(
body
is
response
.
body
)
self
.
assertEqual
(
response
.
_streaming
,
0
)
self
.
assertEqual
(
response
.
_streaming
,
0
)
self
.
assertEqual
(
response
.
getHeader
(
'Content-Length'
),
self
.
assertEqual
(
response
.
getHeader
(
'Content-Length'
),
'%d'
%
len
(
test_streami
terator
.
data
))
'%d'
%
len
(
TestStreamI
terator
.
data
))
def
test___str___raises
(
self
):
def
test___str___raises
(
self
):
response
=
self
.
_makeOne
()
response
=
self
.
_makeOne
()
...
@@ -138,7 +138,7 @@ class WSGIResponseTests(unittest.TestCase):
...
@@ -138,7 +138,7 @@ class WSGIResponseTests(unittest.TestCase):
self
.
assertRaises
(
NotImplementedError
,
lambda
:
str
(
response
))
self
.
assertRaises
(
NotImplementedError
,
lambda
:
str
(
response
))
class
Test
_p
ublish
(
unittest
.
TestCase
):
class
Test
P
ublish
(
unittest
.
TestCase
):
def
_callFUT
(
self
,
request
,
module_name
,
_get_module_info
=
None
):
def
_callFUT
(
self
,
request
,
module_name
,
_get_module_info
=
None
):
from
ZPublisher.WSGIPublisher
import
publish
from
ZPublisher.WSGIPublisher
import
publish
...
@@ -204,7 +204,7 @@ class Test_publish(unittest.TestCase):
...
@@ -204,7 +204,7 @@ class Test_publish(unittest.TestCase):
self
.
assertEqual
(
response
.
realm
,
None
)
self
.
assertEqual
(
response
.
realm
,
None
)
class
Test
_publish_m
odule
(
unittest
.
TestCase
):
class
Test
PublishM
odule
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
from
zope.testing.cleanup
import
cleanUp
from
zope.testing.cleanup
import
cleanUp
...
@@ -245,16 +245,16 @@ class Test_publish_module(unittest.TestCase):
...
@@ -245,16 +245,16 @@ class Test_publish_module(unittest.TestCase):
def
_makeEnviron
(
self
,
**
kw
):
def
_makeEnviron
(
self
,
**
kw
):
from
StringIO
import
StringIO
from
StringIO
import
StringIO
environ
=
{
environ
=
{
'SCRIPT_NAME'
:
''
,
'SCRIPT_NAME'
:
''
,
'REQUEST_METHOD'
:
'GET'
,
'REQUEST_METHOD'
:
'GET'
,
'QUERY_STRING'
:
''
,
'QUERY_STRING'
:
''
,
'SERVER_NAME'
:
'127.0.0.1'
,
'SERVER_NAME'
:
'127.0.0.1'
,
'REMOTE_ADDR'
:
'127.0.0.1'
,
'REMOTE_ADDR'
:
'127.0.0.1'
,
'wsgi.url_scheme'
:
'http'
,
'wsgi.url_scheme'
:
'http'
,
'SERVER_PORT'
:
'8080'
,
'SERVER_PORT'
:
'8080'
,
'HTTP_HOST'
:
'127.0.0.1:8080'
,
'HTTP_HOST'
:
'127.0.0.1:8080'
,
'SERVER_PROTOCOL'
:
'HTTP/1.1'
,
'SERVER_PROTOCOL'
:
'HTTP/1.1'
,
'wsgi.input'
:
StringIO
(
''
),
'wsgi.input'
:
StringIO
(
''
),
'CONTENT_LENGTH'
:
'0'
,
'CONTENT_LENGTH'
:
'0'
,
'HTTP_CONNECTION'
:
'keep-alive'
,
'HTTP_CONNECTION'
:
'keep-alive'
,
'CONTENT_TYPE'
:
''
'CONTENT_TYPE'
:
''
...
@@ -338,11 +338,14 @@ class Test_publish_module(unittest.TestCase):
...
@@ -338,11 +338,14 @@ class Test_publish_module(unittest.TestCase):
self
.
assertEqual
(
kw
,
{})
self
.
assertEqual
(
kw
,
{})
def
test_response_body_is_file
(
self
):
def
test_response_body_is_file
(
self
):
class
DummyFile
(
file
):
class
DummyFile
(
file
):
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
def
read
(
self
,
*
args
,
**
kw
):
def
read
(
self
,
*
args
,
**
kw
):
raise
NotImplementedError
()
raise
NotImplementedError
()
_response
=
DummyResponse
()
_response
=
DummyResponse
()
_response
.
_status
=
'200 OK'
_response
.
_status
=
'200 OK'
_response
.
_headers
=
[(
'Content-Length'
,
'4'
)]
_response
.
_headers
=
[(
'Content-Length'
,
'4'
)]
...
@@ -358,7 +361,7 @@ class Test_publish_module(unittest.TestCase):
...
@@ -358,7 +361,7 @@ class Test_publish_module(unittest.TestCase):
from
ZPublisher.Iterators
import
IStreamIterator
from
ZPublisher.Iterators
import
IStreamIterator
from
zope.interface
import
implements
from
zope.interface
import
implements
class
test_streamiterator
:
class
TestStreamIterator
(
object
)
:
implements
(
IStreamIterator
)
implements
(
IStreamIterator
)
data
=
"hello"
data
=
"hello"
done
=
0
done
=
0
...
@@ -372,7 +375,7 @@ class Test_publish_module(unittest.TestCase):
...
@@ -372,7 +375,7 @@ class Test_publish_module(unittest.TestCase):
_response
=
DummyResponse
()
_response
=
DummyResponse
()
_response
.
_status
=
'200 OK'
_response
.
_status
=
'200 OK'
_response
.
_headers
=
[(
'Content-Length'
,
'4'
)]
_response
.
_headers
=
[(
'Content-Length'
,
'4'
)]
body
=
_response
.
body
=
test_streami
terator
()
body
=
_response
.
body
=
TestStreamI
terator
()
environ
=
self
.
_makeEnviron
()
environ
=
self
.
_makeEnviron
()
start_response
=
DummyCallable
()
start_response
=
DummyCallable
()
_publish
=
DummyCallable
()
_publish
=
DummyCallable
()
...
@@ -384,7 +387,7 @@ class Test_publish_module(unittest.TestCase):
...
@@ -384,7 +387,7 @@ class Test_publish_module(unittest.TestCase):
from
ZPublisher.Iterators
import
IUnboundStreamIterator
from
ZPublisher.Iterators
import
IUnboundStreamIterator
from
zope.interface
import
implements
from
zope.interface
import
implements
class
test_unboundstreamiterator
:
class
TestUnboundStreamIterator
(
object
)
:
implements
(
IUnboundStreamIterator
)
implements
(
IUnboundStreamIterator
)
data
=
"hello"
data
=
"hello"
done
=
0
done
=
0
...
@@ -397,7 +400,7 @@ class Test_publish_module(unittest.TestCase):
...
@@ -397,7 +400,7 @@ class Test_publish_module(unittest.TestCase):
_response
=
DummyResponse
()
_response
=
DummyResponse
()
_response
.
_status
=
'200 OK'
_response
.
_status
=
'200 OK'
body
=
_response
.
body
=
test_unboundstreami
terator
()
body
=
_response
.
body
=
TestUnboundStreamI
terator
()
environ
=
self
.
_makeEnviron
()
environ
=
self
.
_makeEnviron
()
start_response
=
DummyCallable
()
start_response
=
DummyCallable
()
_publish
=
DummyCallable
()
_publish
=
DummyCallable
()
...
@@ -410,14 +413,16 @@ class Test_publish_module(unittest.TestCase):
...
@@ -410,14 +413,16 @@ class Test_publish_module(unittest.TestCase):
start_response
=
DummyCallable
()
start_response
=
DummyCallable
()
_request
=
DummyRequest
()
_request
=
DummyRequest
()
_request
.
_closed
=
False
_request
.
_closed
=
False
def
_close
():
def
_close
():
_request
.
_closed
=
True
_request
.
_closed
=
True
_request
.
close
=
_close
_request
.
close
=
_close
def
_request_factory
(
stdin
,
environ
,
response
):
def
_request_factory
(
stdin
,
environ
,
response
):
return
_request
return
_request
_publish
=
DummyCallable
()
_publish
=
DummyCallable
()
_publish
.
_result
=
DummyResponse
()
_publish
.
_result
=
DummyResponse
()
app_iter
=
self
.
_callFUT
(
environ
,
start_response
,
_publish
,
self
.
_callFUT
(
environ
,
start_response
,
_publish
,
_request_factory
=
_request_factory
)
_request_factory
=
_request_factory
)
self
.
assertTrue
(
_request
.
_closed
)
self
.
assertTrue
(
_request
.
_closed
)
...
@@ -429,21 +434,25 @@ class Test_publish_module(unittest.TestCase):
...
@@ -429,21 +434,25 @@ class Test_publish_module(unittest.TestCase):
start_response
=
DummyCallable
()
start_response
=
DummyCallable
()
_request
=
DummyRequest
()
_request
=
DummyRequest
()
_request
.
_closed
=
False
_request
.
_closed
=
False
def
_close
():
def
_close
():
_request
.
_closed
=
True
_request
.
_closed
=
True
_request
.
close
=
_close
_request
.
close
=
_close
def
_request_factory
(
stdin
,
environ
,
response
):
def
_request_factory
(
stdin
,
environ
,
response
):
return
_request
return
_request
_publish
=
DummyCallable
()
_publish
=
DummyCallable
()
_publish
.
_result
=
DummyResponse
()
_publish
.
_result
=
DummyResponse
()
app_iter
=
self
.
_callFUT
(
environ
,
start_response
,
_publish
,
self
.
_callFUT
(
environ
,
start_response
,
_publish
,
_request_factory
=
_request_factory
)
_request_factory
=
_request_factory
)
self
.
assertFalse
(
_request
.
_closed
)
self
.
assertFalse
(
_request
.
_closed
)
txn
=
transaction
.
get
()
txn
=
transaction
.
get
()
self
.
assertTrue
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
self
.
assertTrue
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
txn
.
commit
()
txn
.
commit
()
self
.
assertTrue
(
_request
.
_closed
)
self
.
assertTrue
(
_request
.
_closed
)
self
.
assertFalse
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
self
.
assertFalse
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
# try again, but this time raise an exception and abort
# try again, but this time raise an exception and abort
_request
.
_closed
=
False
_request
.
_closed
=
False
_publish
.
_raise
=
Exception
(
'oops'
)
_publish
.
_raise
=
Exception
(
'oops'
)
...
@@ -452,9 +461,11 @@ class Test_publish_module(unittest.TestCase):
...
@@ -452,9 +461,11 @@ class Test_publish_module(unittest.TestCase):
_request_factory
=
_request_factory
)
_request_factory
=
_request_factory
)
self
.
assertFalse
(
_request
.
_closed
)
self
.
assertFalse
(
_request
.
_closed
)
txn
=
transaction
.
get
()
txn
=
transaction
.
get
()
self
.
assertTrue
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
self
.
assertTrue
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
txn
.
abort
()
txn
.
abort
()
self
.
assertFalse
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
self
.
assertFalse
(
txn
in
WSGIPublisher
.
_request_closer_for_repoze_tm
.
requests
)
self
.
assertTrue
(
_request
.
_closed
)
self
.
assertTrue
(
_request
.
_closed
)
...
@@ -471,6 +482,7 @@ class DummyRequest(dict):
...
@@ -471,6 +482,7 @@ class DummyRequest(dict):
self
.
_traversed
=
(
path
,
response
,
validated_hook
)
self
.
_traversed
=
(
path
,
response
,
validated_hook
)
return
self
.
_traverse_to
return
self
.
_traverse_to
class
DummyResponse
(
object
):
class
DummyResponse
(
object
):
debug_mode
=
False
debug_mode
=
False
after_list
=
()
after_list
=
()
...
@@ -489,6 +501,7 @@ class DummyResponse(object):
...
@@ -489,6 +501,7 @@ class DummyResponse(object):
body
=
property
(
lambda
self
:
self
.
_body
,
setBody
)
body
=
property
(
lambda
self
:
self
.
_body
,
setBody
)
class
DummyCallable
(
object
):
class
DummyCallable
(
object
):
_called_with
=
_raise
=
_result
=
None
_called_with
=
_raise
=
_result
=
None
...
@@ -498,19 +511,13 @@ class DummyCallable(object):
...
@@ -498,19 +511,13 @@ class DummyCallable(object):
raise
self
.
_raise
raise
self
.
_raise
return
self
.
_result
return
self
.
_result
class
DummyTM
(
object
):
class
DummyTM
(
object
):
_recorded
=
_raise
=
_result
=
None
_recorded
=
_raise
=
_result
=
None
def
recordMetaData
(
self
,
*
args
):
def
recordMetaData
(
self
,
*
args
):
self
.
_recorded
=
args
self
.
_recorded
=
args
def
noopStartResponse
(
status
,
headers
):
def
noopStartResponse
(
status
,
headers
):
pass
pass
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
WSGIResponseTests
),
unittest
.
makeSuite
(
Test_publish
),
unittest
.
makeSuite
(
Test_publish_module
),
))
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