Skip to content

Commit

Permalink
Merge branch '287-datastore-tests-only-on-pg'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jan 30, 2013
2 parents bd80782 + 7f93897 commit 4313177
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 14 deletions.
1 change: 1 addition & 0 deletions ckan/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from meta import (
Session,
engine_is_sqlite,
engine_is_pg,
)
from core import (
System,
Expand Down
8 changes: 7 additions & 1 deletion ckan/model/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import extension
import ckan.lib.activity_streams_session_extension as activity

__all__ = ['Session', 'engine_is_sqlite']
__all__ = ['Session', 'engine_is_sqlite', 'engine_is_pg']


class CkanCacheExtension(SessionExtension):
Expand Down Expand Up @@ -158,3 +158,9 @@ def engine_is_sqlite():
Returns true iff the engine is connected to a sqlite database.
"""
return engine.url.drivername == 'sqlite'

def engine_is_pg():
"""
Returns true iff the engine is connected to a postgresql database.
"""
return engine.url.drivername == 'psycopg2'
4 changes: 4 additions & 0 deletions ckan/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ def is_migration_supported():
is_supported_db = not model.engine_is_sqlite()
return is_supported_db

def is_datastore_supported():
is_supported_db = model.engine_is_pg()
return is_supported_db

def search_related(test):
def skip_test(*args):
raise SkipTest("Search not supported")
Expand Down
32 changes: 19 additions & 13 deletions ckanext/datastore/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import pylons
from sqlalchemy.exc import ProgrammingError

import ckan.plugins as p
import ckanext.datastore.logic.action as action
import ckanext.datastore.logic.auth as auth
import ckanext.datastore.db as db
import ckan.logic as logic
import ckan.model as model

log = logging.getLogger(__name__)
_get_or_bust = logic.get_or_bust
Expand Down Expand Up @@ -52,21 +54,25 @@ def configure(self, config):
else:
self.read_url = self.config['ckan.datastore.read_url']

if not self._is_read_only_database():
# Make sure that the right permissions are set
# so that no harmful queries can be made
if not ('debug' in config and config['debug']):
self._check_separate_db()
if self.legacy_mode:
log.warn('Legacy mode active. The sql search will not be available.')
else:
self._check_read_permissions()
if model.engine_is_pg():
if not self._is_read_only_database():
# Make sure that the right permissions are set
# so that no harmful queries can be made
if not ('debug' in config and config['debug']):
self._check_separate_db()
if self.legacy_mode:
log.warn('Legacy mode active. The sql search will not be available.')
else:
self._check_read_permissions()

self._create_alias_table()
self._create_alias_table()
else:
log.warn("We detected that CKAN is running on a read only database. "
"Permission checks and _table_metadata creation are skipped."
"Make sure that replication is properly set-up.")
else:
log.warn("We detected that CKAN is running on a read only database. "
"Permission checks and _table_metadata creation are skipped."
"Make sure that replication is properly set-up.")
log.warn("We detected that you do not use a PostgreSQL database. "
"The DataStore will NOT work and datastore tests will be skipped.")

## Do light wrapping around action function to add datastore_active
## to resource dict. Not using IAction extension as this prevents other plugins
Expand Down
3 changes: 3 additions & 0 deletions ckanext/datastore/tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import nose

import sqlalchemy.orm as orm

Expand All @@ -18,6 +19,8 @@ class TestDatastoreCreate(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down
3 changes: 3 additions & 0 deletions ckanext/datastore/tests/test_delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import nose

import sqlalchemy
import sqlalchemy.orm as orm
Expand All @@ -19,6 +20,8 @@ class TestDatastoreDelete(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down
7 changes: 7 additions & 0 deletions ckanext/datastore/tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import nose
import pprint

import sqlalchemy.orm as orm
Expand All @@ -18,6 +19,8 @@ class TestDatastoreSearch(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down Expand Up @@ -331,6 +334,8 @@ def test_search_table_metadata(self):
class TestDatastoreFullTextSearch(tests.WsgiAppCase):
@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down Expand Up @@ -397,6 +402,8 @@ class TestDatastoreSQL(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down
7 changes: 7 additions & 0 deletions ckanext/datastore/tests/test_upsert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import nose
import datetime

import sqlalchemy.orm as orm
Expand All @@ -19,6 +20,8 @@ class TestDatastoreUpsert(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down Expand Up @@ -243,6 +246,8 @@ class TestDatastoreInsert(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down Expand Up @@ -344,6 +349,8 @@ class TestDatastoreUpdate(tests.WsgiAppCase):

@classmethod
def setup_class(cls):
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
ctd.CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')
Expand Down

0 comments on commit 4313177

Please sign in to comment.