def test_schemafactory_get_unknown_build(self, mock_logging):
        schemas = DjangoSchemaFactory()
        version_string = django.get_version()
        self.assertFalse(version_string in schemas._schemas)

        # build schema
        schema = schemas.get(version_string, strict=False)()
        # get expected schema
        options = dict([(name.lower(), value) for (name, value) in
            inspect.getmembers(global_settings) if name.isupper()])
        project_options = dict([(name.lower(), value) for (name, value) in
            inspect.getmembers(get_project_settings()) if name.isupper()])
        # handle special case of ROOT_URLCONF which depends on the
        # project name
        root_urlconf = project_options['root_urlconf'].replace(
            '{{ project_name }}.', '')
        project_options['root_urlconf'] = root_urlconf

        options.update(project_options)
        expected = schemas.build(django.get_version(), options)()

        # compare schemas
        self.assert_schemas_equal(schema, expected)

        self.assertEqual(mock_logging.warn.call_args_list[0][0][0],
            "No schema registered for version '{0}'".format(version_string))
        self.assertEqual(mock_logging.warn.call_args_list[1][0][0],
            "Dynamically creating schema for version '{0}'".format(
                version_string))
    def test_schemafactory_get(self):
        # test get valid version
        self.assertEqual(schemas.get('1.0.2 final', strict=True),
            BaseDjangoSchema)

        # test get invalid version
        self.assertRaises(ValueError, schemas.get, '1.1', strict=True)
 def test_django13_logging_config(self):
     schema = schemas.get('1.3')
     section = Section(name='django')
     expected = StringOption(name='logging_config', null=True,
         default='django.utils.log.dictConfig',
         help='The callable to use to configure logging')
     expected.section = section
     self.assertEqual(schema.django.logging_config, expected)
 def test_django13_caches(self):
     schema = schemas.get('1.3')
     expected = DictOption(
         item=UpperCaseDictOption(
             spec={
                 'backend': StringOption(),
                 'location': StringOption()}))
     self.assertEqual(schema.django.caches.item, expected.item)
    def test_schemafactory_build_django(self):
        schemas = DjangoSchemaFactory()

        schema = schemas.build()
        # get known django schema
        # fail for unknown versions of django
        django_schema = schemas.get(django.get_version(), strict=True)

        self.assert_schemas_equal(schema(), django_schema())
    def test_django13_custom_logging_config(self):
        config = StringIO(textwrap.dedent("""
            [django]
            logging_config = foo
            """))

        schema = schemas.get('1.3')
        parser = SchemaConfigParser(schema())
        parser.readfp(config)
        value = parser.values()['django']['logging_config']
        self.assertEqual(value, 'foo')
    def test_schemafactory_get_django(self):
        schemas = DjangoSchemaFactory()

        # build a django schema
        # get only django settings
        options = dict([(name, value) for (name, value) in
            inspect.getmembers(settings) if name.isupper()])
        schema = schemas.build(django.get_version(), options)
        # get known django schema
        # fail for unknown versions of django
        django_schema = schemas.get(django.get_version(), strict=True)

        self.assert_schemas_equal(schema(), django_schema())
示例#8
0
 def setUp(self):
     super(GeneratedSettingsTestCase, self).setUp()
     self.expected_schema = schemas.get(
         django.get_version(), strict=True)()
     self.version = '.'.join(django.get_version().split('.')[:2]) + '.foo'
     mock_get_version = Mock(return_value=self.version)
     self.patch_get_version = patch(
         'django_configglue.tests.settings.django.get_version',
         mock_get_version)
     self.patch_get_version.start()
     self.mock_warn = Mock()
     self.patch_warn = patch(
         'django_configglue.schema.logging.warn', self.mock_warn)
     self.patch_warn.start()
    def test_django13_logging_default(self):
        expected = {
            'version': 1,
            'handlers': {
                'mail_admins': {
                    'class': 'django.utils.log.AdminEmailHandler',
                    'level': 'ERROR'}},
            'loggers': {
                'django.request': {
                    'handlers': ['mail_admins'],
                    'level': 'ERROR',
                    'propagate': True}},
            'disable_existing_loggers': False,
        }

        schema = schemas.get('1.3')
        self.assertEqual(schema().django.logging.default, expected)
    def test_configglue(self):
        target = {}
        schema = schemas.get(django.get_version(), strict=False)
        configglue(schema, [], target)
        # target is consistent with django's settings module
        # except for a few keys
        exclude_keys = ['DATABASE_SUPPORTS_TRANSACTIONS', 'SETTINGS_MODULE']
        # CACHE_BACKEND has been removed from django 1.3 schema but is
        # added by django at runtime, so let's skip that too
        if schema.version >= '1.3':
            exclude_keys.append('CACHE_BACKEND')
        shared_key = lambda x: (not x.startswith('__') and x.upper() == x and
            x not in exclude_keys)
        expected_keys = set(filter(shared_key, dir(settings)))
        target_keys = set(filter(shared_key, target.keys()))

        self.assertEqual(expected_keys, target_keys)
示例#11
0
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
# GNU Lesser General Public License version 3 (see the file LICENSE).

import django
from django_configglue.utils import configglue
from django_configglue.schema import schemas


DjangoSchema = schemas.get(django.get_version(), strict=False)

version = DjangoSchema.version
main_cfg = 'main.cfg'
if version >= '1.3':
    main_cfg = 'main-13.cfg'
elif version >= '1.2':
    main_cfg = 'main-12.cfg'

configglue(DjangoSchema, [main_cfg, 'test.cfg'], __name__)
示例#12
0
文件: schema.py 项目: miing/mci_migo
    BoolOption,
    Section,
    DictOption,
    IntOption,
    ListOption,
    StringOption,
    TupleOption,
    merge,
)
from django_configglue.schema import schemas
from oops_dictconfig.configglue_options import OopsOption

from saml2sso.schema import Saml2IdpSchema


DjangoSchema = schemas.get('1.5.1')


class UpperCaseDictOption(DictOption):
    """ A DictOption with all upper-case keys. """
    def parse(self, section, parser=None, raw=False):
        parsed = super(UpperCaseDictOption, self).parse(
            section, parser, raw)
        result = {}
        for k, v in parsed.items():
            result[k.upper()] = v
        return result


class SSOSchema(DjangoSchema):
    # default
 def test_schema_versions(self):
     django_13 = schemas.get('1.3')()
     django_14 = schemas.get('1.4')()
     self.assertEqual(django_13.version, '1.3')
     self.assertEqual(django_14.version, '1.4')
     self.assertFalse(django_13 is django_14)
 def test_schema_versions(self):
     django_102 = schemas.get('1.0.2 final')()
     django_112 = schemas.get('1.1.2')()
     self.assertEqual(django_102.version, '1.0.2 final')
     self.assertEqual(django_112.version, '1.1.2')
     self.assertFalse(django_102 is django_112)
示例#15
0
import os

import django
from django_configglue.schema import schemas
from configglue.schema import *

from config.schema import SettingsSchema

DjangoSchema = schemas.get(django.get_version())


class FpMonitorSchema(DjangoSchema, SettingsSchema):

    class testing(Section):
        test_coverage_format = StringOption(default='html')
        test_enable_logging = BoolOption(default=False)
        test_ignore_apps = ListOption(item=StringOption(), default=['django_configglue', 'compressor', 'django_extensions'])
        test_output_descriptions = BoolOption(default=False)
        test_output_dir = StringOption()
        test_output_verbose = BoolOption(default=False)
        test_with_coverage = BoolOption(default=False)
        tets_mode = BoolOption(default=False)