Skip to content

Commit

Permalink
fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Apr 10, 2017
1 parent 79bcdd4 commit c821ddd
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions ckan/tests/test_coding_standards.py
Expand Up @@ -587,6 +587,7 @@ def find_unprefixed_string_literals(filename):
u'ckanext/datastore/controller.py',
u'ckanext/datastore/db.py',
u'ckanext/datastore/backend/postgres.py',
u'ckanext/datastore/backend/example_sqlite.py',
u'ckanext/datastore/backend/__init__.py',
u'ckanext/datastore/helpers.py',
u'ckanext/datastore/interfaces.py',
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datapusher/logic/action.py
Expand Up @@ -94,7 +94,7 @@ def datapusher_submit(context, data_dict):
if existing_task.get('state') == 'pending':
updated = datetime.datetime.strptime(
existing_task['last_updated'], '%Y-%m-%dT%H:%M:%S.%f')
time_since_last_updated = datetime.datetime.now() - updated
time_since_last_updated = datetime.datetime.utcnow() - updated
if time_since_last_updated > assume_task_stale_after:
# it's been a while since the job was last updated - it's more
# likely something went wrong with it and the state wasn't
Expand Down
1 change: 0 additions & 1 deletion ckanext/datapusher/tests/test_action.py
Expand Up @@ -295,5 +295,4 @@ def submit(res, user):
r_mock.reset_mock()
submit(res, user)
submit(res, user)

eq_(1, r_mock.call_count)
7 changes: 5 additions & 2 deletions ckanext/datastore/backend/__init__.py
Expand Up @@ -59,8 +59,9 @@ class DatastoreBackend:
"""Base class for all datastore backends.
Very simple example of implementation based on SQLite can be found in
`ckanext.datastore.backend.example`. In order to use it, set datastore.write_url
to 'example-sqlite:////tmp/database-name-on-your-choice'
`ckanext.datastore.backend.example_sqlite`. In order to use it, set
datastore.write_url to
'example-sqlite:////tmp/database-name-on-your-choice'
:prop _backend: mapping(schema, class) of all registered backends
:type _backend: dictonary
Expand All @@ -86,6 +87,8 @@ def set_active_backend(cls, config):
"""
schema = config.get('ckan.datastore.write_url').split(':')[0]
read_schema = config.get('ckan.datastore.read_url').split(':')[0]
assert read_schema == schema, u'Read and write engines are different'
cls._active_backend = cls._backends[schema]()

@classmethod
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions ckanext/datastore/backend/postgres.py
Expand Up @@ -396,7 +396,7 @@ def _textsearch_query(data_dict):
rank_columns.append(rank)

statements_str = ', ' + ', '.join(statements)
rank_columns_str = ', ' + ', '.join(rank_columns)
rank_columns_str = ', '.join(rank_columns)
return statements_str, rank_columns_str


Expand Down Expand Up @@ -1550,14 +1550,17 @@ def datastore_search(self, context, data_dict, fields_types, query_dict):
field_ids = fields_types.keys()

ts_query, rank_column = _textsearch_query(data_dict)

limit = data_dict.get('limit', 100)
offset = data_dict.get('offset', 0)

sort = _sort(data_dict, fields_types)
where = _where_clauses(data_dict, fields_types)

select_cols = [u'"{0}"'.format(field_id) for field_id in field_ids] +\
[u'count(*) over() as "_full_count" %s' % rank_column]
select_cols = [
datastore_helpers.identifier(field_id) for field_id in field_ids]
if rank_column:
select_cols.append(rank_column)

query_dict['distinct'] = data_dict.get('distinct', False)
query_dict['select'] += select_cols
Expand Down
4 changes: 2 additions & 2 deletions ckanext/datastore/controller.py
Expand Up @@ -86,7 +86,7 @@ def dictionary(self, id, resource_id):
'info': {
'label': request.POST.get('f{0}label'.format(i)),
'notes': request.POST.get('f{0}notes'.format(i)),
}} for i, f in enumerate(fields, 1)]})
}} for i, f in enumerate(fields, 1)]})

h.redirect_to(
controller='ckanext.datastore.controller:DatastoreController',
Expand Down Expand Up @@ -118,7 +118,7 @@ def result_page(offs, lim):
PAGINATE_BY if limit is None
else min(PAGINATE_BY, lim),
'offset': offs,
})
})

result = result_page(offset, limit)
columns = [x['id'] for x in result['fields']]
Expand Down
6 changes: 3 additions & 3 deletions ckanext/datastore/helpers.py
Expand Up @@ -24,9 +24,9 @@ def is_valid_field_name(name):
* can't contain double quote (")
* can't be empty
'''
return (name and name == name.strip()
and not name.startswith('_')
and '"' not in name)
return (name and name == name.strip() and
not name.startswith('_') and
'"' not in name)


def is_valid_table_name(name):
Expand Down
3 changes: 3 additions & 0 deletions ckanext/datastore/interfaces.py
Expand Up @@ -162,6 +162,9 @@ def register_backends(self):
`ckan.datastore.write_url` config directive. eg. 'postgresql://a:b@x'
will use 'postgresql' backend, but 'mongodb://a:b@c' will try to use
'mongodb' backend(if such backend has been registered, of course).
If read and write urls use different engines, `set_active_backend`
will raise assertion error.
:returns: the dictonary with backend name as key and backend class as
value
Expand Down
11 changes: 7 additions & 4 deletions ckanext/datastore/plugin.py
Expand Up @@ -18,7 +18,7 @@
DatastoreBackend
)
from ckanext.datastore.backend.postgres import DatastorePostgresqlBackend
from ckanext.datastore.backend.example import DatastoreExampleSqliteBackend
from ckanext.datastore.backend.example_sqlite import DatastoreExampleSqliteBackend

log = logging.getLogger(__name__)
_get_or_bust = logic.get_or_bust
Expand Down Expand Up @@ -230,9 +230,12 @@ def datastore_validate(self, context, data_dict, fields_types):

sort_clauses = data_dict.get('sort')
if sort_clauses:
invalid_clauses = [c for c in sort_clauses
if not _parse_sort_clause(
c, fields_types)]
invalid_clauses = [
c for c in sort_clauses
if not _parse_sort_clause(
c, fields_types
)
]
data_dict['sort'] = invalid_clauses

limit = data_dict.get('limit')
Expand Down

0 comments on commit c821ddd

Please sign in to comment.