Ignore:
Timestamp:
20 Oct 2016, 21:13:17 (8 years ago)
Author:
Henrik Bettermann
Message:

Count mandates on configuration page and provide 'Purge' button.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/mandates/tests.py

    r12816 r14221  
    8989        # Add and execute a mandate with missing parameters.
    9090        mandate = PasswordMandate()
     91        IUserAccount(customer).setPassword('old_pw')
    9192        self.app['mandates'].addMandate(mandate)
    92         msg = mandate.execute()
     93        (msg, redirect_path) = mandate.execute()
    9394        self.assertEqual(msg, u'Wrong mandate parameters.')
    9495        # Add and execute an expired mandate.
    9596        mandate = PasswordMandate(days=0)
     97        mandate.params['user'] = customer
     98        mandate.params['password'] = 'mypwd1'
    9699        self.app['mandates'].addMandate(mandate)
    97         msg = mandate.execute()
     100        (msg, redirect_path) = mandate.execute()
    98101        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'))
    99105        # Add and execute a perfect mandate
    100106        mandate = PasswordMandate()
     
    102108        mandate.params['password'] = 'mypwd1'
    103109        self.app['mandates'].addMandate(mandate)
    104         msg = mandate.execute()
     110        (msg, redirect_path) = mandate.execute()
    105111        # Password has been set.
    106112        self.assertEqual(msg, 'Password has been successfully set. Login with your new password.')
     
    120126        mandate.params['password'] = 'mypwd1'
    121127        self.app['mandates'].addMandate(mandate)
    122         msg = mandate.execute()
     128        (msg, redirect_path) = mandate.execute()
    123129        # Password has been set.
    124130        self.assertEqual(msg, 'Password has been successfully set. Login with your new password.')
     
    142148        self.assertEqual(len(self.app['mandates'].keys()), 1)
    143149        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
    144170
    145171    def test_browser(self):
Note: See TracChangeset for help on using the changeset viewer.