本文整理汇总了Python中south.management.commands.patch_for_test_db_setup函数的典型用法代码示例。如果您正苦于以下问题:Python patch_for_test_db_setup函数的具体用法?Python patch_for_test_db_setup怎么用?Python patch_for_test_db_setup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了patch_for_test_db_setup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
def __enter__(self):
try:
patch_for_test_db_setup()
except NameError:
pass
connection.creation.create_test_db(self.verbosity)
示例2: switch_to_test_database
def switch_to_test_database():
"""
Switching to the test database
"""
logging.info("Setting up a test database ...\n")
try:
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
except ImportError:
pass
world.test_runner = DjangoTestSuiteRunner(interactive=False)
world.test_runner.setup_test_environment()
world.test_db = world.test_runner.setup_databases()
call_command('syncdb', **{
'settings': settings.SETTINGS_MODULE,
'interactive': False,
'verbosity': 0
})
# Reload mongodb database
settings.MONGODB_DATABASE = settings.MONGODB_TEST_DATABASE
for model in [Document, Entry, Notification]:
model.objects.load()
model.objects.collection.remove()
示例3: south_patch
def south_patch(self):
try:
from south.management.commands import patch_for_test_db_setup
except ImportError:
pass
else:
patch_for_test_db_setup()
示例4: handle
def handle(self, *test_labels, **options):
"""Trigger both south and selenium tests."""
run_south_tests = bool(options.get('run_normal_tests', False))
run_selenium_tests = bool(options.get('run_selenium_tests', False))
# Check test types
if (run_south_tests and run_selenium_tests or
not run_south_tests and not run_selenium_tests):
logger.error("You must specify exactly one of --selenium-tests and --normal-tests.")
sys.exit(1)
# Apply the south patch for syncdb, migrate commands during tests
patch_for_test_db_setup()
if run_south_tests:
test_south.Command.handle(self, *test_labels, **options)
elif run_selenium_tests:
# We don't want to call any super handle function, because it will
# try to run tests in addition to parsing command line options.
# Instead, we parse the relevant options ourselves.
verbosity = int(options.get('verbosity', 1))
interactive = options.get('interactive', True)
failfast = options.get('failfast', False)
test_runner = SeleniumTestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
test_runner.selenium = True
test_runner.selenium_only = True
failures = test_runner.run_tests(test_labels)
if failures:
sys.exit(bool(failures))
示例5: runtests
def runtests():
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
test_runner = get_runner(settings)
test_runner = test_runner(interactive=True, verbosity=1, failfast=False)
failures = test_runner.run_tests([])
sys.exit(bool(failures))
示例6: handle
def handle(self, *args, **options):
USE_SOUTH = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
try:
if USE_SOUTH:
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
except:
USE_SOUTH = False
self._test_runner = DjangoTestSuiteRunner(interactive=False)
DjangoTestSuiteRunner.setup_test_environment(self._test_runner)
self._created_db = DjangoTestSuiteRunner.setup_databases(self._test_runner)
call_command('syncdb', verbosity=0, interactive=False,)
if USE_SOUTH:
call_command('migrate', verbosity=0, interactive=False,)
settings.DEBUG = options.get('debug', False)
verbosity = int(options.get('verbosity', 4))
apps_to_run = tuple(options.get('apps', '').split(","))
apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
run_server = not options.get('no_server', False)
tags = options.get('tags', None)
server = Server(port=options['port'])
paths = self.get_paths(args, apps_to_run, apps_to_avoid)
if run_server:
try:
server.start()
except LettuceServerException, e:
raise SystemExit(e)
示例7: __init__
def __init__(self, *args, **kwargs):
self.configure()
self.cov = coverage()
self.cov.start()
self.packages = self.resolve_packages()
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--autoreload', dest='autoreload',
action='store_const', const=True, default=False,)
parser.add_argument('-f', '--failfast', dest='failfast',
action='store_const', const=True, default=False,)
parser.add_argument('-l', '--label', dest='label')
self.options = vars(parser.parse_args(sys.argv[2:]))
sys.argv = sys.argv[:2]
super(SetupTestSuite, self).__init__(tests=self.build_tests(),
*args, **kwargs)
# Setup testrunner.
from django.test.simple import DjangoTestSuiteRunner
self.test_runner = DjangoTestSuiteRunner(
verbosity=1,
interactive=True,
failfast=False
)
# South patches the test management command to handle the
# SOUTH_TESTS_MIGRATE setting. Apply that patch if South is installed.
try:
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
except ImportError:
pass
self.test_runner.setup_test_environment()
self.old_config = self.test_runner.setup_databases()
示例8: django_tests
def django_tests(verbosity, interactive, failfast, test_labels):
import django
from django.conf import settings
if hasattr(django, 'setup'):
# Django >= 1.7 requires this for setting up the application.
django.setup()
if django.VERSION < (1, 7):
# must be imported after settings are set up
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
from django.test.utils import get_runner
TestRunner = get_runner(settings)
if not test_labels:
# apps to test
test_labels = CORE_TEST_MODULES + get_contrib_test_modules()
test_runner = TestRunner(verbosity=verbosity, interactive=interactive,
failfast=failfast)
failures = test_runner.run_tests(test_labels)
teardown()
return failures
示例9: main
def main():
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=2, failfast=False)
if len(sys.argv) > 1:
test_modules = sys.argv[1:]
elif len(sys.argv) == 1:
test_modules = []
else:
print(usage())
sys.exit(1)
if django.VERSION >= (1, 6, 0):
# this is a compat hack because in django>=1.6.0 you must provide
# module like "userena.contrib.umessages" not "umessages"
test_modules = [
get_app(module_name).__name__[:-7] for module_name in test_modules
]
if django.VERSION < (1, 7, 0):
# starting from 1.7.0 built in django migrations are run
# for older releases this patch is required to enable testing with
# migrations
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
failures = test_runner.run_tests(test_modules or ['userena'])
sys.exit(failures)
示例10: _handle_south
def _handle_south():
from django.conf import settings
if 'south' in settings.INSTALLED_APPS:
# Handle south.
from django.core import management
try:
# if `south` >= 0.7.1 we can use the test helper
from south.management.commands import patch_for_test_db_setup
except ImportError:
# if `south` < 0.7.1 make sure it's migrations are disabled
management.get_commands()
management._commands['syncdb'] = 'django.core'
else:
# Monkey-patch south.hacks.django_1_0.SkipFlushCommand to load
# initial data.
# Ref: http://south.aeracode.org/ticket/1395#comment:3
import south.hacks.django_1_0
from django.core.management.commands.flush import (
Command as FlushCommand)
class SkipFlushCommand(FlushCommand):
def handle_noargs(self, **options):
# Reinstall the initial_data fixture.
from django.core.management import call_command
# `load_initial_data` got introduces with Django 1.5.
load_initial_data = options.get('load_initial_data', None)
if load_initial_data or load_initial_data is None:
# Reinstall the initial_data fixture.
call_command('loaddata', 'initial_data', **options)
# no-op to avoid calling flush
return
south.hacks.django_1_0.SkipFlushCommand = SkipFlushCommand
patch_for_test_db_setup()
示例11: setUp
def setUp(self):
# Set up the django test framework.
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
from django.conf import settings
from django.test.utils import setup_test_environment
from django.db import connection
from south.management.commands import patch_for_test_db_setup
# If DEBUG = True, django will sometimes take different code paths.
settings.DEBUG = False
self.django_db = settings.DATABASE_NAME
setup_test_environment()
patch_for_test_db_setup()
connection.creation.create_test_db(verbosity=0)
# A fake cardstories service just to benefit from settings directories.
class FakeService:
def __init__(self, settings):
self.settings = settings
# Instantiate our test subject.
self.auth = djangoauth.Plugin(FakeService({'plugins-libdir': '.',
'plugins-confdir': '../fixture'}), [])
# Use the fake client in the plugin instead of twisted's getPage.
self.auth.getPage = FakeTwistedWebClient().getPage
示例12: handle
def handle(self, *fixture_labels, **options):
from django.core.management import call_command
from django.db import connection
from south.management.commands import patch_for_test_db_setup
patch_for_test_db_setup()
verbosity = int(options.get('verbosity'))
interactive = options.get('interactive')
addrport = options.get('addrport')
# Create a test database.
db_name = connection.creation.create_test_db(verbosity=verbosity, autoclobber=not interactive)
# Import the fixture data into the test database.
call_command('loaddata', *fixture_labels, **{'verbosity': verbosity})
# Run the development server. Turn off auto-reloading because it causes
# a strange error -- it causes this handle() method to be called
# multiple times.
shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name
use_threading = connection.features.test_db_allows_multiple_connections
call_command('runserver',
addrport=addrport,
shutdown_message=shutdown_message,
use_reloader=False,
use_ipv6=options['use_ipv6'],
use_threading=use_threading
)
示例13: setup_databases
def setup_databases(self):
if 'south' in settings.INSTALLED_APPS:
from south.management.commands import (
patch_for_test_db_setup # pylint: disable=F0401
)
patch_for_test_db_setup()
return super(CITestSuiteRunner, self).setup_databases()
示例14: handle
def handle(self, *args, **options):
# Replace the DB name with test DB name in main settings
# since this is what destroy_test_db looks for to determine
# the name of the test_db.
for alias in connections:
connection = connections[alias]
original_name = connection.settings_dict['NAME']
if connection.settings_dict['TEST_NAME']:
test_database_name = connection.settings_dict['TEST_NAME']
else:
test_database_name = TEST_DATABASE_PREFIX + connection.settings_dict['NAME']
connection.settings_dict['NAME'] = test_database_name
# try to delete db if it already exists, so we can recreate.
try:
connection.creation.destroy_test_db(original_name)
except Exception, e:
pass
# check if we have south installed, and so overide syncdb so
# we also run migrations. Uses same method as south's test
# command override.
try:
from south.management.commands import patch_for_test_db_setup
except ImportError:
patch_for_test_db_setup = lambda: None
patch_for_test_db_setup()
connection.creation.create_test_db()
示例15: setup_databases
def setup_databases(self, verbosity, autoclobber, **kwargs):
# Taken from Django 1.2 code, (C) respective Django authors. Modified for backward compatibility by me
connections = self._get_databases()
old_names = []
mirrors = []
from django.conf import settings
if 'south' in settings.INSTALLED_APPS:
from south.management.commands import patch_for_test_db_setup
settings.SOUTH_TESTS_MIGRATE = getattr(settings, 'DST_RUN_SOUTH_MIGRATIONS', True)
patch_for_test_db_setup()
for alias in connections:
connection = connections[alias]
# If the database is a test mirror, redirect it's connection
# instead of creating a test database.
if 'TEST_MIRROR' in connection.settings_dict and connection.settings_dict['TEST_MIRROR']:
mirrors.append((alias, connection))
mirror_alias = connection.settings_dict['TEST_MIRROR']
connections._connections[alias] = connections[mirror_alias]
else:
if 'NAME' in connection.settings_dict:
old_names.append((connection, connection.settings_dict['NAME']))
else:
old_names.append((connection, connection.settings_dict['DATABASE_NAME']))
connection.creation.create_test_db(verbosity=verbosity, autoclobber=autoclobber)
return old_names, mirrors