Exemple #1
0
    def test_bool_opt_casts(self):
        conf = Config({'section1': {'help': 'no', 'bool': True}})
        value = conf.bool('section1', 'help', True)
        self.assertEquals(value, False)
        value = conf.bool('section1', 'bool', True)
        self.assertEquals(value, True)

        def truthy_test(value, expected):
            conf = Config({'section1': {'verbose': value}})
            value = conf.bool('section1', 'verbose', True)
            self.assertEquals(value, expected)

        truthy_test('TRUE', True)
        truthy_test('True', True)
        truthy_test('true', True)
        truthy_test('YES', True)
        truthy_test('yes', True)
        truthy_test('Yes', True)
        truthy_test('T', True)
        truthy_test('t', True)
        truthy_test('Y', True)
        truthy_test('y', True)
        truthy_test('1', True)
        truthy_test('ON', True)
        truthy_test('On', True)
        truthy_test('on', True)
        truthy_test('ENABLE', True)
        truthy_test('Enable', True)
        truthy_test('enable', True)
        truthy_test(True, True)
Exemple #2
0
 def delete(self, req):
     try:
         force = Config.to_bool(req.params.get("force", False))
         initiator = req.params.get("initiator")
         export = self.helper.exports.delete(self.volume_id, force=force, initiator=initiator)
     except NotFound:
         raise HTTPNotFound("No export for volume: '%s'" % self.volume_id)
     except ResourceBusy, e:
         raise HTTPConflict(str(e))
Exemple #3
0
    def setUp(self):
        # Default the config to the local user and our current dir
        self.volume_type = os.environ.get("API_VOLUME_TYPE", "vtype")
        self.skip_admin = Config.to_bool(os.environ.get("API_SKIP_ADMIN", "false"))

        # Start the Lunr API Service if needed
        self.api = LunrApiService()

        # setup our timeouts
        super(LunrApiTestCase, self).setUp()
Exemple #4
0
 def delete(self, req):
     try:
         force = Config.to_bool(req.params.get('force', False))
         initiator = req.params.get('initiator')
         export = self.helper.exports.delete(self.volume_id,
                                             force=force,
                                             initiator=initiator)
     except NotFound:
         raise HTTPNotFound("No export for volume: '%s'" % self.volume_id)
     except ResourceBusy, e:
         raise HTTPConflict(str(e))
Exemple #5
0
    def setUp(self):
        # Default the config to the local user and our current dir
        self.volume_type = os.environ.get('API_VOLUME_TYPE', 'vtype')
        self.skip_admin = Config.to_bool(
            os.environ.get('API_SKIP_ADMIN', 'false'))

        # Start the Lunr API Service if needed
        self.api = LunrApiService()

        # setup our timeouts
        super(LunrApiTestCase, self).setUp()
Exemple #6
0
 def test_write(self):
     s = StringIO()
     conf = Config()
     conf.write(s)
     self.assertEquals(s.getvalue(), "[default]\n")
     s.seek(0)
     conf = Config({'aaa': {'a': 'AAA', 'b': 'BBB'},
                    'bbb': {'c': 'CCC', 'd': 'DDD'},
                    'default': {}})
     conf.write(s)
     expected = "[aaa]\na = AAA\nb = BBB\n[bbb]\n" \
                "c = CCC\nd = DDD\n[default]\n"
     self.assertEquals(s.getvalue(), expected)
Exemple #7
0
    def test_string_opts(self):
        conf = Config()
        value = conf.string('section1', 'string', 'default')
        self.assertEquals(value, 'default')

        conf = Config({'section1': {'string': 'value'}})
        value = conf.string('section1', 'string', 'default')
        self.assertEquals(value, 'value')
Exemple #8
0
    def test_bool_opts(self):
        conf = Config()
        value = conf.bool('section1', 'bool', True)
        self.assertEquals(value, True)

        conf = Config({'section1': {'bool': False}})
        value = conf.bool('section1', 'bool', True)
        self.assertEquals(value, False)
Exemple #9
0
    def test_int_opts(self):
        conf = Config()
        value = conf.int('section1', 'int', 1)
        self.assertEquals(value, 1)

        conf = Config({'section1': {'int': 2}})
        value = conf.int('section1', 'int', 1)
        self.assertEquals(value, 2)
Exemple #10
0
 def truthy_test(value, expected):
     conf = Config({'section1': {'verbose': value}})
     value = conf.bool('section1', 'verbose', True)
     self.assertEquals(value, expected)
Exemple #11
0
 def setUp(self):
     # Default the config to the local user and our current dir
     self.volume_type = os.environ.get('API_VOLUME_TYPE','vtype')
     self.skip_admin = Config.to_bool(os.environ.get('API_SKIP_ADMIN', 'false'))
Exemple #12
0
 def test_int_opt_casts(self):
     conf = Config({'section1': {'int': 'non-numeric', 'bool': True}})
     self.assertRaises(ValueError, conf.int, 'section1', 'int', 1)
     value = conf.int('section1', 'bool', True)
     self.assertEquals(value, 1)
Exemple #13
0
 def test_string_opt_casts(self):
     conf = Config({'section1': {'int': 1, 'bool': True}})
     value = conf.string('section1', 'bool', 'False')
     self.assertEquals(value, 'True')
     value = conf.string('section1', 'int', '2')
     self.assertEquals(value, '1')
Exemple #14
0
    def test_list_opts(self):
        conf = Config()
        value = conf.list('section1', 'list', [])
        self.assertEquals(value, [])

        value = conf.list('section1', 'list', 'monkey')
        self.assertEquals(value, ['monkey'])

        value = conf.list('section1', 'list', ['monkey'])
        self.assertEquals(value, ['monkey'])

        # Not a list or string, just bail?
        self.assertRaises(ValueError, conf.list, 'a', 'b', 42)

        conf = Config({'section1': {'list': 'monkey'}})
        value = conf.list('section1', 'list', [])
        self.assertEquals(value, ['monkey'])

        conf = Config({'section1': {'list': 'monkey, walrus,dog,apple  '}})
        value = conf.list('section1', 'list', [])
        self.assertEquals(value, ['monkey', 'walrus', 'dog', 'apple'])
Exemple #15
0
 def test_section(self):
     conf = Config({'section1': {'value1': 'value2'}})
     self.assertEquals(conf.section('section1'), {'value1': 'value2'})
Exemple #16
0
 def test_set(self):
     conf = Config()
     # Explicity set a value for a section
     conf.set('section1', 'int', 2)
     value = conf.int('section1', 'int', 1)
     self.assertEquals(value, 2)
Exemple #17
0
    def test_environment_variables(self):
        conf = Config()

        os.environ['DEFAULT_TEST_LUNR_DIR'] = '/home/foo'
        value = conf.string('default', 'test_lunr_dir', '/home/lunr')
        self.assertEquals(value, '/home/foo')