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)
예제 #2
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)
예제 #3
0
 class MySchema(Schema):
     foo = ListOption(item=DictOption(
         spec={
             'bar': StringOption(),
             'baz': IntOption(),
             'bla': BoolOption(),
         }))
예제 #4
0
 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)
예제 #5
0
    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)
예제 #6
0
 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)
예제 #7
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)
예제 #8
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)
예제 #9
0
        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")
예제 #10
0
 class MySchema(Schema):
     foo = DictOption(spec={'bar': DictOption()}, strict=True)
예제 #11
0
 class MyOtherSchema(Schema):
     foo = self.cls(item=DictOption(), remove_duplicates=True)
예제 #12
0
 class MySchema(Schema):
     foo = DictOption(spec=spec)
예제 #13
0
 class MySchema(Schema):
     foo = DictOption(spec={'a': IntOption()})
예제 #14
0
 class MySchema(Schema):
     foo = ListOption(
         item=DictOption(
             item=ListOption(item=DictOption())))
예제 #15
0
 def test_to_string_when_json(self):
     option = DictOption()
     result = option.to_string({'foo': '1'})
     self.assertEqual(result, '{"foo": "1"}')
예제 #16
0
 class MySchema(Schema):
     foo = DictOption(spec={
         'bar': IntOption(),
         'baz': BoolOption()})
예제 #17
0
 class MySchema(Schema):
     foo = ListOption(
         item=DictOption(spec={
             'bar': IntOption(),
             'baz': IntOption(),
         }, strict=True))
예제 #18
0
 class MySchema(Schema):
     foo = ListOption(
         item=DictOption(spec={'bar': IntOption()}))
예제 #19
0
 class MySchema(Schema):
     foo = DictOption()
예제 #20
0
 class MySchema(Schema):
     foo = IntOption()
     bar = DictOption(spec={'baz': IntOption(), 'BAZ': IntOption()})
예제 #21
0
 def test_to_string_when_json(self):
     option = DictOption()
     result = option.to_string({'foo': '1'})
     self.assertEqual(result, '{"foo": "1"}')
예제 #22
0
 def test_to_string_when_no_json(self):
     option = DictOption(parse_json=False)
     result = option.to_string({'foo': '1'})
     self.assertEqual(result, str({'foo': '1'}))
예제 #23
0
 def test_to_string_when_no_json(self):
     option = DictOption(parse_json=False)
     result = option.to_string({'foo': '1'})
     self.assertEqual(result, str({'foo': '1'}))