[PATCH 1 of 4] [pyramid/test] add test for pyramid.ini generation

Laurent Peuch cortex at worlddomination.be
Wed May 15 12:07:44 CEST 2019


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1557914752 -7200
#      Wed May 15 12:05:52 2019 +0200
# Node ID 0f33639d305b2aba43c02e55c10278c9a2641604
# Parent  7882ad3339542f824fcfaaa4635a91a3b86e9d56
[pyramid/test] add test for pyramid.ini generation

diff --git a/cubicweb/pyramid/test/test_config.py b/cubicweb/pyramid/test/test_config.py
--- a/cubicweb/pyramid/test/test_config.py
+++ b/cubicweb/pyramid/test/test_config.py
@@ -25,6 +25,7 @@ from unittest.mock import patch
 
 
 from cubicweb.pyramid import config
+from cubicweb.pyramid.pyramidctl import _generate_pyramid_ini_file
 
 
 class PyramidConfigTC(TestCase):
@@ -35,6 +36,27 @@ class PyramidConfigTC(TestCase):
         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'



More information about the cubicweb-devel mailing list