# HG changeset patch # User Laurent Peuch # Date 1557914752 -7200 # Node ID 0f33639d305b2aba43c02e55c10278c9a2641604 # Parent 7882ad3339542f824fcfaaa4635a91a3b86e9d56 [pyramid/test] add test for pyramid.ini generation diff -r 7882ad333954 -r 0f33639d305b cubicweb/pyramid/test/test_config.py --- a/cubicweb/pyramid/test/test_config.py Fri May 10 16:07:32 2019 +0200 +++ b/cubicweb/pyramid/test/test_config.py Wed May 15 12:05:52 2019 +0200 @@ -25,6 +25,7 @@ from cubicweb.pyramid import config +from cubicweb.pyramid.pyramidctl import _generate_pyramid_ini_file class PyramidConfigTC(TestCase): @@ -35,6 +36,27 @@ self.assertEqual(patched_choice.call_count, 50) self.assertEqual(secret, '0' * 50) + def test_write_pyramid_ini(self): + with TemporaryDirectory() as instancedir: + pyramid_ini_path = path.join(instancedir, "pyramid.ini") + with patch('random.SystemRandom.choice', return_value='0') as patched_choice: + _generate_pyramid_ini_file(pyramid_ini_path) + with open(path.join(instancedir, 'pyramid.ini')) as f: + lines = f.readlines() + + self.assertEqual(patched_choice.call_count, 50 * 3) + + secret = '0' * 50 + + for option in ('cubicweb.session.secret', + 'cubicweb.auth.authtkt.persistent.secret', + 'cubicweb.auth.authtkt.session.secret'): + self.assertIn('{} = {}\n'.format(option, secret), lines) + + for option in ('cubicweb.auth.authtkt.persistent.secure', + 'cubicweb.auth.authtkt.session.secure'): + self.assertIn('{} = {}\n'.format(option, "no"), lines) + def test_write_development_ini(self): with TemporaryDirectory() as instancedir: appid = 'pyramid-instance'