Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Fix annoying space issue in py27 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gyst committed Jan 15, 2018
1 parent fc32c44 commit a1168c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/grokcore/rest/tests/functional/rest/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@
the response MUST include an Allow header containing a list of valid
methods for the requested resource::
>>> print(http_call(wsgi_app(), 'POST', '/++rest++b/app HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'POST', '/++rest++b/app HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow: GET, PUT
Content-Length: 18
Content-Type: text/plain;charset=utf-8
<BLANKLINE>
Method Not Allowed
>>> print(http_call(wsgi_app(), 'DELETE', '/++rest++b/app HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'DELETE', '/++rest++b/app HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow: GET, PUT
Content-Length: 18
Content-Type: text/plain;charset=utf-8
<BLANKLINE>
Method Not Allowed
>>> print(http_call(wsgi_app(), 'POST', '/++rest++c/app HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'POST', '/++rest++c/app HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow:
Content-Length: 18
Expand All @@ -166,7 +166,7 @@
We can also try this with a completely made-up request method, like FROG::
>>> print(http_call(wsgi_app(), 'FROG', '/++rest++b/app HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'FROG', '/++rest++b/app HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow: GET, PUT
Content-Length: 18
Expand All @@ -177,7 +177,7 @@
Let's now see whether security works properly with REST. GET should
be public::
>>> print(http_call(wsgi_app(), 'GET', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'GET', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
HTTP/1.0 200 Ok
Content-Length: 4
Content-Type: text/plain;charset=utf-8
Expand All @@ -186,21 +186,21 @@
POST, PUT and DELETE however are not public::
>>> print(http_call(wsgi_app(), 'POST', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'POST', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
HTTP/1.0 401 Unauthorized
Content-Length: 0
Content-Type: text/plain;charset=utf-8
WWW-Authenticate: basic realm="Zope"
<BLANKLINE>
>>> print(http_call(wsgi_app(), 'PUT', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'PUT', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
HTTP/1.0 401 Unauthorized
Content-Length: 0
Content-Type: text/plain;charset=utf-8
WWW-Authenticate: basic realm="Zope"
<BLANKLINE>
>>> print(http_call(wsgi_app(), 'DELETE', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'DELETE', '/++rest++e/app/alpha HTTP/1.1', handle_errors=True))
HTTP/1.0 401 Unauthorized
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Expand All @@ -215,7 +215,7 @@
therefore need to have some easy way to get to this information. The 'body'
attribute on the REST view contains the uploaded data::
>>> print(http_call(
>>> print(str_http_call(
... wsgi_app(), 'POST', 'http://localhost/++rest++f/app/alpha',
... 'this is the POST body'))
HTTP/1.0 200 Ok
Expand All @@ -226,7 +226,7 @@
This works with PUT as well::
>>> print(http_call(
>>> print(str_http_call(
... wsgi_app(), 'PUT', 'http://localhost/++rest++f/app/alpha',
... 'this is the PUT body'))
HTTP/1.0 200 Ok
Expand All @@ -238,14 +238,14 @@
Opening up the publication for REST doesn't mean we can just delete
random objects without access:
>>> print(http_call(wsgi_app(), 'DELETE', '/app HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'DELETE', '/app HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow:
Content-Length: 18
Content-Type: text/plain;charset=utf-8
Method Not Allowed
>>> print(http_call(wsgi_app(), 'DELETE', '/app/alpha HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'DELETE', '/app/alpha HTTP/1.1', handle_errors=True))
HTTP/1.0 405 Method Not Allowed
Allow:
Content-Length: 18
Expand All @@ -254,7 +254,7 @@
We shouldn't be allowed to PUT either::
>>> print(http_call(wsgi_app(), 'PUT', '/app/beta HTTP/1.1', handle_errors=True))
>>> print(str_http_call(wsgi_app(), 'PUT', '/app/beta HTTP/1.1', handle_errors=True))
HTTP/1.0 404 Not Found
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Expand Down
7 changes: 7 additions & 0 deletions src/grokcore/rest/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def http_call(app, method, path, data=None, handle_errors=False, **kw):
return result


def str_http_call(*args, **kw):
result = http_call(*args, **kw)
# annoying 2.7 regression even though zope.errorview was fixed
return str(result).replace('plain; charset', 'plain;charset')


def suiteFromPackage(name):
layer_dir = 'functional'
files = resource_listdir(__name__, '{}/{}'.format(layer_dir, name))
Expand All @@ -71,6 +77,7 @@ def suiteFromPackage(name):
bprint=grokcore.rest.testing.bprint,
getRootFolder=layer.getRootFolder,
http_call=http_call,
str_http_call=str_http_call,
http=http,
wsgi_app=layer.make_wsgi_app),
optionflags=(
Expand Down

0 comments on commit a1168c6

Please sign in to comment.