Skip to content

Commit

Permalink
PEP8 cleanup and skipping tests with 8.4
Browse files Browse the repository at this point in the history
As Postgres 8.4 is now legacy, we will skip tests that rely on features that no longer work.
  • Loading branch information
rossjones committed Sep 7, 2015
1 parent 45fd1ca commit 02bcde1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
29 changes: 15 additions & 14 deletions ckanext/datastore/db.py
Expand Up @@ -86,8 +86,8 @@ 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 Expand Up @@ -135,7 +135,7 @@ def _cache_types(context):
'json' if native_json else 'text'))
_pg_types.clear()

## redo cache types with json now available.
# redo cache types with json now available.
return _cache_types(context)

psycopg2.extras.register_composite('nested',
Expand Down Expand Up @@ -215,7 +215,7 @@ def _guess_type(field):
elif float in data_types:
return 'numeric'

##try iso dates
# try iso dates
for format in _DATE_FORMATS:
try:
datetime.datetime.strptime(field, format)
Expand Down Expand Up @@ -324,7 +324,7 @@ def create_table(context, data_dict):
})
supplied_field_ids = records[0].keys()
for field_id in supplied_field_ids:
if not field_id in field_ids:
if field_id not in field_ids:
extra_fields.append({
'id': field_id,
'type': _guess_type(records[0][field_id])
Expand Down Expand Up @@ -565,7 +565,7 @@ def alter_table(context, data_dict):
'present or in wrong order').format(
field['id'])]
})
## no need to check type as field already defined.
# no need to check type as field already defined.
continue

if 'type' not in field:
Expand All @@ -589,7 +589,7 @@ def alter_table(context, data_dict):
})
supplied_field_ids = records[0].keys()
for field_id in supplied_field_ids:
if not field_id in field_ids:
if field_id not in field_ids:
new_fields.append({
'id': field_id,
'type': _guess_type(records[0][field_id])
Expand Down Expand Up @@ -636,7 +636,7 @@ def upsert_data(context, data_dict):
for field in fields:
value = record.get(field['id'])
if value and field['type'].lower() == 'nested':
## a tuple with an empty second value
# a tuple with an empty second value
value = (json.dumps(value), '')
row.append(value)
row.append(_to_full_text(fields, record))
Expand Down Expand Up @@ -678,7 +678,7 @@ def upsert_data(context, data_dict):
for field in fields:
value = record.get(field['id'])
if value is not None and field['type'].lower() == 'nested':
## a tuple with an empty second value
# a tuple with an empty second value
record[field['id']] = (json.dumps(value), '')

non_existing_filed_names = [field for field in record
Expand Down Expand Up @@ -778,7 +778,7 @@ def _validate_record(record, num, field_names):
raise ValidationError({
'records': [u'row "{0}" is not a json object'.format(num)]
})
## check for extra fields in data
# check for extra fields in data
extra_keys = set(record.keys()) - set(field_names)

if extra_keys:
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def delete(context, data_dict):
trans = context['connection'].begin()
try:
# check if table exists
if not 'filters' in data_dict:
if 'filters' not in data_dict:
context['connection'].execute(
u'DROP TABLE "{0}" CASCADE'.format(data_dict['resource_id'])
)
Expand Down Expand Up @@ -1224,9 +1224,10 @@ def search_sql(context, data_dict):
'permissions': ['Not authorized to access system tables']
})

# Check the user has the correct permissions for this resource. This would
# normally be done in the action function (action.datastore_search_sql) but
# it is only at this point that we know which tables are being queried.
# Check the user has the correct permissions for this resource. This
# would normally be done in the action function
# (action.datastore_search_sql) but it is only at this point that we
# know which tables are being queried.
for resource_table in table_names:
data_dict['resource_id'] = resource_table
p.toolkit.check_access('datastore_search_sql', context, data_dict)
Expand Down
5 changes: 3 additions & 2 deletions ckanext/datastore/logic/auth.py
Expand Up @@ -2,7 +2,7 @@


def datastore_auth(context, data_dict, privilege='resource_update'):
if not 'id' in data_dict:
if 'id' not in data_dict:
data_dict['id'] = data_dict.get('resource_id')

user = context.get('user')
Expand All @@ -13,7 +13,7 @@ def datastore_auth(context, data_dict, privilege='resource_update'):
return {
'success': False,
'msg': p.toolkit._('User {0} not authorized to update resource {1}'
.format(str(user), data_dict['id']))
.format(str(user), data_dict['id']))
}
else:
return {'success': True}
Expand Down Expand Up @@ -47,6 +47,7 @@ def datastore_info(context, data_dict):
def datastore_search(context, data_dict):
return datastore_auth(context, data_dict, 'resource_show')


@p.toolkit.auth_allow_anonymous_access
def datastore_search_sql(context, data_dict):
return datastore_auth(context, data_dict, 'resource_show')
Expand Down
3 changes: 3 additions & 0 deletions ckanext/datastore/tests/test_dump.py
Expand Up @@ -21,6 +21,9 @@ class TestDatastoreDump(object):

@classmethod
def setup_class(cls):
if not config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

wsgiapp = middleware.make_app(config['global_conf'], **config)
cls.app = paste.fixture.TestApp(wsgiapp)
if not tests.is_datastore_supported():
Expand Down
5 changes: 5 additions & 0 deletions ckanext/datastore/tests/test_interface.py
@@ -1,5 +1,7 @@
import nose

from pylons import config

import ckan.plugins as p
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
Expand All @@ -11,6 +13,9 @@
class TestInterfaces(object):
@classmethod
def setup_class(cls):
if not config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

p.load('datastore')
p.load('sample_datastore_plugin')

Expand Down
4 changes: 4 additions & 0 deletions ckanext/datastore/tests/test_plugin.py
Expand Up @@ -6,6 +6,7 @@
import ckanext.datastore.interfaces as interfaces
import ckanext.datastore.plugin as plugin

from pylons import config

DatastorePlugin = plugin.DatastorePlugin
assert_equal = nose.tools.assert_equal
Expand Down Expand Up @@ -53,6 +54,9 @@ def test_loading_datastore_last_doesnt_work(self):
class TestPluginDatastoreSearch(object):
@classmethod
def setup_class(cls):
if not config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

p.load('datastore')

@classmethod
Expand Down
12 changes: 12 additions & 0 deletions ckanext/datastore/tests/test_search.py
Expand Up @@ -23,6 +23,9 @@
class TestDatastoreSearchNewTest(object):
@classmethod
def setup_class(cls):
if not pylons.config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

p.load('datastore')

@classmethod
Expand Down Expand Up @@ -110,6 +113,9 @@ class TestDatastoreSearch(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not pylons.config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
Expand Down Expand Up @@ -649,6 +655,9 @@ def test_search_is_unsuccessful_when_called_with_invalid_fields(self):
class TestDatastoreFullTextSearch(tests.WsgiAppCase):
@classmethod
def setup_class(cls):
if not pylons.config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
Expand Down Expand Up @@ -779,6 +788,9 @@ class TestDatastoreSQL(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not pylons.config.get('ckan.datastore.read_url'):
raise nose.SkipTest('Skipping datastore_search tests in legacy mode...')

if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
plugin = p.load('datastore')
Expand Down

0 comments on commit 02bcde1

Please sign in to comment.