cubicweb/pyramid/test/test_config.py
branch3.26
changeset 12562 7bb677060ebd
parent 12053 c3c9f2e1424c
child 12567 26744ad37953
equal deleted inserted replaced
12511:e312461d3200 12562:7bb677060ebd
    29 
    29 
    30 
    30 
    31 class PyramidConfigTC(TestCase):
    31 class PyramidConfigTC(TestCase):
    32 
    32 
    33     def test_get_random_secret_key(self):
    33     def test_get_random_secret_key(self):
    34         with patch('random.choice', return_value='0') as patched_choice:
    34         with patch('random.SystemRandom.choice', return_value='0') as patched_choice:
    35             secret = config.get_random_secret_key()
    35             secret = config.get_random_secret_key()
    36         self.assertEqual(patched_choice.call_count, 50)
    36         self.assertEqual(patched_choice.call_count, 50)
    37         self.assertEqual(secret, '0' * 50)
    37         self.assertEqual(secret, '0' * 50)
    38 
    38 
    39     def test_write_development_ini(self):
    39     def test_write_development_ini(self):
    41             appid = 'pyramid-instance'
    41             appid = 'pyramid-instance'
    42             os.makedirs(path.join(instancedir, appid))
    42             os.makedirs(path.join(instancedir, appid))
    43             os.environ['CW_INSTANCES_DIR'] = instancedir
    43             os.environ['CW_INSTANCES_DIR'] = instancedir
    44             try:
    44             try:
    45                 cfg = config.CubicWebPyramidConfiguration(appid)
    45                 cfg = config.CubicWebPyramidConfiguration(appid)
    46                 with patch('random.choice', return_value='0') as patched_choice:
    46                 with patch('random.SystemRandom.choice', return_value='0') as patched_choice:
    47                     cfg.write_development_ini(['foo', 'bar'])
    47                     cfg.write_development_ini(['foo', 'bar'])
    48             finally:
    48             finally:
    49                 os.environ.pop('CW_INSTANCES_DIR')
    49                 os.environ.pop('CW_INSTANCES_DIR')
    50             with open(path.join(instancedir, appid, 'development.ini')) as f:
    50             with open(path.join(instancedir, appid, 'development.ini')) as f:
    51                 lines = f.readlines()
    51                 lines = f.readlines()