From cca66d914bf270dd12524b2640778db37cf5c0a7 Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Wed, 3 Jul 2013 10:47:44 +0200 Subject: [PATCH] [#1067] Test % in delete, resolve unicode issues in messages --- ckanext/datastore/logic/action.py | 10 +++++----- ckanext/datastore/tests/test_delete.py | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ckanext/datastore/logic/action.py b/ckanext/datastore/logic/action.py index 01fef0a6c53..e30dd5bfe2e 100644 --- a/ckanext/datastore/logic/action.py +++ b/ckanext/datastore/logic/action.py @@ -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 @@ -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) @@ -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) @@ -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) @@ -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') diff --git a/ckanext/datastore/tests/test_delete.py b/ckanext/datastore/tests/test_delete.py index cfc69035d51..70497335724 100644 --- a/ckanext/datastore/tests/test_delete.py +++ b/ckanext/datastore/tests/test_delete.py @@ -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, @@ -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) @@ -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' @@ -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' @@ -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()