Skip to content

Commit

Permalink
[#1067] Test % in delete, resolve unicode issues in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jul 3, 2013
1 parent 773b0e1 commit cca66d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ckanext/datastore/logic/action.py
Expand Up @@ -68,7 +68,7 @@ def datastore_create(context, data_dict):
for alias in aliases:
if not db._is_valid_table_name(alias):
raise p.toolkit.ValidationError({
'alias': ['"{0}" is not a valid alias name'.format(alias)]
'alias': [u'"{0}" is not a valid alias name'.format(alias)]
})

# create a private datastore resource, if necessary
Expand Down Expand Up @@ -137,7 +137,7 @@ def datastore_upsert(context, data_dict):

if not res_exists:
raise p.toolkit.ObjectNotFound(p.toolkit._(
'Resource "{0}" was not found.'.format(res_id)
u'Resource "{0}" was not found.'.format(res_id)
))

p.toolkit.check_access('datastore_upsert', context, data_dict)
Expand Down Expand Up @@ -181,7 +181,7 @@ def datastore_delete(context, data_dict):

if not res_exists:
raise p.toolkit.ObjectNotFound(p.toolkit._(
'Resource "{0}" was not found.'.format(res_id)
u'Resource "{0}" was not found.'.format(res_id)
))

p.toolkit.check_access('datastore_delete', context, data_dict)
Expand Down Expand Up @@ -349,7 +349,7 @@ def datastore_make_private(context, data_dict):

if not _resource_exists(context, data_dict):
raise p.toolkit.ObjectNotFound(p.toolkit._(
'Resource "{0}" was not found.'.format(res_id)
u'Resource "{0}" was not found.'.format(res_id)
))

p.toolkit.check_access('datastore_change_permissions', context, data_dict)
Expand All @@ -375,7 +375,7 @@ def datastore_make_public(context, data_dict):

if not _resource_exists(context, data_dict):
raise p.toolkit.ObjectNotFound(p.toolkit._(
'Resource "{0}" was not found.'.format(res_id)
u'Resource "{0}" was not found.'.format(res_id)
))

data_dict['connection_url'] = pylons.config.get('ckan.datastore.write_url')
Expand Down
21 changes: 12 additions & 9 deletions ckanext/datastore/tests/test_delete.py
Expand Up @@ -30,11 +30,14 @@ def setup_class(cls):
resource = model.Package.get('annakarenina').resources[0]
cls.data = {
'resource_id': resource.id,
'aliases': 'books2',
'aliases': u'b\xfck2',
'fields': [{'id': 'book', 'type': 'text'},
{'id': 'author', 'type': 'text'}],
'records': [{'book': 'annakarenina', 'author': 'tolstoy'},
{'book': 'warandpeace', 'author': 'tolstoy'}]
{'id': 'author', 'type': 'text'},
{'id': 'rating with %', 'type': 'text'}],
'records': [{'book': 'annakarenina', 'author': 'tolstoy',
'rating with %': '90%'},
{'book': 'warandpeace', 'author': 'tolstoy',
'rating with %': '42%'}]
}

engine = db._get_engine(None,
Expand Down Expand Up @@ -73,13 +76,13 @@ def test_delete_basic(self):
c = self.Session.connection()

# alias should be deleted
results = c.execute("select 1 from pg_views where viewname = '{0}'".format(self.data['aliases']))
results = c.execute(u"select 1 from pg_views where viewname = '{0}'".format(self.data['aliases']))
assert results.rowcount == 0

try:
# check that data was actually deleted: this should raise a
# ProgrammingError as the table should not exist any more
c.execute('select * from "{0}";'.format(resource_id))
c.execute(u'select * from "{0}";'.format(resource_id))
raise Exception("Data not deleted")
except sqlalchemy.exc.ProgrammingError as e:
expected_msg = 'relation "{0}" does not exist'.format(resource_id)
Expand Down Expand Up @@ -110,7 +113,7 @@ def test_delete_filters(self):
assert res_dict['success'] is True

c = self.Session.connection()
result = c.execute('select * from "{0}";'.format(resource_id))
result = c.execute(u'select * from "{0}";'.format(resource_id))
results = [r for r in result]
assert len(results) == 1
assert results[0].book == 'annakarenina'
Expand All @@ -127,7 +130,7 @@ def test_delete_filters(self):
assert res_dict['success'] is True

c = self.Session.connection()
result = c.execute('select * from "{0}";'.format(resource_id))
result = c.execute(u'select * from "{0}";'.format(resource_id))
results = [r for r in result]
assert len(results) == 1
assert results[0].book == 'annakarenina'
Expand All @@ -144,7 +147,7 @@ def test_delete_filters(self):
assert res_dict['success'] is True

c = self.Session.connection()
result = c.execute('select * from "{0}";'.format(resource_id))
result = c.execute(u'select * from "{0}";'.format(resource_id))
results = [r for r in result]
assert len(results) == 0
self.Session.remove()
Expand Down

0 comments on commit cca66d9

Please sign in to comment.