本文整理汇总了Python中cms.test_utils.util.context_managers.SettingsOverride.__enter__方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsOverride.__enter__方法的具体用法?Python SettingsOverride.__enter__怎么用?Python SettingsOverride.__enter__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.test_utils.util.context_managers.SettingsOverride
的用法示例。
在下文中一共展示了SettingsOverride.__enter__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Fixture
# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __enter__ [as 别名]
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
# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __enter__ [as 别名]
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
# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __enter__ [as 别名]
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)