Skip to content

Commit

Permalink
[#3229] Fix various issues in tests
Browse files Browse the repository at this point in the history
The DataStore ones were encoding things badly.
On the multilingual plugin, the origin of the failure is unclear
but it was related to the PylonsTestCase in
the legacy tests messing with the pylons request object.
  • Loading branch information
amercader committed Sep 5, 2016
1 parent 2ef2c57 commit 308758c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions ckan/tests/legacy/logic/test_auth.py
@@ -1,6 +1,5 @@
# encoding: utf-8

import paste
from ckan.common import config
import ckan.config.middleware
import ckan.tests.legacy as tests
Expand Down Expand Up @@ -252,6 +251,9 @@ def setup_class(cls):
for user in model.Session.query(model.User):
cls.apikeys[user.name] = str(user.apikey)

cls.sysadmin = get_action('get_site_user')(
{'model': model, 'ignore_auth': True}, {})

cls._original_config = config.copy()

config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'
Expand All @@ -273,7 +275,8 @@ def teardown_class(cls):
def _reset_a_datasets_owner_org(self):
rev = model.repo.new_revision()
get_action('package_owner_org_update')(
{'model': model, 'ignore_auth': True},
{'model': model, 'user': self.sysadmin['name'],
'ignore_auth': True},
{'id': 'adataset',
'organization_id': 'national-health-service'})

Expand Down
8 changes: 4 additions & 4 deletions ckanext/datastore/tests/test_search.py
Expand Up @@ -2,6 +2,7 @@

import json
import nose
import urllib
import pprint

import sqlalchemy.orm as orm
Expand Down Expand Up @@ -926,10 +927,9 @@ def test_self_join(self):
where a.author = b.author
limit 2
'''.format(self.data['resource_id'])
data = {'sql': query}
postparams = json.dumps(data)
data = urllib.urlencode({'sql': query})
auth = {'Authorization': str(self.normal_user.apikey)}
res = self.app.post('/api/action/datastore_search_sql', params=postparams,
res = self.app.post('/api/action/datastore_search_sql', params=data,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['success'] is True
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def test_not_authorized_to_access_system_tables(self):
]
for query in test_cases:
data = {'sql': query.replace('\n', '')}
postparams = json.dumps(data)
postparams = urllib.urlencode(data)
res = self.app.post('/api/action/datastore_search_sql',
params=postparams,
status=403)
Expand Down
3 changes: 3 additions & 0 deletions ckanext/multilingual/plugin.py
Expand Up @@ -109,6 +109,7 @@ def translate_resource_data_dict(data_dict):
as possible translated into the desired or the fallback language.
'''

desired_lang_code = request.environ['CKAN_LANG']
fallback_lang_code = config.get('ckan.locale_default', 'en')

Expand Down Expand Up @@ -257,6 +258,8 @@ def before_search(self, search_params):
current_lang = config.get('ckan.locale_default')
else:
raise
except KeyError:
current_lang = config.get('ckan.locale_default')

# fallback to default locale if locale not in suported langs
if not current_lang in lang_set:
Expand Down

0 comments on commit 308758c

Please sign in to comment.