comparison test/test_templating.py @ 5488:52cb53eedf77

reworked random number use prefer secrets module from Python 3.6+, random.SystemRandom and finally plain random
author Christof Meerwald <cmeerw@cmeerw.org>
date Sat, 04 Aug 2018 22:40:16 +0100
parents b0359a7c5b6d
children f8893e1cde0d
comparison
equal deleted inserted replaced
5487:ce171c81d823 5488:52cb53eedf77
151 for test in [ 'module', 'template', 'default_time' ]: 151 for test in [ 'module', 'template', 'default_time' ]:
152 print("Testing:", test) 152 print("Testing:", test)
153 153
154 if test == 'module': 154 if test == 'module':
155 # test the module function 155 # test the module function
156 nonce1 = anti_csrf_nonce(self, self.client, lifetime=1) 156 nonce1 = anti_csrf_nonce(self.client, lifetime=1)
157 # lifetime * 60 is the offset 157 # lifetime * 60 is the offset
158 greater_than = week_seconds - 1 * 60 158 greater_than = week_seconds - 1 * 60
159 elif test == 'template': 159 elif test == 'template':
160 # call the function through the TemplatingUtils class 160 # call the function through the TemplatingUtils class
161 cls = TemplatingUtils(self.client) 161 cls = TemplatingUtils(self.client)
162 nonce1 = cls.anti_csrf_nonce(lifetime=5) 162 nonce1 = cls.anti_csrf_nonce(lifetime=5)
163 greater_than = week_seconds - 5 * 60 163 greater_than = week_seconds - 5 * 60
164 elif test == 'default_time': 164 elif test == 'default_time':
165 # use the module function but with no lifetime 165 # use the module function but with no lifetime
166 nonce1 = anti_csrf_nonce(self, self.client) 166 nonce1 = anti_csrf_nonce(self.client)
167 # see above for web nonce lifetime. 167 # see above for web nonce lifetime.
168 greater_than = week_seconds - 10 * 60 168 greater_than = week_seconds - 10 * 60
169 169
170 self.assertEqual(len(nonce1), 64) 170 self.assertEqual(len(nonce1), 64)
171 171

Roundup Issue Tracker: http://roundup-tracker.org/