Changeset 13959 for main/waeup.kofa/trunk/src/waeup/kofa/mandates
- Timestamp:
- 21 Jun 2016, 04:46:56 (9 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/mandates
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/mandates/container.py
r11946 r13959 30 30 grok.implements(IMandatesContainer) 31 31 grok.provides(IMandatesContainer) 32 33 @property 34 def count(self): 35 """Count active and expired mandates. 36 """ 37 now = datetime.utcnow() 38 total = len(self) 39 expired = len([i for i in self.values() if i.expires < now]) 40 active = total - expired 41 return active, expired, total 32 42 33 43 def addMandate(self, mandate): -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/interfaces.py
r8910 r13959 25 25 """ 26 26 27 count = Attribute('Count active and expired mandates.') 28 27 29 def addMandate(mandate): 28 30 """Add mandate. -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py
r11681 r13959 153 153 self.app['mandates'].addMandate(mandate2) 154 154 self.assertEqual(len(self.app['mandates'].keys()), 2) 155 self.assertEqual(self.app['mandates'].count, (1, 1, 2)) 155 156 num_deleted = self.app['mandates'].removeExpired() 156 157 self.assertEqual(num_deleted, 1) … … 158 159 self.assertEqual(len(self.app['mandates'].keys()), 1) 159 160 self.assertEqual([i for i in self.app['mandates'].keys()], [u'23456']) 161 162 def test_purge_mandates(self): 163 # mandate1 is an old mandate which just expired. 164 mandate1 = PasswordMandate(days=0) 165 self.app['mandates'].addMandate(mandate1) 166 # mandate2 is a new mandate with default time delta. 167 mandate2 = PasswordMandate(mandate_id='23456') 168 self.app['mandates'].addMandate(mandate2) 169 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 170 self.browser.open('http://localhost/app/configuration') 171 self.assertEqual(self.app['mandates'].count, (1, 1, 2)) 172 self.assertTrue('<span>expired</span>' in self.browser.contents) 173 self.browser.getControl("Purge mandates").click() 174 self.assertTrue('1 mandate(s) were purged' in self.browser.contents) 175 self.assertEqual(self.app['mandates'].count, (1, 0, 1)) 176 return 160 177 161 178 def test_browser(self):
Note: See TracChangeset for help on using the changeset viewer.