Skip to content

Commit

Permalink
Split datastore tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz authored and amercader committed Oct 12, 2012
1 parent db85bfc commit 19edd37
Show file tree
Hide file tree
Showing 8 changed files with 1,780 additions and 1,740 deletions.
2 changes: 2 additions & 0 deletions ckanext/datastore/plugin.py
Expand Up @@ -23,6 +23,8 @@ class DatastorePlugin(p.SingletonPlugin):
p.implements(p.IActions)
p.implements(p.IAuthFunctions)

legacy_mode = False

def configure(self, config):
self.config = config
# check for ckan.datastore.write_url and ckan.datastore.read_url
Expand Down
31 changes: 31 additions & 0 deletions ckanext/datastore/tests/helpers.py
@@ -0,0 +1,31 @@
import ckan.model as model
import ckan.lib.cli as cli


def extract(d, keys):
return dict((k, d[k]) for k in keys if k in d)


def clear_db(Session):
drop_tables = u'''select 'drop table "' || tablename || '" cascade;'
from pg_tables where schemaname = 'public' '''
c = Session.connection()
results = c.execute(drop_tables)
for result in results:
c.execute(result[0])
Session.commit()
Session.remove()


def rebuild_all_dbs(Session):
''' If the tests are running on the same db, we have to make sure that
the ckan tables are recrated.
'''
db_read_url_parts = cli.parse_db_config('ckan.datastore.write_url')
db_ckan_url_parts = cli.parse_db_config('sqlalchemy.url')
same_db = db_read_url_parts['db_name'] == db_ckan_url_parts['db_name']

if same_db:
model.repo.tables_created_and_initialised = False
clear_db(Session)
model.repo.rebuild_db()

0 comments on commit 19edd37

Please sign in to comment.