[pyramid/test] add test for pyramid.ini generation
authorLaurent Peuch <cortex@worlddomination.be>
Wed, 15 May 2019 12:05:52 +0200
changeset 12600 0f33639d305b
parent 12597 7882ad333954
child 12601 f28a19408d3d
[pyramid/test] add test for pyramid.ini generation
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'