touch-couchdb-views accepts DB URL from commandline
[mygpo.git] / mygpo / test.py
blobc807a163de8dc422a37b07ba5634190990834c27
1 import os.path
3 from django.conf import settings
5 from couchdbkit import Database
6 from couchdbkit.loaders import FileSystemDocsLoader
7 from couchdbkit.ext.django.testrunner import CouchDbKitTestSuiteRunner
9 from mygpo.db.couchdb.utils import sync_design_docs
12 # inspired by
13 # http://djangosnippets.org/snippets/2211/
15 class MygpoTestSuiteRunner(CouchDbKitTestSuiteRunner):
16 """
17 Test runner that is able to skip some tests according to settings.py
18 """
20 def __init__(self, *args, **kwargs):
21 self.EXCLUDED_APPS = getattr(settings, 'TEST_EXCLUDE', [])
22 settings.TESTING = True
23 super(MygpoTestSuiteRunner, self).__init__(*args, **kwargs)
26 def setup_databases(self, **kwargs):
27 ret = super(MygpoTestSuiteRunner, self).setup_databases(**kwargs)
28 sync_design_docs()
29 return ret
32 def build_suite(self, *args, **kwargs):
33 suite = super(MygpoTestSuiteRunner, self).build_suite(*args, **kwargs)
34 if not args[0] and not getattr(settings, 'RUN_ALL_TESTS', False):
35 tests = []
36 for case in suite:
37 pkg = case.__class__.__module__.split('.')[0]
38 if pkg not in self.EXCLUDED_APPS:
39 tests.append(case)
40 suite._tests = tests
41 return suite
44 def create_auth_string(username, password):
45 import base64
46 credentials = base64.encodestring("%s:%s" % (username, password)).rstrip()
47 auth_string = 'Basic %s' % credentials
48 return auth_string