本文整理汇总了Python中cms.test_utils.util.context_managers.SettingsOverride类的典型用法代码示例。如果您正苦于以下问题:Python SettingsOverride类的具体用法?Python SettingsOverride怎么用?Python SettingsOverride使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SettingsOverride类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Fixture
class Fixture(object): # pragma: no cover
DB_OVERRIDE = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
}
def __init__(self, name, apps=['cms'], **settings_overrides):
self.name = name
self.apps = apps
self.settings_overrides = settings_overrides
def start(self):
self.so = SettingsOverride(**self.settings_overrides)
self.so.__enter__()
self.old_db = connections.databases['default']
connections.databases['default'] = self.DB_OVERRIDE
if 'default' in connections._connections:
del connections._connections['default']
call_command('syncdb', migrate_all=True, interactive=False, verbosity=0)
def save(self):
filename = os.path.join(settings.FIXTURE_DIRS[0], self.name)
with open(filename, 'wb') as fobj:
call_command('dumpdata', *self.apps, stdout=fobj)
self.so.__exit__(None, None, None)
connections.databases['default'] = self.old_db
if 'default' in connections._connections:
del connections._connections['default']
示例2: NoAdminPageTests
class NoAdminPageTests(CMSTestCase):
urls = 'cms.test_utils.project.noadmin_urls'
def setUp(self):
admin = 'django.contrib.admin'
noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
self._ctx.__enter__()
def tearDown(self):
self._ctx.__exit__(None, None, None)
def test_get_page_from_request_fakeadmin_nopage(self):
request = self.get_request('/en/admin/')
page = get_page_from_request(request)
self.assertEqual(page, None)
示例3: SettingsOverrideTestCase
class SettingsOverrideTestCase(CMSTestCase):
settings_overrides = {}
def _pre_setup(self):
self._enter_settings_override()
super(SettingsOverrideTestCase, self)._pre_setup()
def _enter_settings_override(self):
self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
self._settings_ctx_manager.__enter__()
def _post_teardown(self):
super(SettingsOverrideTestCase, self)._post_teardown()
self._exit_settings_override()
def _exit_settings_override(self):
self._settings_ctx_manager.__exit__(None, None, None)
示例4: start
def start(self):
self.so = SettingsOverride(**self.settings_overrides)
self.so.__enter__()
self.old_db = connections.databases['default']
connections.databases['default'] = self.DB_OVERRIDE
if 'default' in connections._connections:
del connections._connections['default']
call_command('syncdb', migrate_all=True, interactive=False, verbosity=0)
示例5: setUp
def setUp(self):
admin = 'django.contrib.admin'
noadmin_apps = [app for app in installed_apps() if not app == admin]
try:
from django.apps import apps
apps.set_installed_apps(noadmin_apps)
except ImportError:
self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
self._ctx.__enter__()
示例6: setUp
def setUp(self):
admin = 'django.contrib.admin'
noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
self._ctx.__enter__()
示例7: _enter_settings_override
def _enter_settings_override(self):
self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
self._settings_ctx_manager.__enter__()