Changeset 14221 for main/waeup.ikoba/trunk/src/waeup
- Timestamp:
- 20 Oct 2016, 21:13:17 (8 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py
r14183 r14221 939 939 grok.require('waeup.managePortalConfiguration') 940 940 grok.name('index') 941 grok.template('configurationmanagepage') 941 942 grok.context(IConfigurationContainer) 942 943 pnav = 0 … … 962 963 grok.getSite().updatePlugins() 963 964 self.flash(_('Plugins were updated. See log file for details.')) 965 return 966 967 @action(_('Purge mandates'), 968 tooltip=_('For experts only!'), 969 validator=NullValidator) 970 def purgeMandates(self, **data): 971 num = grok.getSite()['mandates'].removeExpired() 972 self.flash(_('${a} mandate(s) were purged.', mapping = {'a': num})) 964 973 return 965 974 -
main/waeup.ikoba/trunk/src/waeup/ikoba/mandates/container.py
r11954 r14221 31 31 grok.provides(IMandatesContainer) 32 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 42 33 43 def addMandate(self, mandate): 34 44 if not IMandate.providedBy(mandate): … … 42 52 """ 43 53 num_deleted = 0 44 for mandate in self.keys(): 54 keys = list(self.keys()) 55 for mandate in keys: 45 56 if self[mandate].expires < datetime.utcnow(): 46 57 del self[mandate] 47 58 num_deleted += 1 59 grok.getSite().logger.info('%s mandates purged' % num_deleted) 48 60 return num_deleted 49 61 -
main/waeup.ikoba/trunk/src/waeup/ikoba/mandates/interfaces.py
r11949 r14221 25 25 """ 26 26 27 count = Attribute('Count active and expired mandates.') 28 27 29 def addMandate(mandate): 28 30 """Add mandate. -
main/waeup.ikoba/trunk/src/waeup/ikoba/mandates/mandate.py
r11949 r14221 67 67 def execute(self): 68 68 msg = _('Wrong mandate parameters.') 69 redirect_path = '' 69 70 if self.expires < datetime.utcnow(): 70 71 msg = _('Mandate expired.') 71 if self._setPassword():72 elif self._setPassword(): 72 73 msg = _('Password has been successfully set. ' 73 74 'Login with your new password.') … … 75 76 grok.getSite().logger.info( 76 77 'PasswordMandate used: %s ' % username) 78 redirect_path = 'login' 77 79 del self.__parent__[self.mandate_id] 78 return msg 80 return msg, redirect_path -
main/waeup.ikoba/trunk/src/waeup/ikoba/mandates/tests.py
r12816 r14221 89 89 # Add and execute a mandate with missing parameters. 90 90 mandate = PasswordMandate() 91 IUserAccount(customer).setPassword('old_pw') 91 92 self.app['mandates'].addMandate(mandate) 92 msg= mandate.execute()93 (msg, redirect_path) = mandate.execute() 93 94 self.assertEqual(msg, u'Wrong mandate parameters.') 94 95 # Add and execute an expired mandate. 95 96 mandate = PasswordMandate(days=0) 97 mandate.params['user'] = customer 98 mandate.params['password'] = 'mypwd1' 96 99 self.app['mandates'].addMandate(mandate) 97 msg= mandate.execute()100 (msg, redirect_path) = mandate.execute() 98 101 self.assertEqual(msg, u'Mandate expired.') 102 self.assertEqual(redirect_path, '') 103 # Password has not been set 104 self.assertTrue(IUserAccount(customer).checkPassword('old_pw')) 99 105 # Add and execute a perfect mandate 100 106 mandate = PasswordMandate() … … 102 108 mandate.params['password'] = 'mypwd1' 103 109 self.app['mandates'].addMandate(mandate) 104 msg= mandate.execute()110 (msg, redirect_path) = mandate.execute() 105 111 # Password has been set. 106 112 self.assertEqual(msg, 'Password has been successfully set. Login with your new password.') … … 120 126 mandate.params['password'] = 'mypwd1' 121 127 self.app['mandates'].addMandate(mandate) 122 msg= mandate.execute()128 (msg, redirect_path) = mandate.execute() 123 129 # Password has been set. 124 130 self.assertEqual(msg, 'Password has been successfully set. Login with your new password.') … … 142 148 self.assertEqual(len(self.app['mandates'].keys()), 1) 143 149 self.assertEqual([i for i in self.app['mandates'].keys()], [u'23456']) 150 logfile = os.path.join( 151 self.app['datacenter'].storage, 'logs', 'main.log') 152 logcontent = open(logfile).read() 153 self.assertTrue('system - 1 mandates purged' in logcontent) 154 155 def test_purge_mandates(self): 156 # mandate1 is an old mandate which just expired. 157 mandate1 = PasswordMandate(days=0) 158 self.app['mandates'].addMandate(mandate1) 159 # mandate2 is a new mandate with default time delta. 160 mandate2 = PasswordMandate(mandate_id='23456') 161 self.app['mandates'].addMandate(mandate2) 162 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 163 self.browser.open('http://localhost/app/configuration') 164 self.assertEqual(self.app['mandates'].count, (1, 1, 2)) 165 self.assertTrue('<span>expired</span>' in self.browser.contents) 166 self.browser.getControl("Purge mandates").click() 167 self.assertTrue('1 mandate(s) were purged' in self.browser.contents) 168 self.assertEqual(self.app['mandates'].count, (1, 0, 1)) 169 return 144 170 145 171 def test_browser(self):
Note: See TracChangeset for help on using the changeset viewer.