Skip to content

Commit

Permalink
Test app urls need to be str type
Browse files Browse the repository at this point in the history
With this upgrade of werkzeug, url_for now returns unicode, rather than a str. I'm not clear where that happens, but flask uses lots of bits of werkzeug underneath.

The exception occurs because WSGI requires environ.PATH_INFO to be a string (bytes, not unicode). This is being checked by webtest.lint (the newest version does the same check). PATH_INFO is the part of the WSGI request storing the URL's path. WebOb needs to save it as str, but our old version, webob.request stores it in whatever encoding we give it, so we need to specify the URL already encoded.

I'm not 100% sure that UTF8 is the correct encoding - it might need url (percent) encoding, but for these tests it doesn't make any difference.
  • Loading branch information
David Read committed Aug 21, 2019
1 parent ea4ceb4 commit 2140a1b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ckan/tests/helpers.py
Expand Up @@ -155,6 +155,10 @@ def flask_app(self):
self._flask_app = self.app.apps['flask_app']._wsgi_app
return self._flask_app

def post(self, url, *args, **kwargs):
url = url.encode('utf8') # or maybe it should be url_encoded?
return super(CKANTestApp, self).post(url, *args, **kwargs)


def _get_test_app():
'''Return a webtest.TestApp for CKAN, with legacy templates disabled.
Expand Down

0 comments on commit 2140a1b

Please sign in to comment.