def test_delete_basic(self): resource = factories.Resource() data = { 'resource_id': resource['id'], 'force': True, 'aliases': u'b\xfck2', 'fields': [{'id': 'book', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'rating with %', 'type': 'text'}], 'records': [{'book': 'annakarenina', 'author': 'tolstoy', 'rating with %': '90%'}, {'book': 'warandpeace', 'author': 'tolstoy', 'rating with %': '42%'}] } helpers.call_action('datastore_create', **data) data = { 'resource_id': resource['id'], 'force': True, } helpers.call_action('datastore_delete', **data) results = execute_sql(u'select 1 from pg_views where viewname = %s', u'b\xfck2') assert results.rowcount == 0 # check the table is gone results = execute_sql( u'''SELECT table_name FROM information_schema.tables WHERE table_name=%s;''', resource['id']) assert results.rowcount == 0
def test_delete_basic(self): resource = factories.Resource() data = { "resource_id": resource["id"], "force": True, "aliases": u"b\xfck2", "fields": [ { "id": "book", "type": "text" }, { "id": "author", "type": "text" }, { "id": "rating with %", "type": "text" }, ], "records": [ { "book": "annakarenina", "author": "tolstoy", "rating with %": "90%", }, { "book": "warandpeace", "author": "tolstoy", "rating with %": "42%", }, ], } helpers.call_action("datastore_create", **data) data = {"resource_id": resource["id"], "force": True} helpers.call_action("datastore_delete", **data) results = execute_sql(u"select 1 from pg_views where viewname = %s", u"b\xfck2") assert results.rowcount == 0 # check the table is gone results = execute_sql( u"""SELECT table_name FROM information_schema.tables WHERE table_name=%s;""", resource["id"], ) assert results.rowcount == 0
def _has_index_on_field(self, resource_id, field): sql = u""" SELECT relname FROM pg_class WHERE pg_class.relname = %s """ index_name = db._generate_index_name(resource_id, field) results = execute_sql(sql, index_name).fetchone() return bool(results)
def _get_index_names(self, resource_id): sql = u""" SELECT i.relname AS index_name FROM pg_class t, pg_class i, pg_index idx WHERE t.oid = idx.indrelid AND i.oid = idx.indexrelid AND t.relkind = 'r' AND t.relname = %s """ results = execute_sql(sql, resource_id).fetchall() return [result[0] for result in results]