3 from django
.conf
import settings
4 from django
.core
.urlresolvers
import resolve
5 from django
.contrib
.auth
.models
import AnonymousUser
6 from django
.test
.client
import RequestFactory
8 from couchdbkit
import Database
9 from couchdbkit
.loaders
import FileSystemDocsLoader
10 from couchdbkit
.ext
.django
.testrunner
import CouchDbKitTestSuiteRunner
12 from mygpo
.db
.couchdb
.utils
import sync_design_docs
16 # http://djangosnippets.org/snippets/2211/
18 class MygpoTestSuiteRunner(CouchDbKitTestSuiteRunner
):
20 Test runner that is able to skip some tests according to settings.py
23 def __init__(self
, *args
, **kwargs
):
24 self
.EXCLUDED_APPS
= getattr(settings
, 'TEST_EXCLUDE', [])
25 settings
.TESTING
= True
26 super(MygpoTestSuiteRunner
, self
).__init
__(*args
, **kwargs
)
29 def setup_databases(self
, **kwargs
):
30 ret
= super(MygpoTestSuiteRunner
, self
).setup_databases(**kwargs
)
35 def build_suite(self
, *args
, **kwargs
):
36 suite
= super(MygpoTestSuiteRunner
, self
).build_suite(*args
, **kwargs
)
37 if not args
[0] and not getattr(settings
, 'RUN_ALL_TESTS', False):
40 pkg
= case
.__class
__.__module
__.split('.')[0]
41 if pkg
not in self
.EXCLUDED_APPS
:
47 def create_auth_string(username
, password
):
49 credentials
= base64
.encodestring("%s:%s" % (username
, password
)).rstrip()
50 auth_string
= 'Basic %s' % credentials
54 def anon_request(url
):
55 """ Emulates an anonymous request, returns the response
58 factory
= RequestFactory()
59 request
= factory
.get(url
)
60 request
.user
= AnonymousUser()
63 response
= view
.func(request
, *view
.args
, **view
.kwargs
)