Skip to content

Commit

Permalink
Do not use multi-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Dec 26, 2019
1 parent fe5a5f1 commit 8084463
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 51 deletions.
2 changes: 2 additions & 0 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -42,6 +42,7 @@
check_session_cookie,
set_controller_and_action,
handle_i18n,
set_ckan_current_url,
)

import logging
Expand Down Expand Up @@ -330,6 +331,7 @@ def ckan_before_request():
# with extensions
set_controller_and_action()

set_ckan_current_url(request.environ)
g.__timer = time.time()


Expand Down
8 changes: 3 additions & 5 deletions ckan/tests/config/test_sessions.py
Expand Up @@ -11,18 +11,16 @@


@pytest.mark.ckan_config(u"ckan.plugins", u"test_flash_plugin")
@pytest.mark.usefixtures("with_request_context")
class TestWithFlashPlugin:
# @pytest.mark.skipif(six.PY3, reason=u"There is no pylons app in Py3")
def test_flash_populated_by_flask_redirect_to_flask(self, app, client, ckan_config):
def test_flash_populated_by_flask_redirect_to_flask(self, app):
u"""
Flash store is populated by Flask view is accessible by another Flask
view.
"""
url = u"/flask_add_flash_message_redirect_to_flask"
if client:
res = client.get(url, base_url=ckan_config['ckan.site_url'], follow_redirects=True)
else:
res = app.get(url).follow()
res = app.get(url).follow()
assert body_contains(res, u"This is a success message populated by Flask")

@pytest.mark.skipif(six.PY3, reason=u"There is no pylons app in Py3")
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/controllers/test_feed.py
Expand Up @@ -68,6 +68,7 @@ def test_custom_atom_feed_works(self, app):
assert not helpers.body_contains(res, u'<title">{0}</title>'.format(dataset2["title"]))


@pytest.mark.skipif(six.PY3, reason="Relies on webhelpers")
@pytest.mark.ckan_config("ckan.plugins", "test_feed_plugin")
@pytest.mark.usefixtures("clean_db", "clean_index", "with_plugins", "with_request_context")
class TestCustomFeedPlugin:
Expand Down
3 changes: 1 addition & 2 deletions ckan/tests/controllers/test_group.py
Expand Up @@ -382,8 +382,7 @@ def test_remove_member(self, app):
# redirected to member list after removal
remove_response = remove_response.follow(extra_environ=env)

assert "Group member has been deleted." in remove_response
assert "1 members" in remove_response
assert helpers.body_contains(remove_response, "1 members")

remove_response_html = BeautifulSoup(remove_response.body)
user_names = [
Expand Down
23 changes: 1 addition & 22 deletions ckan/tests/pytest_ckan/fixtures.py
Expand Up @@ -173,32 +173,11 @@ def with_plugins(ckan_config):
ckan.plugins.unload(plugin)


@pytest.fixture
def client(app):
"""Client for making requests to application endpoints(Py3 only).
Natiive `test client
<https://werkzeug.palletsprojects.com/en/0.16.x/test/#werkzeug.test.Client>`_
provided by Werkzeug. Py2 still uses WebTest instance for making
requests, as it consists of two real applications. For Py3 there
is no need in such complications.
"""
if six.PY2:
return None
flask_app = app.app._wsgi_app
return flask_app.test_client()


@pytest.fixture
def test_request_context(app):
"""Provide function for creating Flask request context.
"""
try:
flask_app = app.app._wsgi_app
except AttributeError:
flask_app = app.app.apps['flask_app']._wsgi_app
return flask_app.test_request_context
return app.flask_app.test_request_context


@pytest.fixture
Expand Down
27 changes: 15 additions & 12 deletions ckan/views/__init__.py
Expand Up @@ -241,17 +241,20 @@ def handle_i18n(environ=None):
environ[u'CKAN_LANG'] = default_locale
environ[u'CKAN_LANG_IS_DEFAULT'] = True

# Current application url
path_info = environ[u'PATH_INFO']
# sort out weird encodings
path_info = \
u'/'.join(quote(pce, u'') for pce in path_info.split(u'/'))
set_ckan_current_url(environ)

qs = environ.get(u'QUERY_STRING')

if qs:
# sort out weird encodings
qs = quote(qs, u'')
environ[u'CKAN_CURRENT_URL'] = u'%s?%s' % (path_info, qs)
else:
environ[u'CKAN_CURRENT_URL'] = path_info
def set_ckan_current_url(environ):
# Current application url
path_info = environ[u'PATH_INFO']
# sort out weird encodings
path_info = \
u'/'.join(quote(pce, u'') for pce in path_info.split(u'/'))

qs = environ.get(u'QUERY_STRING')
if qs:
# sort out weird encodings
qs = quote(qs, u'')
environ[u'CKAN_CURRENT_URL'] = u'%s?%s' % (path_info, qs)
else:
environ[u'CKAN_CURRENT_URL'] = path_info
19 changes: 9 additions & 10 deletions ckan/views/feed.py
Expand Up @@ -51,14 +51,14 @@ def _package_search(data_dict):


def _enclosure(pkg):
enc = Enclosure(
h.url_for(
u'api.action',
logic_function=u'package_show',
id=pkg['name'],
ver=3,
_external=True),
url = h.url_for(
u'api.action',
logic_function=u'package_show',
id=pkg['name'],
ver=3,
_external=True
)
enc = Enclosure(url)
enc.type = u'application/json'
enc.length = text_type(len(json.dumps(pkg)))
return enc
Expand All @@ -73,7 +73,6 @@ def _set_extras(**kw):

class Enclosure(text_type):
def __init__(self, url):
super(Enclosure, self).__init__(url)
self.url = url
self.length = u'0'
self.mime_type = u'application/json'
Expand Down Expand Up @@ -277,11 +276,11 @@ def group_or_organization(obj_dict, is_org):
params,
item_count=item_count,
limit=data_dict['rows'],
controller=u'feed',
controller=u'feeds',
action=group_type,
id=obj_dict['name'])
feed_url = _feed_url(
params, controller=u'feed', action=group_type, id=obj_dict['name'])
params, controller=u'feeds', action=group_type, id=obj_dict['name'])
# site_title = SITE_TITLE
if is_org:
guid = _create_atom_id(
Expand Down

0 comments on commit 8084463

Please sign in to comment.