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
c92eb929
Commit
c92eb929
authored
Sep 03, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup, avoid duplicated imports in tests for external dependencies.
parent
26370f24
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
72 additions
and
129 deletions
+72
-129
src/OFS/tests/testFileAndImage.py
src/OFS/tests/testFileAndImage.py
+0
-14
src/Products/Five/browser/tests/test_i18n.py
src/Products/Five/browser/tests/test_i18n.py
+5
-8
src/Testing/ZopeTestCase/zopedoctest/FunctionalDocTest.txt
src/Testing/ZopeTestCase/zopedoctest/FunctionalDocTest.txt
+20
-14
src/Testing/ZopeTestCase/zopedoctest/functional.py
src/Testing/ZopeTestCase/zopedoctest/functional.py
+6
-5
src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
...Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
+3
-2
src/Testing/tests/test_testbrowser.py
src/Testing/tests/test_testbrowser.py
+2
-2
src/ZPublisher/HTTPResponse.py
src/ZPublisher/HTTPResponse.py
+3
-3
src/ZPublisher/WSGIPublisher.py
src/ZPublisher/WSGIPublisher.py
+2
-3
src/ZPublisher/__init__.py
src/ZPublisher/__init__.py
+10
-1
src/ZPublisher/tests/testBaseRequest.py
src/ZPublisher/tests/testBaseRequest.py
+2
-19
src/ZPublisher/tests/testHTTPRequest.py
src/ZPublisher/tests/testHTTPRequest.py
+8
-37
src/ZPublisher/tests/testHTTPResponse.py
src/ZPublisher/tests/testHTTPResponse.py
+11
-21
No files found.
src/OFS/tests/testFileAndImage.py
View file @
c92eb929
import
unittest
import
Testing
import
Zope2
import
os
...
...
@@ -286,16 +285,3 @@ class ImageTests(FileTests):
from
OFS.interfaces
import
IWriteLock
verifyClass
(
IWriteLock
,
Image
)
class
ImagePublishTests
(
Testing
.
ZopeTestCase
.
FunctionalTestCase
):
def
testTagSafe
(
self
):
self
.
app
.
manage_addImage
(
"image"
,
""
)
res
=
self
.
publish
(
"/image/tag?height=0&width=0&css_class=%22%3E%3Cscript%20type"
"%3D%22text%2Fjavascript%22%3Ealert('evil')%3B%3C%2Fscript"
"%3E%3Cdiv%20class%3D%22"
)
self
.
assertFalse
(
'<script type="text/javascript">alert(
\
'
evil
\
'
);</script>'
in
res
.
getBody
())
src/Products/Five/browser/tests/test_i18n.py
View file @
c92eb929
...
...
@@ -54,14 +54,12 @@ def test_zpt_i18n():
``Accept-Language`` header which is processed by the
``IUserPreferredLangauges`` adapter:
>>> print
http(r'''
>>> print
(
http(r'''
... GET /test_folder_1_/testoid/@@i18n.html HTTP/1.1
... Accept-Language: de
... ''')
... ''')
)
HTTP/1.1 200 OK
...
<html>
<body>
<p>Dies ist eine Nachricht</p>
<p>Dies ist eine explizite Nachricht</p>
<p>Dies sind 4 Nachrichten</p>
...
...
@@ -72,8 +70,6 @@ def test_zpt_i18n():
</table>
<p>Dies ist eine Nachricht</p>
<p>Dies ist eine Nachricht</p>
</body>
</html>
...
...
...
@@ -86,5 +82,6 @@ def test_zpt_i18n():
def
test_suite
():
from
Testing.ZopeTestCase
import
FunctionalDocTestSuite
from
doctest
import
ELLIPSIS
return
FunctionalDocTestSuite
(
optionflags
=
ELLIPSIS
)
import
doctest
return
FunctionalDocTestSuite
(
optionflags
=
doctest
.
ELLIPSIS
|
doctest
.
NORMALIZE_WHITESPACE
)
src/Testing/ZopeTestCase/zopedoctest/FunctionalDocTest.txt
View file @
c92eb929
...
...
@@ -70,10 +70,11 @@ Examples
Test Publish Document
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html HTTP/1.1
... """, handle_errors=False)
... """, handle_errors=False)
)
HTTP/1.1 200 OK
...
Content-Length: 5
Content-Type: text/plain; charset=...
<BLANKLINE>
...
...
@@ -81,10 +82,11 @@ Test Publish Document
Test parameter containing an additional '?'
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_?foo=bla%3Fbaz HTTP/1.1
... """)
... """)
)
HTTP/1.1 200 OK
...
Content-Length: 5
Content-Type: text/plain; charset=utf-8
<BLANKLINE>
...
...
@@ -93,9 +95,9 @@ Test parameter containing an additional '?'
Test Unauthorized
>>> self.folder.index_html.manage_permission('View', ['Owner'])
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html HTTP/1.1
... """, handle_errors=True)
... """, handle_errors=True)
)
HTTP/1.1 401 Unauthorized
...
Www-Authenticate: basic realm=...
...
...
@@ -105,11 +107,12 @@ Test Basic Authentication
>>> from AccessControl.Permissions import manage_properties
>>> self.setPermissions([manage_properties])
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html/change_title?title=Foo HTTP/1.1
... Authorization: Basic %s
... """ % user_auth, handle_errors=False)
... """ % user_auth, handle_errors=False)
)
HTTP/1.1 200 OK
...
Content-Length: 0
...
...
...
@@ -119,11 +122,12 @@ Test Basic Authentication
Test passing in non-base64-encoded login/pass
>>> from Testing.ZopeTestCase import user_name, user_password
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html/change_title?title=Baz HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password), handle_errors=False)
... """ % (user_name, user_password), handle_errors=False)
)
HTTP/1.1 200 OK
...
Content-Length: 0
...
...
...
@@ -132,10 +136,11 @@ Test passing in non-base64-encoded login/pass
Test setting cookies
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html/set_cookie HTTP/1.1
... """, handle_errors=False)
... """, handle_errors=False)
)
HTTP/1.1 200 OK
...
Content-Length: 0
...
Set-Cookie: foo="Bar"; Path=/
...
...
@@ -143,11 +148,12 @@ Test setting cookies
Test reading cookies
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html/show_cookies HTTP/1.1
... Cookie: foo=bar; baz="oki doki"
... """, handle_errors=False)
... """, handle_errors=False)
)
HTTP/1.1 200 OK
...
Content-Length: 23
Content-Type: text/plain; charset=...
<BLANKLINE>
...
...
src/Testing/ZopeTestCase/zopedoctest/functional.py
View file @
c92eb929
...
...
@@ -149,11 +149,12 @@ def http(request_string, handle_errors=True):
instream = StringIO(request_string)
env = {"HTTP_HOST": '
localhost
',
"HTTP_REFERER": '
localhost
',
"REQUEST_METHOD": method,
"SERVER_PROTOCOL": protocol,
}
env = {
'
HTTP_HOST
': '
localhost
',
'
HTTP_REFERER
': '
localhost
',
'
REQUEST_METHOD
': method,
'
SERVER_PROTOCOL
': protocol,
}
p = path.split('
?
', 1)
if len(p) == 1:
...
...
src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py
View file @
c92eb929
...
...
@@ -96,10 +96,11 @@ SHOW_COOKIES_DTML = '''\
def
setUp
(
self
):
'''This method will run after the test_class' setUp.
>>> print
http(r"""
>>> print
(
http(r"""
... GET /test_folder_1_/index_html HTTP/1.1
... """)
... """)
)
HTTP/1.1 200 OK
...
Content-Length: 5
Content-Type: text/plain; charset=...
<BLANKLINE>
...
...
src/Testing/tests/test_testbrowser.py
View file @
c92eb929
...
...
@@ -39,8 +39,8 @@ def doctest_cookies():
This response looks alright:
>>> response = self.publish('/test_folder_1_/stub')
>>> print
str(response
) #doctest: +ELLIPSIS
Status:
200 OK
>>> print
(str(response)
) #doctest: +ELLIPSIS
HTTP/1.1
200 OK
...
Set-Cookie: evil="cookie"
...
...
...
src/ZPublisher/HTTPResponse.py
View file @
c92eb929
...
...
@@ -25,15 +25,15 @@ import zlib
from
zope.event
import
notify
from
zExceptions
import
(
BadRequest
,
HTTPRedirection
,
InternalError
,
NotFound
,
Redirect
,
status_reasons
,
Unauthorized
,
)
from
zExceptions.ExceptionFormatter
import
format_exception
from
ZPublisher
import
BadRequest
from
ZPublisher
import
InternalError
from
ZPublisher
import
NotFound
from
ZPublisher.BaseResponse
import
BaseResponse
from
ZPublisher.pubevents
import
PubBeforeStreaming
...
...
src/ZPublisher/WSGIPublisher.py
View file @
c92eb929
...
...
@@ -363,7 +363,6 @@ def publish_module(environ, start_response,
else
:
# If somebody used response.write, that data will be in the
# stdout StringIO, so we put that before the body.
# XXX This still needs verification that it really works.
result
=
(
stdout
.
getvalue
(),
response
.
body
)
if
not
repoze_tm_active
:
...
...
@@ -371,8 +370,8 @@ def publish_module(environ, start_response,
stdout
.
close
()
for
callable
in
response
.
after_list
:
callable
()
for
func
in
response
.
after_list
:
func
()
# Return the result body iterable.
return
result
src/ZPublisher/__init__.py
View file @
c92eb929
...
...
@@ -12,8 +12,17 @@
##############################################################################
from
six
import
reraise
from
zope.deferredimport
import
deprecated
from
zExceptions
import
NotFound
,
BadRequest
,
InternalError
,
Forbidden
# NOQA
# BBB Zope 5.0
deprecated
(
'Please import from zExceptions.'
,
NotFound
=
'zExceptions:NotFound'
,
BadRequest
=
'zExceptions:BadRequest'
,
InternalError
=
'zExceptions:InternalError'
,
Forbidden
=
'zExceptions:Forbidden'
,
)
class
Retry
(
Exception
):
...
...
src/ZPublisher/tests/testBaseRequest.py
View file @
c92eb929
import
unittest
from
zExceptions
import
NotFound
from
zope.interface
import
implements
from
zope.publisher.interfaces
import
IPublishTraverse
from
zope.publisher.interfaces
import
NotFound
as
ztkNotFound
...
...
@@ -15,7 +16,7 @@ class DummyTraverser(object):
raise
ztkNotFound
(
self
,
name
)
class
BaseRequest_factory
:
class
BaseRequest_factory
(
object
)
:
def
_makeOne
(
self
,
root
):
from
Acquisition
import
Implicit
...
...
@@ -37,7 +38,6 @@ class BaseRequest_factory:
self
.
base
=
str
(
base
)
def
notFoundError
(
self
,
name
):
from
zExceptions
import
NotFound
raise
NotFound
(
name
)
forbiddenError
=
notFoundError
...
...
@@ -280,7 +280,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def
test_traverse_withBDEmpty
(
self
):
# Collector 1079 (infinite loop 2)
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
_setObject
(
'objWithBD'
,
self
.
_makeObjectWithBD
())
folder
.
objWithBD
.
_default_path
=
[
''
]
...
...
@@ -290,7 +289,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def
test_traverse_withBBT_handles_AttributeError
(
self
):
# Test that if __bobo_traverse__ raises AttributeError
# that we get a NotFound
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
def
_faux___bobo_traverse__
(
REQUEST
,
name
):
...
...
@@ -331,7 +329,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
# and __bobo_traverse__
# __bobo_traverse__ should raise an AttributeError, which will
# raise a NotFound
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
_setObject
(
'objWithBDBBT'
,
self
.
_makeObjectWithBDBBT
())
folder
.
objWithBDBBT
.
_default_path
=
[
'xxx'
]
...
...
@@ -356,14 +353,12 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
self
.
assertEqual
(
r
.
response
.
base
,
''
)
def
test_traverse_attribute_without_docstring
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
_setObject
(
'objBasic'
,
self
.
_makeBasicObject
())
r
=
self
.
_makeOne
(
root
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/objBasic/noview'
)
def
test_traverse_acquired_attribute_without_docstring
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
root
.
_setObject
(
'objBasic'
,
self
.
_makeObjectWithEmptyDocstring
())
...
...
@@ -371,7 +366,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/objBasic'
)
def
test_traverse_class_without_docstring
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
_setObject
(
'objWithoutDocstring'
,
self
.
_makeObjectWithEmptyDocstring
())
...
...
@@ -379,7 +373,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/objWithoutDocstring'
)
def
test_traverse_attribute_of_class_without_docstring
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
_setObject
(
'objWithoutDocstring'
,
self
.
_makeObjectWithEmptyDocstring
())
...
...
@@ -388,7 +381,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
'folder/objWithoutDocstring/view'
)
def
test_traverse_attribute_and_class_without_docstring
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
r
=
self
.
_makeOne
(
root
)
folder
.
_setObject
(
'objWithoutDocstring'
,
...
...
@@ -397,28 +389,24 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
'folder/objWithoutDocstring/noview'
)
def
test_traverse_simple_string
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleString
=
'foo'
r
=
self
.
_makeOne
(
root
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/simpleString'
)
def
test_traverse_simple_list
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleList
=
[]
r
=
self
.
_makeOne
(
root
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/simpleList'
)
def
test_traverse_simple_boolean
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleBoolean
=
True
r
=
self
.
_makeOne
(
root
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/simpleBoolean'
)
def
test_traverse_simple_complex
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleComplex
=
complex
(
1
)
folder
.
simpleString
=
'foo'
...
...
@@ -426,14 +414,12 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/simpleComplex'
)
def
test_traverse_simple_set
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleSet
=
set
([])
r
=
self
.
_makeOne
(
root
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'folder/simpleSet'
)
def
test_traverse_simple_frozen_set
(
self
):
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder
.
simpleFrozenSet
=
frozenset
([])
r
=
self
.
_makeOne
(
root
)
...
...
@@ -470,7 +456,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
def
test_traverse_unsubscriptable
(
self
):
# See https://bugs.launchpad.net/bugs/213311
from
ZPublisher
import
NotFound
r
=
self
.
_makeOne
(
None
)
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'not_found'
)
...
...
@@ -479,7 +464,6 @@ class TestBaseRequest(unittest.TestCase, BaseRequest_factory):
self
.
assertEqual
(
r
.
traverse
(
'dummy'
),
'dummy object'
)
def
test_traverse_publishTraverse_error
(
self
):
from
ZPublisher
import
NotFound
r
=
self
.
_makeOne
(
DummyTraverser
())
self
.
assertRaises
(
NotFound
,
r
.
traverse
,
'not_found'
)
...
...
@@ -715,7 +699,6 @@ class TestBaseRequestViews(TestRequestViewsBase):
def
test_traverse_view_attr_acquired
(
self
):
# normal acquired attribute without view
from
ZPublisher
import
NotFound
root
,
folder
=
self
.
_makeRootAndFolder
()
folder2
=
root
.
_setObject
(
'folder2'
,
self
.
_makeDummyObjectWithAttr
(
'folder2'
))
...
...
src/ZPublisher/tests/testHTTPRequest.py
View file @
c92eb929
import
base64
from
StringIO
import
StringIO
import
sys
import
unittest
from
zExceptions
import
NotFound
from
zope.component
import
provideAdapter
from
zope.i18n.interfaces
import
IUserPreferredLanguages
from
zope.i18n.interfaces.locales
import
ILocale
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.testing.cleanup
import
cleanUp
from
ZPublisher.tests.testBaseRequest
import
TestRequestViewsBase
...
...
@@ -31,7 +39,6 @@ class HTTPRequestFactoryMixin(object):
return
HTTPRequest
def
_makeOne
(
self
,
stdin
=
None
,
environ
=
None
,
response
=
None
,
clean
=
1
):
from
StringIO
import
StringIO
from
ZPublisher.HTTPResponse
import
HTTPResponse
if
stdin
is
None
:
stdin
=
StringIO
()
...
...
@@ -715,8 +722,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
def
test_close_removes_stdin_references
(
self
):
# Verifies that all references to the input stream go away on
# request.close(). Otherwise a tempfile may stick around.
import
sys
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_FILE_DATA
)
start_count
=
sys
.
getrefcount
(
s
)
...
...
@@ -728,7 +733,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
def
test_processInputs_w_large_input_gets_tempfile
(
self
):
# checks fileupload object supports the filename
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_LARGEFILE_DATA
)
req
=
self
.
_makeOne
(
stdin
=
s
,
environ
=
TEST_ENVIRON
.
copy
())
...
...
@@ -739,7 +743,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
def
test_processInputs_with_file_upload_gets_iterator
(
self
):
# checks fileupload object supports the iterator protocol
# collector entry 1837
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_FILE_DATA
)
req
=
self
.
_makeOne
(
stdin
=
s
,
environ
=
TEST_ENVIRON
.
copy
())
...
...
@@ -752,7 +755,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assertEqual
(
f
.
xreadlines
(),
f
)
def
test__authUserPW_simple
(
self
):
import
base64
user_id
=
'user'
password
=
'password'
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
))
...
...
@@ -768,7 +770,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
def
test__authUserPW_with_embedded_colon
(
self
):
# http://www.zope.org/Collectors/Zope/2039
import
base64
user_id
=
'user'
password
=
'embedded:colon'
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
))
...
...
@@ -812,11 +813,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assertEqual
(
request
.
debug
,
'2'
)
def
test_locale_property_accessor
(
self
):
from
zope.component
import
provideAdapter
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.i18n.interfaces
import
IUserPreferredLanguages
from
zope.i18n.interfaces.locales
import
ILocale
from
ZPublisher.HTTPRequest
import
_marker
provideAdapter
(
BrowserLanguages
,
[
IHTTPRequest
],
...
...
@@ -839,11 +835,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assert_
(
request
.
get
(
'locale'
)
is
None
)
def
test_locale_in_qs
(
self
):
from
zope.component
import
provideAdapter
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.i18n.interfaces
import
IUserPreferredLanguages
provideAdapter
(
BrowserLanguages
,
[
IHTTPRequest
],
IUserPreferredLanguages
)
...
...
@@ -858,12 +849,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assertEqual
(
request
[
'locale'
],
'1'
)
def
test_locale_property_override_via_form_other
(
self
):
from
zope.component
import
provideAdapter
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.i18n.interfaces
import
IUserPreferredLanguages
from
zope.i18n.interfaces.locales
import
ILocale
provideAdapter
(
BrowserLanguages
,
[
IHTTPRequest
],
IUserPreferredLanguages
)
env
=
{
'HTTP_ACCEPT_LANGUAGE'
:
'en'
}
...
...
@@ -881,12 +866,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assertEqual
(
request
.
locale
,
'2'
)
def
test_locale_semantics
(
self
):
from
zope.component
import
provideAdapter
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.i18n.interfaces
import
IUserPreferredLanguages
from
zope.i18n.interfaces.locales
import
ILocale
provideAdapter
(
BrowserLanguages
,
[
IHTTPRequest
],
IUserPreferredLanguages
)
env_
=
{
'HTTP_ACCEPT_LANGUAGE'
:
'en'
}
...
...
@@ -910,12 +889,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
self
.
assertEqual
(
locale
.
id
.
variant
,
variant
)
def
test_locale_fallback
(
self
):
from
zope.component
import
provideAdapter
from
zope.publisher.browser
import
BrowserLanguages
from
zope.publisher.interfaces.http
import
IHTTPRequest
from
zope.i18n.interfaces
import
IUserPreferredLanguages
from
zope.i18n.interfaces.locales
import
ILocale
provideAdapter
(
BrowserLanguages
,
[
IHTTPRequest
],
IUserPreferredLanguages
)
...
...
@@ -1084,7 +1057,6 @@ class HTTPRequestTests(unittest.TestCase, HTTPRequestFactoryMixin):
def
test_resolve_url_errorhandling
(
self
):
# Check that resolve_url really raises the same error
# it received from ZPublisher.BaseRequest.traverse
from
zExceptions
import
NotFound
request
=
self
.
_makeOne
()
request
[
'PARENTS'
]
=
[
object
()]
self
.
assertRaises
(
...
...
@@ -1129,7 +1101,6 @@ class TestHTTPRequestZope3Views(TestRequestViewsBase):
def
test_no_traversal_of_view_request_attribute
(
self
):
# make sure views don't accidentally publish the 'request' attribute
from
ZPublisher
import
NotFound
root
,
_
=
self
.
_makeRootAndFolder
()
# make sure the view itself is traversable:
...
...
src/ZPublisher/tests/testHTTPResponse.py
View file @
c92eb929
# -*- coding: utf-8 -*-
import
unittest
from
StringIO
import
StringIO
import
sys
import
unittest
from
zExceptions
import
(
BadRequest
,
Forbidden
,
InternalError
,
NotFound
,
ResourceLockedError
,
Unauthorized
,
)
class
HTTPResponseTests
(
unittest
.
TestCase
):
...
...
@@ -56,7 +66,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
assertEqual
(
response
.
headers
,
{})
def
test_ctor_w_status_exception
(
self
):
from
zExceptions
import
Unauthorized
response
=
self
.
_makeOne
(
status
=
Unauthorized
)
self
.
assertEqual
(
response
.
status
,
401
)
self
.
assertEqual
(
response
.
errmsg
,
'Unauthorized'
)
...
...
@@ -141,28 +150,24 @@ class HTTPResponseTests(unittest.TestCase):
self
.
assertEqual
(
response
.
errmsg
,
'Bad Request'
)
def
test_setStatus_BadRequest
(
self
):
from
zExceptions
import
BadRequest
response
=
self
.
_makeOne
()
response
.
setStatus
(
BadRequest
)
self
.
assertEqual
(
response
.
status
,
400
)
self
.
assertEqual
(
response
.
errmsg
,
'Bad Request'
)
def
test_setStatus_Unauthorized_exception
(
self
):
from
zExceptions
import
Unauthorized
response
=
self
.
_makeOne
()
response
.
setStatus
(
Unauthorized
)
self
.
assertEqual
(
response
.
status
,
401
)
self
.
assertEqual
(
response
.
errmsg
,
'Unauthorized'
)
def
test_setStatus_Forbidden_exception
(
self
):
from
zExceptions
import
Forbidden
response
=
self
.
_makeOne
()
response
.
setStatus
(
Forbidden
)
self
.
assertEqual
(
response
.
status
,
403
)
self
.
assertEqual
(
response
.
errmsg
,
'Forbidden'
)
def
test_setStatus_NotFound_exception
(
self
):
from
zExceptions
import
NotFound
response
=
self
.
_makeOne
()
response
.
setStatus
(
NotFound
)
self
.
assertEqual
(
response
.
status
,
404
)
...
...
@@ -170,13 +175,11 @@ class HTTPResponseTests(unittest.TestCase):
def
test_setStatus_ResourceLockedError_exception
(
self
):
response
=
self
.
_makeOne
()
from
zExceptions
import
ResourceLockedError
response
.
setStatus
(
ResourceLockedError
)
self
.
assertEqual
(
response
.
status
,
423
)
self
.
assertEqual
(
response
.
errmsg
,
'Locked'
)
def
test_setStatus_InternalError_exception
(
self
):
from
zExceptions
import
InternalError
response
=
self
.
_makeOne
()
response
.
setStatus
(
InternalError
)
self
.
assertEqual
(
response
.
status
,
500
)
...
...
@@ -615,7 +618,6 @@ class HTTPResponseTests(unittest.TestCase):
# (r19315): "merged content type on error fixes from 2.3
# If the str of the object returs a Python "pointer" looking mess,
# don't let it get treated as HTML.
from
ZPublisher
import
NotFound
BOGUS
=
'<Bogus a39d53d>'
response
=
self
.
_makeOne
()
self
.
assertRaises
(
NotFound
,
response
.
setBody
,
BOGUS
)
...
...
@@ -782,7 +784,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
assertEqual
(
response
.
quoteHTML
(
BEFORE
),
AFTER
)
def
test_notFoundError
(
self
):
from
ZPublisher
import
NotFound
response
=
self
.
_makeOne
()
try
:
response
.
notFoundError
()
...
...
@@ -793,7 +794,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise NotFound"
)
def
test_notFoundError_w_entry
(
self
):
from
ZPublisher
import
NotFound
response
=
self
.
_makeOne
()
try
:
response
.
notFoundError
(
'ENTRY'
)
...
...
@@ -804,7 +804,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise NotFound"
)
def
test_forbiddenError
(
self
):
from
ZPublisher
import
NotFound
response
=
self
.
_makeOne
()
try
:
response
.
forbiddenError
()
...
...
@@ -815,7 +814,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise NotFound"
)
def
test_forbiddenError_w_entry
(
self
):
from
ZPublisher
import
NotFound
response
=
self
.
_makeOne
()
try
:
response
.
forbiddenError
(
'ENTRY'
)
...
...
@@ -826,7 +824,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise NotFound"
)
def
test_debugError
(
self
):
from
ZPublisher
import
NotFound
response
=
self
.
_makeOne
()
try
:
response
.
debugError
(
'testing'
)
...
...
@@ -838,7 +835,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise NotFound"
)
def
test_badRequestError_valid_parameter_name
(
self
):
from
ZPublisher
import
BadRequest
response
=
self
.
_makeOne
()
try
:
response
.
badRequestError
(
'some_parameter'
)
...
...
@@ -850,7 +846,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise BadRequest"
)
def
test_badRequestError_invalid_parameter_name
(
self
):
from
ZPublisher
import
InternalError
response
=
self
.
_makeOne
()
try
:
response
.
badRequestError
(
'URL1'
)
...
...
@@ -883,7 +878,6 @@ class HTTPResponseTests(unittest.TestCase):
'basic realm="Folly"'
)
def
test_unauthorized_no_debug_mode
(
self
):
from
zExceptions
import
Unauthorized
response
=
self
.
_makeOne
()
try
:
response
.
unauthorized
()
...
...
@@ -895,7 +889,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise Unauthorized"
)
def
test_unauthorized_w_debug_mode_no_credentials
(
self
):
from
zExceptions
import
Unauthorized
response
=
self
.
_makeOne
()
response
.
debug_mode
=
True
try
:
...
...
@@ -907,7 +900,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
fail
(
"Didn't raise Unauthorized"
)
def
test_unauthorized_w_debug_mode_w_credentials
(
self
):
from
zExceptions
import
Unauthorized
response
=
self
.
_makeOne
()
response
.
debug_mode
=
True
response
.
_auth
=
'bogus'
...
...
@@ -1243,7 +1235,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
assertEqual
(
lines
[
5
],
'BLAH'
)
def
test_write_already_wrote
(
self
):
from
StringIO
import
StringIO
stdout
=
StringIO
()
response
=
self
.
_makeOne
(
stdout
=
stdout
)
response
.
write
(
'Kilroy was here!'
)
...
...
@@ -1258,7 +1249,6 @@ class HTTPResponseTests(unittest.TestCase):
self
.
assertEqual
(
lines
[
4
],
'Kilroy was here!'
)
def
test_write_not_already_wrote
(
self
):
from
StringIO
import
StringIO
stdout
=
StringIO
()
response
=
self
.
_makeOne
(
stdout
=
stdout
)
response
.
_wrote
=
True
...
...
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