示例#1
0
        class MySchema(Schema):
            foo = IntOption()

            class one(Section):
                bar = IntOption()

            two = Section()
            two.bam = IntOption()
示例#2
0
 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)
示例#3
0
    def test_equal_when_error(self):
        """Test option equality when errors."""
        opt1 = IntOption()
        opt2 = IntOption()

        # make sure an attribute error is raised
        del opt2.name
        self.assertNotEqual(opt1, opt2)
示例#4
0
 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)
示例#5
0
    def test_equal_when_in_section(self):
        """Test option equality for section options."""
        sect1 = Section(name='sect1')
        sect2 = Section(name='sect2')
        opt1 = IntOption()
        opt2 = IntOption()

        self.assertEqual(opt1, opt2)

        opt1.section = sect1
        opt2.section = sect2
        self.assertNotEqual(opt1, opt2)
示例#6
0
    def test_mutable_inherited(self):
        """Test modifying inherited attribute doesn't affect parent."""
        # modify one inherited attribute
        self.schema.foo.baz = IntOption()

        # test on the other schema
        self.assertFalse(hasattr(self.other.foo, 'baz'))
示例#7
0
    def test_options(self):
        """Test Section options method."""
        section = self.cls()
        section.foo = IntOption()
        section.bar = 4

        self.assertEqual(section.options(), [section.foo])
示例#8
0
    def test_option(self):
        """Test Section option method."""
        section = self.cls()
        section.foo = IntOption()

        self.assertEqual(section.option('foo'), section.foo)
        self.assertRaises(NoOptionError, section.option, 'bar')
    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)
示例#10
0
 class MySchema(Schema):
     foo = self.cls(spec={
         'bar': StringOption(),
         'baz': IntOption(),
         'bla': BoolOption(),
     },
                    parse_json=False)
示例#11
0
 class MySchema(Schema):
     foo = ListOption(item=DictOption(
         spec={
             'bar': StringOption(),
             'baz': IntOption(),
             'bla': BoolOption(),
         }))
示例#12
0
    def test_has_option(self):
        """Test Section has_option method."""
        section = self.cls()
        section.foo = IntOption()
        section.bar = 4

        self.assertEqual(section.has_option('foo'), True)
        self.assertEqual(section.has_option('bar'), False)
示例#13
0
 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.')
示例#14
0
    def test_equality(self):
        """Test Section equality."""
        section1 = self.cls()
        section2 = self.cls()
        section3 = self.cls(name='foo')
        section4 = self.cls()
        section4.foo = IntOption()

        self.assertEqual(section1, section1)
        self.assertEqual(section1, section2)
        self.assertNotEqual(section1, section3)
        self.assertNotEqual(section1, section4)
示例#15
0
    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)
示例#16
0
    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)
示例#17
0
    def test_init(self):
        """Test default values for DictOption attributes."""
        opt = self.cls()
        self.assertEqual(opt.spec, {})
        self.assertEqual(opt.strict, False)

        spec = {'a': IntOption(), 'b': BoolOption()}
        opt = self.cls(spec=spec)
        self.assertEqual(opt.spec, spec)
        self.assertEqual(opt.strict, False)

        opt = self.cls(spec=spec, strict=True)
        self.assertEqual(opt.spec, spec)
        self.assertEqual(opt.strict, True)
示例#18
0
    def test_equal_when_in_section(self):
        """Test option equality for section options."""
        sect1 = Section(name='sect1')
        sect2 = Section(name='sect2')
        opt1 = IntOption()
        opt2 = IntOption()

        self.assertEqual(opt1, opt2)

        opt1.section = sect1
        opt2.section = sect2
        self.assertNotEqual(opt1, opt2)
示例#19
0
 class MySchema(Schema):
     foo = self.cls(item=IntOption())
示例#20
0
 class web(Section):
     bar = IntOption()
示例#21
0
 class MySchema(Schema):
     foo = IntOption()
     bar = DictOption(spec={'baz': IntOption(), 'BAZ': IntOption()})
示例#22
0
 class MySchema(Schema):
     foo = IntOption()
示例#23
0
 class django(Section):
     bar = IntOption()
示例#24
0
 class django(Section):
     foo = IntOption()
示例#25
0
 class bar(Section):
     baz = IntOption()
示例#26
0
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)
示例#27
0
 class MySchema(Schema):
     foo = self.cls(item=IntOption(), parse_json=False)
示例#28
0
        class MyThirdSchema(Schema):
            bar = IntOption()

            class froo(Section):
                twaddle = ListOption(item=BoolOption())
示例#29
0
 def test_validate_nonlist(self):
     """Test ListOption validate a non-list value."""
     opt = self.cls(item=IntOption())
     self.assertEqual(opt.validate(''), False)
示例#30
0
 def test_validate_list(self):
     """Test ListOption validate a list value."""
     opt = self.cls(item=IntOption())
     self.assertEqual(opt.validate([]), True)
示例#31
0
 def test_default(self):
     """Test ListOption default value."""
     opt = self.cls(item=IntOption())
     self.assertEqual(opt.default, [])