当前位置: 首页>>代码示例>>Python>>正文


Python SettingsOverride.__exit__方法代码示例

本文整理汇总了Python中cms.test_utils.util.context_managers.SettingsOverride.__exit__方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsOverride.__exit__方法的具体用法?Python SettingsOverride.__exit__怎么用?Python SettingsOverride.__exit__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cms.test_utils.util.context_managers.SettingsOverride的用法示例。


在下文中一共展示了SettingsOverride.__exit__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Fixture

# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __exit__ [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']
开发者ID:BeUnique,项目名称:django-cms,代码行数:30,代码来源:fixtures.py

示例2: NoAdminPageTests

# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __exit__ [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)
开发者ID:CenturyGlorion,项目名称:django-cms,代码行数:18,代码来源:page.py

示例3: SettingsOverrideTestCase

# 需要导入模块: from cms.test_utils.util.context_managers import SettingsOverride [as 别名]
# 或者: from cms.test_utils.util.context_managers.SettingsOverride import __exit__ [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)
开发者ID:31H0B1eV,项目名称:django-cms,代码行数:19,代码来源:testcases.py


注:本文中的cms.test_utils.util.context_managers.SettingsOverride.__exit__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。