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


Python context_managers.SettingsOverride类代码示例

本文整理汇总了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']
开发者ID:BeUnique,项目名称:django-cms,代码行数:28,代码来源:fixtures.py

示例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)
开发者ID:CenturyGlorion,项目名称:django-cms,代码行数:16,代码来源:page.py

示例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)
开发者ID:31H0B1eV,项目名称:django-cms,代码行数:17,代码来源:testcases.py

示例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)
开发者ID:BeUnique,项目名称:django-cms,代码行数:8,代码来源:fixtures.py

示例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__()
开发者ID:360yln,项目名称:django-cms-2.4,代码行数:9,代码来源:page.py

示例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__()
开发者ID:CenturyGlorion,项目名称:django-cms,代码行数:5,代码来源:page.py

示例7: _enter_settings_override

 def _enter_settings_override(self):
     self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
     self._settings_ctx_manager.__enter__()
开发者ID:31H0B1eV,项目名称:django-cms,代码行数:3,代码来源:testcases.py


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