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 PATH_INFO 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 22, 2019
1 parent ea4ceb4 commit b2f25f9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ckan/tests/controllers/test_home.py
Expand Up @@ -44,7 +44,7 @@ def test_email_address_nag(self):
response = app.get(url=url_for('home.index'), extra_environ=env)

assert 'update your profile' in response.body
assert url_for('user.edit') in response.body
assert str(url_for('user.edit')) in response.body
assert ' and add your email address.' in response.body

def test_email_address_no_nag(self):
Expand Down
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
2 changes: 1 addition & 1 deletion ckan/tests/legacy/functional/test_preview_interface.py
Expand Up @@ -87,4 +87,4 @@ def test_iframe_is_shown(self):

def test_iframe_url_is_correct(self):
result = self.app.get(self.url)
assert self.preview_url in result.body, (self.preview_url, result.body)
assert str(self.preview_url) in result.body, (self.preview_url, result.body)
4 changes: 2 additions & 2 deletions ckanext/datastore/tests/test_info.py
Expand Up @@ -66,11 +66,11 @@ def test_api_info(self):
'http://test.ckan.net/api/3/action/datastore_upsert',
'<code>http://test.ckan.net/api/3/action/datastore_search',
'http://test.ckan.net/api/3/action/datastore_search_sql',
'http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&amp;limit=5',
'http://test.ckan.net/api/3/action/datastore_search?limit=5&amp;resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b',
'http://test.ckan.net/api/3/action/datastore_search?q=jones&amp;resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b',
'http://test.ckan.net/api/3/action/datastore_search_sql?sql=SELECT * from &#34;588dfa82-760c-45a2-b78a-e3bc314a4a9b&#34; WHERE title LIKE &#39;jones&#39;',
"url: 'http://test.ckan.net/api/3/action/datastore_search'",
"http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&amp;limit=5&amp;q=title:jones",
"http://test.ckan.net/api/3/action/datastore_search?limit=5&amp;resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&amp;q=title:jones",
)
for url in expected_urls:
assert url in page, url
4 changes: 2 additions & 2 deletions ckanext/multilingual/tests/test_multilingual_plugin.py
Expand Up @@ -71,8 +71,8 @@ def test_user_read_translation(self):
# It is testsysadmin who created the dataset, so testsysadmin whom
# we'd expect to see the datasets for.
for user_name in ('testsysadmin',):
offset = h.url_for(
'user.read', id=user_name)
offset = str(h.url_for(
'user.read', id=user_name))
for (lang_code, translations) in (
('de', _create_test_data.german_translations),
('fr', _create_test_data.french_translations),
Expand Down

0 comments on commit b2f25f9

Please sign in to comment.