def test_schemafactory_build_complex_options(self): schemas = DjangoSchemaFactory() options = { 'dict1': {'foo': 1, 'bar': '2'}, 'dict2': {'foo': {'bar': 2, 'baz': 3}}, 'list1': ['1', '2', '3'], 'list2': [1, 2, 3], } expected = { 'dict1': DictOption(name='dict1', default=options['dict1'], item=StringOption()), 'dict2': DictOption(name='dict2', default=options['dict2'], item=DictOption()), 'list1': ListOption(name='list1', default=options['list1'], item=StringOption()), 'list2': ListOption(name='list2', default=options['list2'], item=IntOption()), } schema = schemas.build('foo', options)() sections = sorted( [section.name for section in schema.sections()]) section = schema.section('django') self.assertEqual(sections, ['django']) for name in options: option = expected[name] option.section = section self.assertEqual(section.option(name), option) self.assertEqual(section.option(name).item, option.item)
def test_equal(self): """Test StringOption equality.""" option1 = StringOption() option2 = StringOption(null=True) self.assertEqual(option1, option1) self.assertNotEqual(option1, option2)
class DjangoZipkinSection(Section): zipkin_service_name = StringOption(default=DEFAULT_ZIPKIN_SERVICE_NAME) zipkin_data_store_class = StringOption( default=DEFAULT_ZIPKIN_DATA_STORE_CLASS) zipkin_logger_name = StringOption(default=DEFAULT_ZIPKIN_LOGGER_NAME) zipkin_id_generator_class = StringOption( default=DEFAULT_ZIPKIN_ID_GENERATOR_CLASS)
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)
class raven(Section): sentry_servers = ListOption() sentry_include_paths = ListOption( item=StringOption()) sentry_exclude_paths = ListOption( item=StringOption(), help='Ignore module prefixes when attempting to discover which ' 'function an error comes from.') sentry_timeout = IntOption( default=5, help='Timeout value for sending messages to remote.') sentry_name = StringOption( null=True, help='This will override the server_name value for this installation.') sentry_auto_log_stacks = BoolOption( default=False, help='Should raven automatically log frame stacks (including ' 'locals) all calls as it would for exceptions.') sentry_key = StringOption( null=True) sentry_max_length_string = IntOption( default=200, help='The maximum characters of a string that should be stored.') sentry_max_length_list = IntOption( default=50, help='The maximum number of items a list-like container should store.') sentry_site = StringOption( null=True, help='An optional, arbitrary string to identify this client ' 'installation.') sentry_public_key = StringOption( null=True, help='Public key of the project member which will authenticate as ' 'the client.') sentry_private_key = StringOption( null=True, help='Private key of the project member which will authenticate as ' 'the client.') sentry_project = IntOption( default=1, help='Sentry project ID. The default value for installations is 1.') sentry_processors = ListOption( item=StringOption(), default=[ 'raven.processors.SanitizePasswordsProcessor', ], help='List of processors to apply to events before sending them ' 'to the Sentry server.') sentry_dsn = StringOption( help='A sentry compatible DSN.') sentry_client = StringOption( default='raven.contrib.django.DjangoClient') sentry_debug = BoolOption( default=False)
class MySchema(Schema): foo = self.cls(spec={ 'bar': StringOption(), 'baz': IntOption(), 'bla': BoolOption(), }, parse_json=False)
class MySchema(Schema): foo = ListOption(item=DictOption( spec={ 'bar': StringOption(), 'baz': IntOption(), 'bla': BoolOption(), }))
def test_equal(self): """Test ListOption equality.""" option1 = ListOption() option2 = ListOption(name='foo') option3 = ListOption(item=StringOption()) option4 = ListOption(item=DictOption()) option5 = ListOption(raw=True) option6 = ListOption(remove_duplicates=True) option7 = ListOption(raw=False, item=StringOption(raw=True)) self.assertEqual(option1, option1) self.assertNotEqual(option1, option2) self.assertEqual(option1, option3) self.assertNotEqual(option1, option4) self.assertNotEqual(option1, option5) self.assertNotEqual(option1, option6) self.assertNotEqual(option1, option7)
def test_equal(self): """Test option equality.""" opt1 = IntOption(name='opt1') opt2 = IntOption(name='opt2') opt3 = StringOption(name='opt1') self.assertEqual(opt1, opt1) self.assertNotEqual(opt1, opt2) self.assertNotEqual(opt1, opt3)
class django_jenkins(Section): project_apps = ListOption( item=StringOption(), default=[], help='List of of django apps for Jenkins to run.') jenkins_tasks = TupleOption( default=( 'django_jenkins.tasks.run_pylint', 'django_jenkins.tasks.with_coverage', 'django_jenkins.tasks.django_tests', ), help='List of Jenkins tasks executed by ./manage.py jenkins ' 'command.') jenkins_test_runner = StringOption( default='', help='The name of the class to use for starting the test suite for ' 'jenkins and jtest commands. Class should be inherited from ' 'django_jenkins.runner.CITestSuiteRunner.')
def ini2schema(fd, p=None): """ Turn a fd that refers to a INI-style schema definition into a SchemaConfigParser object @param fd: file-like object to read the schema from @param p: a parser to use. If not set, uses AttributedConfigParser """ if p is None: p = AttributedConfigParser() p.readfp(fd) p.parse_all() parser2option = {'unicode': StringOption, 'int': IntOption, 'bool': BoolOption, 'lines': ListOption} class MySchema(Schema): pass for section_name in p.sections(): if section_name == '__main__': section = MySchema else: section = Section(name=section_name) setattr(MySchema, section_name, section) for option_name in p.options(section_name): option = p.get(section_name, option_name) parser = option.attrs.pop('parser', 'unicode') parser_args = option.attrs.pop('parser.args', '').split() parser_fun = getattr(parsers, parser, None) if parser_fun is None: parser_fun = getattr(__builtin__, parser, None) if parser_fun is None: parser_fun = lambda x: x attrs = {'name': option_name} option_help = option.attrs.pop('help', None) if option_help is not None: attrs['help'] = option_help if not option.is_empty: attrs['default'] = parser_fun(option.value, *parser_args) option_action = option.attrs.pop('action', None) if option_action is not None: attrs['action'] = option_action klass = parser2option.get(parser, StringOption) if parser == 'lines': instance = klass(item=StringOption(), **attrs) else: instance = klass(**attrs) setattr(section, option_name, instance) return SchemaConfigParser(MySchema())
class saml2(Section): saml2idp_autosubmit = BoolOption(default=True) saml2idp_issuer = StringOption(default='http://127.0.0.1:8000') saml2idp_certificate_file = StringOption( default='keys/certificate.pem') saml2idp_private_key_file = StringOption( default='keys/private-key.pem') saml2idp_signing = BoolOption(default=True) saml2idp_valid_acs = ListOption( item=StringOption(), default=[ 'https://login.salesforce.com', ], help="List of ACS URLs accepted by /+saml login") saml2idp_processor_classes = ListOption( item=StringOption(), default=[ 'saml2idp.salesforce.Processor', 'saml2idp.google_apps.Processor', ], help="List of SAML 2.0 AuthnRequest processors")
def test_parse_dict_with_dicts(self): innerspec = { 'bar': StringOption(), 'baz': IntOption(), 'bla': BoolOption(), } spec = { 'name': StringOption(), 'size': IntOption(), 'options': DictOption(spec=innerspec) } class MySchema(Schema): foo = DictOption(spec=spec) config = StringIO("""[__main__] foo = outerdict [outerdict] options = innerdict [innerdict] bar = something baz = 42 """) expected_values = { '__main__': { 'foo': { 'name': '', 'size': 0, 'options': { 'bar': 'something', 'baz': 42, 'bla': False } } } } schema = MySchema() parser = SchemaConfigParser(schema) parser.readfp(config) self.assertEqual(parser.values(), expected_values)
def test_equal(self): """Test DictOption equality.""" option1 = DictOption() option2 = DictOption(spec={'foo': BoolOption()}) option3 = DictOption(strict=True) option4 = DictOption(item=StringOption()) option5 = DictOption(item=IntOption()) self.assertEqual(option1, option1) self.assertNotEqual(option1, option2) self.assertNotEqual(option1, option3) self.assertEqual(option1, option4) self.assertNotEqual(option1, option5)
class openid(Section): openid_use_as_admin_login = BoolOption(default=False) openid_create_users = BoolOption(default=False) openid_update_details_from_sreg = BoolOption(default=False) openid_physical_multifactor_required = BoolOption(default=False) openid_strict_usernames = BoolOption(default=False) openid_sreg_required_fields = ListOption(item=StringOption()) openid_sreg_extra_fields = ListOption(item=StringOption()) openid_follow_renames = BoolOption(default=False) openid_launchpad_teams_mapping_auto = BoolOption(default=False) openid_launchpad_teams_mapping_auto_blacklist = ListOption( item=StringOption()) openid_launchpad_teams_mapping = DictOption() openid_launchpad_staff_teams = ListOption(item=StringOption()) openid_disallow_inames = BoolOption(default=False) allowed_external_openid_redirect_domains = ListOption( item=StringOption()) openid_trust_root = StringOption() openid_sso_server_url = StringOption(null=True)
class devserver(Section): devserver_args = ListOption( item=StringOption(), default=[], help='Additional command line arguments to pass to the runserver command (as defaults).') devserver_default_addr = StringOption( default='127.0.0.1', help='The default address to bind to.') devserver_default_port = StringOption( default='8000', help='The default port to bind to.') devserver_wsgi_middleware = ListOption( item=StringOption(), default=[], help='A list of additional WSGI middleware to apply to the runserver command.') devserver_modules = ListOption( item=StringOption(), default=[ 'devserver.modules.sql.SQLRealTimeModule', ], help='List of devserver modules to enable') devserver_ignored_prefixes = ListOption( item=StringOption(), default=['/media', '/uploads'], help='List of prefixes to supress and skip process on. By default, ' 'ADMIN_MEDIA_PREFIX, MEDIA_URL and STATIC_URL ' '(for Django >= 1.3) will be ignored (assuming MEDIA_URL and ' 'STATIC_URL is relative).') devserver_truncate_sql = BoolOption( default=True, help='Truncate SQL queries output by SQLRealTimeModule.') devserver_truncate_aggregates = BoolOption( default=False) devserver_active = BoolOption( default=False) devserver_ajax_content_length = IntOption( default=300, help='Maximum response length to dump.') devserver_ajax_pretty_print = BoolOption( default=False) devserver_sql_min_duration = IntOption( default=None, help='Minimum time a query must execute to be shown, value is in ms.') devserver_auto_profile = BoolOption( default=False, help='Automatically profile all view functions.')
def test_default_item(self): """Test ListOption default item.""" opt = self.cls() self.assertEqual(opt.item, StringOption())
class MySchema(Schema): foo = StringOption()
class OpenProximitySchema(Django13Schema): ################################################ # openproximity general settings ################################################ openproximity = Section('openproximity') openproximity.aircable_path = StringOption( default='/tmp/aircable', help= 'Path were we store the database file (if using sqlite) and storing files for campaigns etc' ) openproximity.op2_debug = BoolOption( default=True, help='Disable if you want to hide the "Databrowse" tab') openproximity.op2_translate = BoolOption( default=True, help='Disable if you want to hide the "Translate" tab') openproximity.op2_twitter = BoolOption( default=True, help='Disable if you want to hide the Twitter news client') openproximity.op2_logo = StringOption( default='logo.gif', help='Logo to display instead of AIRcable logo') openproximity.op2_plugins = DictOption( item=BoolOption(), help= """A list of plugins name with they're enable/disable state overrides plugins defaults)""" ) openproximity.op2_scanners = ListOption( item=TupleOption(4), help= """A list of ([MAC filter], scanner priority) for dongle configuration on initial discovery""" ) openproximity.op2_uploaders = ListOption( item=TupleOption(4), help= """A list of ([MAC filter], max connections) for dongle configuration on initial discovery""" ) ################################################ # cherrypy settings ################################################ cherrypy = Section('cherrypy') cherrypy.cp_host = StringOption(default="localhost", help='hostname to listen on') cherrypy.cp_port = IntOption(default=8088, help='port to listen on') cherrypy.cp_server_name = StringOption( default="localhost", help="CherryPy's SERVER_NAME environ entry") cherrypy.cp_daemonize = BoolOption(default=False, help='whether to detach from terminal') cherrypy.cp_pidfile = StringOption( default=None, help="write the spawned process-id to this file") cherrypy.cp_workdir = StringOption( default=None, help="change to this directory when daemonizing") cherrypy.cp_threads = IntOption(default=20, help='Number of threads for server to use') cherrypy.cp_ssl_certificate = StringOption(default=None, help="SSL certificate filename") cherrypy.cp_ssl_private_key = StringOption(default=None, help="SSL private key filename") cherrypy.cp_server_user = StringOption( default='www-data', help="user to run daemonized process") cherrypy.cp_server_group = StringOption(default='www-data', help="group to daemonized process") ################################################ # rpyc settings ################################################ rpyc = Section('rpyc') rpyc.rpc_host = StringOption(default="localhost", help='hostname to listen on') rpyc.rpc_port = IntOption(default=8010, help='port to listen on') rpyc.rpc_daemonize = BoolOption(default=False, help='whether to detach from terminal') rpyc.rpc_threaded = BoolOption( default=True, help='run in threaded way instead of forked') rpyc.rpc_autoregister = BoolOption( default=False, help='try registering the server in name servers') rpyc.rpc_pidfile = StringOption( default=None, help="write the spawned process-id to this file") rpyc.rpc_server_user = StringOption(default='www-data', help="user to run daemonized process") rpyc.rpc_server_group = StringOption(default='www-data', help="group to daemonized process") ################################################ # debugging settings ################################################ debug = Section('debug') debug.debug_console = StringOption( default='INFO', help='console debug level, default INFO') debug.debug_level = StringOption(default='DEBUG', help='in file debug level, default DEBUG') debug.debug_path = StringOption( default='/var/log/openproximity', help='default path used for storing log files') debug.debug_maxsize = IntOption(default=10, help='max log file in MB, defaults to 10') debug.debug_count = IntOption( default=5, help='amount of log files to store when rotating, defaults to 2') debug.debug_filename = StringOption( default=None, help='file name used for this debug session, defaults to sys.argv[1]') debug.debug_console_format = StringOption( default='%(name)s %(module)s:%(funcName)s: %(message)s', help='console log formatting') debug.debug_format = StringOption( default= '%(asctime)-12s - %(levelname)5s - %(name)10s - %(funcName)-12s: %(message)s', help='file log formatting') debug.debug_disables = StringOption( default='', help='comma separated list of disable log modules') rpc_client = Section("rpc_client") rpc_client.client_mode = StringOption() rpc_client.client_daemonize = BoolOption(default=False) rpc_client.client_pidfile = StringOption(default=None) rpc_client.client_host = StringOption(default="localhost") rpc_client.client_port = IntOption(default=8010)
help='amount of log files to store when rotating, defaults to 2') debug.debug_filename = StringOption( default=None, help='file name used for this debug session, defaults to sys.argv[1]') debug.debug_console_format = StringOption( default='%(name)s %(module)s:%(funcName)s: %(message)s', help='console log formatting') debug.debug_format = StringOption( default= '%(asctime)-12s - %(levelname)5s - %(name)10s - %(funcName)-12s: %(message)s', help='file log formatting') debug.debug_disables = StringOption( default='', help='comma separated list of disable log modules') rpc_client = Section("rpc_client") rpc_client.client_mode = StringOption() rpc_client.client_daemonize = BoolOption(default=False) rpc_client.client_pidfile = StringOption(default=None) rpc_client.client_host = StringOption(default="localhost") rpc_client.client_port = IntOption(default=8010) if os.path.isfile('/etc/timezone'): OpenProximitySchema.django.time_zone.default = \ file('/etc/timezone').readline().strip() OpenProximitySchema.django.auth_profile_module = StringOption( default=None, help="Module to use for authoring") OpenProximitySchema.django.serialization_modules = DictOption( help="Default empty dict")
class baz(Section): bar = StringOption()
class foo(Section): bar = StringOption()
class MySchema(Schema): foo = StringOption() bar = StringOption() baz = IntOption()
def test_validate_null_string(self): """Test OptionString validate a null string.""" opt = StringOption(null=True) self.assertEqual(opt.validate(None), True)
class MySchema(Schema): foo = self.cls(item=StringOption(), remove_duplicates=True)
class MySchema(Schema): foo = StringOption() class DEFAULTSECT(Section): pass
def test_to_string_for_null_string(self): """Test OptionString to_string for a null string.""" opt = StringOption(null=True) self.assertEqual(opt.to_string(None), 'None') self.assertEqual(opt.to_string(''), '') self.assertEqual(opt.to_string('foo'), 'foo')
class preflight(Section): preflight_base_template = StringOption(default='index.1col.html') preflight_table_class = StringOption(default='listing')
class bar(Section): baz = IntOption() bla = StringOption(default='hello')