Revision 2e616dbd kamaki/cli/config/test.py

b/kamaki/cli/config/test.py
327 327
            _cnf.set_global('opt', 'val')
328 328
            c_set.assert_called_once_with('global', 'opt', 'val')
329 329

  
330
    def test__load_defaults(self):
331
        from kamaki.cli.config import Config, DEFAULTS
332
        _cnf = Config(path=self.f.name)
333

  
334
        with patch('kamaki.cli.config.Config.set') as c_set:
335
            _cnf._load_defaults()
336
            for i, (section, options) in enumerate(DEFAULTS.items()):
337
                for j, (option, val) in enumerate(options.items()):
338
                    self.assertEqual(
339
                        c_set.mock_calls[(i + 1) * j],
340
                        call(section, option, val))
341

  
342
    def test__get_dict(self):
343
        from kamaki.cli.config import Config, CLOUD_PREFIX, DEFAULTS
344

  
345
        def make_file(lines):
346
            f = NamedTemporaryFile()
347
            f.writelines(lines)
348
            f.flush()
349
            return f
350

  
351
        with make_file([]) as f:
352
            _cnf = Config(path=f.name)
353
            for term in ('global', CLOUD_PREFIX):
354
                self.assertEqual(DEFAULTS[term], _cnf._get_dict(term))
355
            for term in ('nosection', ''):
356
                self.assertEqual({}, _cnf._get_dict(term))
357

  
358
        with make_file(self.config_file_content) as f:
359
            _cnf = Config(path=f.name)
360
            for term in ('global', CLOUD_PREFIX):
361
                self.assertNotEqual(DEFAULTS[term], _cnf._get_dict(term))
362

  
363
    def test_reload(self):
364
        from kamaki.cli.config import Config
365
        _cnf = Config(path=self.f.name)
366

  
367
        with patch('kamaki.cli.config.Config.__init__') as i:
368
            _cnf.reload()
369
            i.assert_called_once_with(self.f.name)
370

  
330 371

  
331 372
if __name__ == '__main__':
332 373
    from sys import argv

Also available in: Unified diff