Skip to content

Commit

Permalink
[#1251] Fixes to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Mar 20, 2014
1 parent a9c6304 commit ba69718
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
25 changes: 16 additions & 9 deletions ckanext/datastore/db.py
Expand Up @@ -745,7 +745,7 @@ def _to_full_text(fields, record):
return ' '.join(full_text)


def _where(field_ids, data_dict):
def _where(field_ids, fields, data_dict):
'''Return a SQL WHERE clause from data_dict filters and q'''
filters = data_dict.get('filters', {})

Expand All @@ -764,12 +764,19 @@ def _where(field_ids, data_dict):
)

if isinstance(value, list):
where_clauses.append(
u'"{0}" in ({1})'.format(field,
','.join(['%s'] * len(value)))
)
values.extend(value)
continue
for item in fields:
if item['id'] == field:
field_type = item['type']
break

# ignore array types when doing in search.
if not field_type.startswith('_'):
where_clauses.append(
u'"{0}" in ({1})'.format(field,
','.join(['%s'] * len(value)))
)
values.extend(value)
continue

where_clauses.append(u'"{0}" = %s'.format(field))
values.append(value)
Expand Down Expand Up @@ -881,7 +888,7 @@ def _insert_links(data_dict, limit, offset):
def delete_data(context, data_dict):
fields = _get_fields(context, data_dict)
field_ids = set([field['id'] for field in fields])
where_clause, where_values = _where(field_ids, data_dict)
where_clause, where_values = _where(field_ids, fields, data_dict)

context['connection'].execute(
u'DELETE FROM "{0}" {1}'.format(
Expand Down Expand Up @@ -913,7 +920,7 @@ def search_data(context, data_dict):
select_columns = ', '.join([u'"{0}"'.format(field_id)
for field_id in field_ids])
ts_query, rank_column = _textsearch_query(data_dict)
where_clause, where_values = _where(all_field_ids, data_dict)
where_clause, where_values = _where(all_field_ids, all_fields, data_dict)
limit = data_dict.get('limit', 100)
offset = data_dict.get('offset', 0)

Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/tests/test_search.py
Expand Up @@ -232,7 +232,7 @@ def test_search_filters_get(self):
def test_search_invalid_filter(self):
data = {'resource_id': self.data['resource_id'],
# invalid because author is not an array
'filters': {u'author': [u'tolstoy']}}
'filters': {u'author': {u'tolstoy': 'book'}}}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
Expand Down
2 changes: 1 addition & 1 deletion ckanext/webpageview/plugin.py
Expand Up @@ -42,7 +42,7 @@ def add_default_views(self, context, data_dict):
'resource_id': resource['id'],
'view_type': 'webpage'}
p.toolkit.get_action('resource_view_create')(
{'defer_commit': True}, view
{'defer_commit': True, 'ignore_auth': True}, view
)

def after_update(self, context, data_dict):
Expand Down

0 comments on commit ba69718

Please sign in to comment.